Turn off lighting for VR

This commit is contained in:
Manish Goregaokar 2018-03-09 16:46:46 -08:00
parent 3af3635eea
commit 2b0b699fa0
2 changed files with 16 additions and 10 deletions

View File

@ -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);
}

View File

@ -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);
}