I've been trying to work with WebGL and finally managed to find a 1-line change that can break one of the demos.
https://github.com/KhronosGroup/WebGL/blob/master/sdk/demos/webkit/SpiritBox.html
has a vertex shader :
uniform mat4 u_modelViewProjMatrix;
uniform mat4 u_normalMatrix;
uniform vec3 lightDir;
attribute vec3 vNormal;
attribute vec4 vTexCoord;
attribute vec4 vPosition;
varying float v_Dot;
varying vec2 v_texCoord;
void main()
{
gl_Position = u_modelViewProjMatrix * vPosition;
v_texCoord = vTexCoord.st;
vec4 transNormal = u_normalMatrix * vec4(vNormal, 1);
v_Dot = max(dot(transNormal.xyz, lightDir), 0.0);
}
The demo shows a spinning box with a picture of a puppy on each face.
If we add a single line to the end of the shader function:
v_Dot = 1.0;
then the box now renders as white. Switching from =1.0 to
v_Dot = max(v_Dot, 1.0);
makes the puppy reappear.
Here's a copy of the fragment shader just in case the link is broken:
precision mediump float;
uniform sampler2D sampler2d;
varying float v_Dot;
varying vec2 v_texCoord;
void main()
{
vec2 texCoord = vec2(v_texCoord.s, 1.0 - v_texCoord.t);
vec4 color = texture2D(sampler2d, texCoord);
color += vec4(0.1, 0.1, 0.1, 1);
gl_FragColor = vec4(color.xyz * v_Dot, color.a);
}
What the heck is going on here? I am using Firefox version 24.7.0 .
v_Dot = 1.0;
, thevNormal
vertex attribute is no longer used, so the shader compiler will probably delete it from the program, and I've occasionally seen bugs in framework code that don't handle missing attributes / uniforms gracefully. – Dietrich Epp