git-svn-id: svn://db.shs.com.ru/libs@58 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -225,7 +225,7 @@ public:
|
||||
virtual void init() {shadow_map.resize(512, 512); is_init = true;}
|
||||
virtual void draw(QGLShaderProgram * prog, bool simplest = false);
|
||||
|
||||
QVector3D direction;
|
||||
QVector3D direction, dir0, dir1;
|
||||
GLdouble angle_start;
|
||||
GLdouble angle_end;
|
||||
GLdouble intensity;
|
||||
|
||||
@@ -238,7 +238,11 @@ void GLRendererBase::renderShadow(Light * l, QGLShaderProgram * prog, QMatrix4x4
|
||||
cam.setDepthEnd(view.camera().depthEnd());
|
||||
cam.setFOV(l->angle_end);
|
||||
cam.apply(1.);
|
||||
view.objects_.preparePos(cam);
|
||||
cam.rotateXY(l->angle_end);
|
||||
l->dir0 = cam.direction();
|
||||
cam.rotateXY(-l->angle_end);
|
||||
cam.rotateZ(l->angle_end);
|
||||
l->dir1 = cam.direction();
|
||||
RenderingParameters rpl;
|
||||
rpl.pass = GLObjectBase::Solid;
|
||||
rpl.shaders = prog;
|
||||
@@ -248,7 +252,7 @@ void GLRendererBase::renderShadow(Light * l, QGLShaderProgram * prog, QMatrix4x4
|
||||
QMatrix4x4 mbias;
|
||||
mbias.scale(0.5, 0.5, 0.5);
|
||||
mbias.translate(1., 1., 1.);
|
||||
l->shadow_matrix = mbias*rpl.proj_matrix*rpl.view_matrix;//*mat;
|
||||
l->shadow_matrix = mbias*rpl.proj_matrix*rpl.view_matrix;//*mat;//;// * mbias;
|
||||
//qDebug() << mbias;
|
||||
//glPushMatrix();
|
||||
renderSingleShadow(view.objects_, rpl);
|
||||
|
||||
@@ -67,7 +67,9 @@ const char qgl_structs[] =
|
||||
" float quadraticAttenuation;\n"
|
||||
" sampler2DShadow shadow;\n"
|
||||
//" sampler2D shadowColor\n"
|
||||
" mat4 shadowMatrix;\n"
|
||||
//" mat4 shadowMatrix;\n"
|
||||
" vec4 shadowDir0;\n"
|
||||
" vec4 shadowDir1;\n"
|
||||
"};\n"
|
||||
"struct QGLMap {\n"
|
||||
" float offset;\n"
|
||||
@@ -215,7 +217,7 @@ void setUniformLights(QGLShaderProgram * prog, const QVector<Light*> & lights, c
|
||||
*/
|
||||
void setUniformLight(QGLShaderProgram * prog, Light * light, QString ulightn, const QMatrix4x4 & mat, int shadow) {
|
||||
QMatrix4x4 m = mat * light->worldTransform();
|
||||
QVector4D pos(0, 0, 0, 1.), dir(light->direction);
|
||||
QVector4D pos(0, 0, 0, 1.), dir(light->direction), dir0(light->dir0), dir1(light->dir1);
|
||||
pos = m * pos;
|
||||
dir = (mat * dir).normalized();
|
||||
double ang_start = light->angle_start / 2., ang_end = light->angle_end / 2.;
|
||||
@@ -235,5 +237,8 @@ void setUniformLight(QGLShaderProgram * prog, Light * light, QString ulightn, co
|
||||
prog->setUniformValue((ulightn + ".quadraticAttenuation").toLatin1().constData(), GLfloat(light->decay_quadratic));
|
||||
prog->setUniformValue((ulightn + ".shadow").toLatin1().constData(), shadow);
|
||||
prog->setUniformValue((ulightn + ".shadowColor").toLatin1().constData(), shadow);
|
||||
prog->setUniformValue((ulightn + ".shadowMatrix").toLatin1().constData(), light->shadow_matrix);
|
||||
prog->setUniformValue((ulightn + ".shadowDir0").toLatin1().constData(), (mat * dir0).normalized());
|
||||
prog->setUniformValue((ulightn + ".shadowDir1").toLatin1().constData(), (mat * dir1).normalized());
|
||||
//qDebug() << light->direction << light->dir0 << light->dir1;
|
||||
//prog->setUniformValue((ulightn + ".shadowMatrix").toLatin1().constData(), light->shadow_matrix);
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ void QGLView::drawBackground(QPainter * painter, const QRectF & rect) {
|
||||
|
||||
|
||||
void QGLView::initializeGL() {
|
||||
qDebug() << "init glview";
|
||||
//qDebug() << "init glview";
|
||||
makeCurrent();
|
||||
currentQGLView = (QGLWidget * )viewport();
|
||||
currentGLTextureManager = &textures_manager;
|
||||
@@ -509,7 +509,7 @@ void QGLView::resizeGL(int width, int height) {
|
||||
if (!is_init) return;
|
||||
aspect = double(width) / double(height);
|
||||
if (renderer_ != 0) renderer_->resize(width, height);
|
||||
qDebug() << "resize" << width << height;
|
||||
//qDebug() << "resize" << width << height;
|
||||
fbo_selection.resize(width, height);
|
||||
mouse_first = true;
|
||||
iaspect = (aspect == 0.) ? 0. : 1 / aspect;
|
||||
|
||||
@@ -24,7 +24,7 @@ float sh_pow, sh_mul, dist, NdotL, NdotH, spot, ldist, diff, sdist, shadow;
|
||||
float getShadow(int light, vec3 view_pos, vec3 dpos) {
|
||||
shp = mat_viewi * vec4(view_pos, 1);
|
||||
shp += vec4(dpos, 0);
|
||||
shp = qgl_Light[light].shadowMatrix * shp;
|
||||
//shp = qgl_Light[light].shadowMatrix * shp;
|
||||
//shp.xyz /= shp.w;
|
||||
shp.z -= 0.1;
|
||||
return textureProj(qgl_Light[light].shadow, shp);
|
||||
@@ -43,10 +43,7 @@ void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
|
||||
if (qgl_Light[index].endAngle <= 90.) {
|
||||
float scos = max(dot(-ldir, qgl_Light[index].direction.xyz), 0.);
|
||||
spot *= scos * step(qgl_Light[index].endAngleCos, scos);
|
||||
//spot = clamp(scos / (-qgl_Light[index].endAngleCos + qgl_Light[index].startAngleCos + 0.0001),0,1);
|
||||
spot *= smoothstep(qgl_Light[index].endAngleCos, qgl_Light[index].startAngleCos, scos);
|
||||
//spot = pow(spot, (qgl_Light[index].spotExponent + 0.001));
|
||||
|
||||
lwdir = mat3(mat_viewi) * qgl_Light[index].direction.xyz;
|
||||
bn = normalize(cross(lwdir, vec3(1, 0, 0)));
|
||||
bn2 = normalize(cross(lwdir, bn));
|
||||
@@ -54,7 +51,7 @@ void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
|
||||
//spot *= clamp(1. - sdist, 0, 1);
|
||||
vds = ds * bn.xyz;
|
||||
vds2 = ds * bn2.xyz;
|
||||
float shadow = getShadow(index, pos.xyz, vec3(0)) * 3. +
|
||||
float shadow = 1;/* getShadow(index, pos.xyz, vec3(0))/* * 3. +
|
||||
getShadow(index, pos.xyz, vds ) * 2. +
|
||||
getShadow(index, pos.xyz, - vds ) * 2. +
|
||||
getShadow(index, pos.xyz, - vds2 ) * 2. +
|
||||
@@ -74,47 +71,8 @@ void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
|
||||
getShadow(index, pos.xyz, vds - vds2 - vds2) +
|
||||
getShadow(index, pos.xyz, vds + vds2 + vds2) +
|
||||
getShadow(index, pos.xyz, - vds - vds2 - vds2) +
|
||||
getShadow(index, pos.xyz, - vds + vds2 + vds2);
|
||||
//spot *= shadow / 29.;
|
||||
/*shp = qgl_Light[index].shadowMatrix*vec4(pos.xyz,1);
|
||||
//shp.z -= 0.1;
|
||||
shp.xyz /= shp.w;
|
||||
float shr = texture(qgl_Light[index].shadowColor, shp.xy).r;
|
||||
sdist = shp.w - shr - 1.;
|
||||
//if (sdist > 0.) {
|
||||
shadow = //shr + //texture(qgl_Light[index].shadowColor, shp.xy, shp.zw)) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy + vds ).r - 1, 0, 1)
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy + vds - vds2 ).r - 1, 0, 1) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy + vds + vds2 ).r - 1, 0, 1) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy - vds ).r - 1, 0, 1) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy - vds - vds2 ).r - 1, 0, 1) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy - vds + vds2 ).r - 1, 0, 1) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy - vds2 ).r - 1, 0, 1) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy + vds2 ).r - 1, 0, 1) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy + vds + vds ).r - 1, 0, 1) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy - vds - vds ).r - 1, 0, 1) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy - vds2 - vds2).r - 1, 0, 1) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy + vds2 + vds2).r - 1, 0, 1)*/;
|
||||
/*texture(qgl_Light[index].shadowColor, shp.xy - vds ).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy - vds + vds2 ).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy + vds2 ).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy ).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy - vds ).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy - vds2 ).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy - vds - vds2 ).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy ).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy + vds + vds + vds2 + vds2).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy + vds + vds + vds2 + vds2).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy + vds + vds + vds2 + vds2).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy + vds + vds + vds2 + vds2).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy + vds + vds + vds2 + vds2).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy + vds + vds + vds2 + vds2).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy + vds + vds + vds2 + vds2).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy + vds + vds + vds2 + vds2).r;
|
||||
shadow = shadow / 1;// - 0.5;
|
||||
spot *= ds*100;//clamp(1. - shadow, 0, 1);
|
||||
//}*/
|
||||
///spot *= textureProj(qgl_Light[index].shadow, shp);
|
||||
getShadow(index, pos.xyz, - vds + vds2 + vds2)*/;
|
||||
spot *= shadow;// / 29.;
|
||||
}
|
||||
spot /= (qgl_Light[index].constantAttenuation + ldist * (qgl_Light[index].linearAttenuation + ldist * qgl_Light[index].quadraticAttenuation));
|
||||
///li += spot * gl_LightSource[index].diffuse.rgb * light_diffuse(0, ldir, n);
|
||||
@@ -175,7 +133,17 @@ void main(void) {
|
||||
//qgl_FragData[0].rgb = vec3(abs(lpos.xyz - pos.xyz)/10);
|
||||
//qgl_FragData[0].rgb = li + vec3(texelFetch(t_pp, tc, 0).xyz);
|
||||
//shd = shd - shp.w;
|
||||
vec3 fp = pos.xyz * lpos.w;
|
||||
vec3 _dlp = fp - qgl_Light[0].position.xyz;
|
||||
vec3 _ld = qgl_Light[0].direction.xyz;
|
||||
float lz = dot(_ld, _dlp);
|
||||
vec3 _lt = normalize(cross(_ld, _dlp));
|
||||
vec3 _lt2 = normalize(cross(_lt, _dlp));
|
||||
float ly = dot(qgl_Light[0].shadowDir0.xyz, normalize(_dlp));
|
||||
float lx = dot(qgl_Light[0].shadowDir1.xyz, normalize(_dlp));
|
||||
vec3 dd = mat3(mat_viewi)*(normalize(_dlp) - _ld);
|
||||
//qgl_FragData[0].rgb = vec3(abs(shp.xy/shp.w)/1,0);
|
||||
qgl_FragData[0].rgb = vec3(lx*qgl_Light[0].endAngleCos/1);
|
||||
//qgl_FragData[0].rgb = vec3(abs(mat3(mat_viewi)* qgl_Light[0].direction.xyz));
|
||||
//qgl_FragData[0].rgb = vec3(texture(qgl_Light[0].shadow,shp.xyz/shp.w)/2);
|
||||
//qgl_FragData[0].a = 0.;
|
||||
|
||||
Reference in New Issue
Block a user