I was trying to debug a problem with a bump mapping shader, when I was surprised when my simple glsl code for debug did not work.
The following code crashes:
uniform sampler2D diffuse_map;
uniform sampler2D normal_map;
varying vec3 lightVec;
varying vec3 halfVec;
varying vec3 eyeVec;
void main (void)
{
gl_FragColor= vec4(texture2D (normal_map, gl_TexCoord[0].st).rgb, 1.0);
}
But this other code did not:
uniform sampler2D diffuse_map;
uniform sampler2D normal_map;
varying vec3 lightVec;
varying vec3 halfVec;
varying vec3 eyeVec;
void main (void)
{
vec2 texCoords;
texCoords = gl_TexCoord[0].st;
// fetch normal from normal map, expand to the [-1, 1] range, and normalize
vec3 normal = 2.0 * texture2D (normal_map, gl_TexCoord[0].st).rgb - 1.0;
normal = normalize (normal);
// compute diffuse lighting
vec3 diffuse = max (dot (lightVec, normal), 0.0) * vec3 (gl_LightSource[1].diffuse);
vec3 decalColor = texture2D (diffuse_map, texCoords).rgb;
// compute specular lighting
//vec3 specularCoeff = texture2D (glossMap, texCoords).rgb;
float specular = max (dot (halfVec, normal), 0.0);
specular = pow (specular, 8.0);
// output final color
gl_FragColor = vec4 (diffuse * decalColor + vec3 (specular), 1.0) + gl_LightSource[1].ambient;
}