Hi,
I'm using a simple shader in my app that implements per-pixel lighting and texturing.
Here's the frag shader:
varying vec3 N;
varying vec3 v;
uniform sampler2D tex;
void main (void)
{
vec3 L = normalize(gl_LightSource[0].position.xyz - v);
vec3 E = normalize(-v); // we are in Eye Coordinates, so EyePos is (0,0,0)
vec3 R = normalize(-reflect(L,N));
//calculate Ambient Term:
vec4 Iamb = gl_FrontLightProduct[0].ambient;
//calculate Diffuse Term:
vec4 Idiff = texture2D(tex, vec2(gl_TexCoord[0])) * gl_FrontLightProduct[0].diffuse * max(dot(N,L), 0.0);
// calculate Specular Term:
vec4 Ispec = gl_FrontLightProduct[0].specular
* pow(max(dot(R,E),0.0),0.3*gl_FrontMaterial.shininess);
// write Total Color:
gl_FragColor = gl_FrontLightModelProduct.sceneColor + Iamb + Idiff + Ispec;
}
Before drawing the object, I'm doing:
_shader->begin()
glBindTexture(GL_TEXTURE_2D, _texture->getId());
...
And it works! Shouldn't GLSL complain because I'm not sending the tex uniform?? And even if it doesn't complain... wy does it work?
Edit: actually, setting the uniform gives me gl error #1282 (invalid operation) :(
Thanks!
[Edited by - FreJa on December 17, 2008 1:42:45 PM]
"Through me the road to the city of desolation,Through me the road to sorrows diuturnal,Through me the road among the lost creation."