This is my fragment shader:
Code :varying vec3 n; varying vec3 position; varying vec2 tex_coord; uniform sampler2D wood_tex; uniform int light2; void main() { vec3 light = normalize((gl_LightSource[2].position - position).xyz); vec3 h = normalize(normalize(- position) + light); vec4 amb = gl_LightSource[2].ambient * gl_FrontMaterial.ambient; vec4 diff = gl_LightSource[2].diffuse * gl_FrontMaterial.diffuse * max(0.0, dot(n, light)); vec4 spec = gl_LightSource[2].specular * gl_FrontMaterial.specular * pow(max(0.0, dot(h, n)), gl_FrontMaterial.shininess); vec4 wood = texture2D(wood_tex, tex_coord); vec4 color = vec4(0.0,0.0,0.0,0.0); color = (amb + diff) * wood + spec; gl_FragColor = color; }
Vertex shader:
Code :varying vec3 n; varying vec3 position; varying vec2 tex_coord; void main() { n = normalize(gl_NormalMatrix * gl_Normal); position = (gl_ModelViewMatrix * gl_Vertex).xyz; tex_coord = gl_MultiTexCoord0.st; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
I use these shaders to texture object in my scene. The problem is that when the scene is loaded the object is already illuminated even though the light is turned off. I would like to ask how can I make the shader illuminate the object only when the light is turned on and when I turn the light off the shader will also stop illuminating the object.