From 2b0b699fa066aa95359d86df9aeb1bdd8d0df195 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 9 Mar 2018 16:46:46 -0800 Subject: [PATCH] Turn off lighting for VR --- demo/client/src/3d-demo.ts | 2 +- shaders/gles2/demo-3d-monument.fs.glsl | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/demo/client/src/3d-demo.ts b/demo/client/src/3d-demo.ts index 41c04766..f893ec98 100644 --- a/demo/client/src/3d-demo.ts +++ b/demo/client/src/3d-demo.ts @@ -719,7 +719,7 @@ class ThreeDRenderer extends Renderer { normal[0] / normal[3], normal[1] / normal[3], normal[2] / normal[3]); - + gl.uniform1f(monumentProgram.uniforms.uLightThings, this.inVR ? 0 : 1); // Draw the face! gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, face * 6 * UINT16_SIZE); } diff --git a/shaders/gles2/demo-3d-monument.fs.glsl b/shaders/gles2/demo-3d-monument.fs.glsl index 8f5e495f..eb6920a4 100644 --- a/shaders/gles2/demo-3d-monument.fs.glsl +++ b/shaders/gles2/demo-3d-monument.fs.glsl @@ -25,22 +25,28 @@ uniform float uShininess; /// The normal of these vertices. uniform vec3 uNormal; +uniform bool uLightThings; + varying vec3 vPosition; void main() { vec3 normal = normalize(uNormal); vec3 lightDirection = normalize(uLightPosition - vPosition); - float lambertian = max(dot(lightDirection, normal), 0.0); - float specular = 0.0; + vec3 color = uAmbientColor; - if (lambertian > 0.0) { - vec3 viewDirection = normalize(-vPosition); - vec3 halfDirection = normalize(lightDirection + viewDirection); - float specularAngle = max(dot(halfDirection, normal), 0.0); - specular = pow(specularAngle, uShininess); + if (uLightThings) { + float lambertian = max(dot(lightDirection, normal), 0.0); + float specular = 0.0; + + if (lambertian > 0.0) { + vec3 viewDirection = normalize(-vPosition); + vec3 halfDirection = normalize(lightDirection + viewDirection); + float specularAngle = max(dot(halfDirection, normal), 0.0); + specular = pow(specularAngle, uShininess); + } + + color = color + uAmbientColor + lambertian * uDiffuseColor + specular * uSpecularColor; } - - vec3 color = uAmbientColor + lambertian * uDiffuseColor + specular * uSpecularColor; gl_FragColor = vec4(color, 1.0); }