lighting calculations causing transparency??
I am just learning OpenGLES 2.0 and am having trouble with textures, blending and shading. I have a working example where I texture-map a cube. I'm working off the tutorials provided here:
At the end of that tutorial they apply a decal-like second texture map, and they enable blending so that the alpha in the decal is applied correctly.
glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
However, when I do it, it does work but also it has the side effect of turning all the rest of my objects half-transparent!
I think this is happening in my vertex shader, in the calculations that create the color:
attribute vec4 position;
attribute vec3 normal;
varying lowp vec4 colorVarying;
uniform mat4 modelViewProjectionMatrix;
uniform mat3 normalMatrix;
attribute vec2 TexCoordIn;
varying vec2 TexCoordOut;
vec3 eyeNormal = normalize(normalMatrix * normal);
vec3 lightPosition = vec3(0.0, 0.0, 1.0);
vec4 diffuseColor = vec4(0.7, 0.7, 1.0, 1.0);
float nDotVP = max(0.0, dot(eyeNormal, normalize(lightPosition)));
colorVarying = diffuseColor * nDotVP; // this multiplication causes it?
gl_Position = modelViewProjectionMatrix * position;
TexCoordOut = TexCoordIn;
This produces half-transparent objects.
In my tests though, if I skip the lighting multiplication (*nDotVP) above, and I just set colorVarying = diffuseColor, then the object becomes solid again. It seems like there is something in those lighting-eye calculations which is mangling the alpha value, is that possible? Anyone know why or how I can fix it?