diff --git a/qglview/mainwindow.cpp b/qglview/mainwindow.cpp index 2839c26..6cdf851 100644 --- a/qglview/mainwindow.cpp +++ b/qglview/mainwindow.cpp @@ -81,10 +81,11 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow() } view->addObject(obj); - obj->setPos(1000000, -1000000, -10000000); - obj->child("Box001")->addChild(&(view->camera())); + //obj->setPos(1000000, -1000000, -10000000); + //obj->child("Box001")->addChild(&(view->camera())); + //obj->child("Box001")->VBO().translatePoints(QVector3D(20,30,40)); view->camera().setPos(QVector3D(10, -20, 20)); - //view->camera().setAim(obj->pos()); + view->camera().setAim(obj->pos()); view->camera().flyToDistance(500); double al = 7.; diff --git a/qglview/shaders/dsl_pass_1.frag b/qglview/shaders/dsl_pass_1.frag index 962e9a9..d232fc6 100644 --- a/qglview/shaders/dsl_pass_1.frag +++ b/qglview/shaders/dsl_pass_1.frag @@ -23,8 +23,8 @@ vec3 vds, vds2; float sh_pow, sh_mul, dist, NdotL, NdotH, spot, ldist, diff, sdist, shadow; float getShadow(int light, vec3 view_pos, vec3 dpos) { - shp = qgl_Light[light].shadowMatrix * vec4(view_pos, 1); - shp.z -= 0.1; + shp = qgl_Light[light].shadowMatrix * vec4(view_pos + dpos, 1); + shp.z -= 0.05; return textureProj(qgl_Light[light].shadow, shp); } @@ -43,13 +43,13 @@ void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) { spot *= scos * step(qgl_Light[index].endAngleCos, scos); spot *= smoothstep(qgl_Light[index].endAngleCos, qgl_Light[index].startAngleCos, scos); lwdir = mat3(mat_viewi) * qgl_Light[index].direction.xyz; - bn = normalize(cross(lwdir, vec3(1, 0, 0))); - bn2 = normalize(cross(lwdir, bn)); - float ds = ldist/100;//max(abs(sdist) / 5000, 0.02); + //bn = normalize(cross(lwdir, vec3(1, 0, 0))); + //bn2 = normalize(cross(lwdir, bn)); + float ds = ldist/200.;//max(abs(sdist) / 5000, 0.02); //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 = 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. + @@ -69,8 +69,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 *= mix(1., shadow, shadow_on);// / 29.; + getShadow(index, pos.xyz, - vds + vds2 + vds2); + spot *= mix(1., shadow / 29., shadow_on); } 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); @@ -101,8 +101,8 @@ void main(void) { v4 = texelFetch(t4, tc, 0); vec2 sp = gl_FragCoord.xy * dt * 2 - vec2(1, 1); vec3 dc = v0.rgb, n = v1.xyz * 2. - vec3(1.); - //bn = vec3(v3.w, v4.zw); - //bn2 = normalize(cross(n, bn)); + bn = normalize(vec3(v3.w, v4.zw)); + bn2 = normalize(cross(n, bn)); float height = v2.w; li = qgl_AmbientLight.color.rgb * qgl_AmbientLight.intensity; si = vec3(0.); @@ -131,9 +131,10 @@ void main(void) { sh_mul = max(1. - v1.w, 0.0001); for (int i = 0; i < 8; ++i) calcLight(i, n, v, v2); - // calcLight(0, n, v, v2); + calcLight(0, n, v, v2); qgl_FragData[0].rgb = li * dc + si * v2.rgb + v3.rgb + texelFetch(t_pp, tc, 0).rgb; + //qgl_FragData[0].rgb = vec3(vds2.x*1); //qgl_FragData[0].rgb = li + vec3(texelFetch(t_pp, tc, 0).xyz); //shd = shd - shp.w;