Mukund
08-06-2011, 09:57 AM
Hello Everyone,
I needed a small clarification w.r.t the following:
Say we have something like this:
// Fragment Shader
uniform float val;
void main(void)
{
float intensity = dot(vec3(gl_LightSource[0].position),normal);
if (intensity > 0.9)
gl_FragColor = vec4(val, val, val, 1);
}
Now, i could not understand why the uniform variables were used in this way. The "val" passed was a constant. So, wouldn't if make more sense with this:
if (intensity > 0.9)
gl_FragColor = vec4(0.5, 0.5, 0.5, 1); // assume val=0.5
Or, is there any specific reason behind using uniforms in Fragment shaders? I understand that using varying variables from vertex to fragment shader yields interpolation. But, is there any particular reason for using uniforms in Fragment shaders or is it just a way of passing data to the fragment shader?
Can anyone please clarify this for me?
Thanks.
I needed a small clarification w.r.t the following:
Say we have something like this:
// Fragment Shader
uniform float val;
void main(void)
{
float intensity = dot(vec3(gl_LightSource[0].position),normal);
if (intensity > 0.9)
gl_FragColor = vec4(val, val, val, 1);
}
Now, i could not understand why the uniform variables were used in this way. The "val" passed was a constant. So, wouldn't if make more sense with this:
if (intensity > 0.9)
gl_FragColor = vec4(0.5, 0.5, 0.5, 1); // assume val=0.5
Or, is there any specific reason behind using uniforms in Fragment shaders? I understand that using varying variables from vertex to fragment shader yields interpolation. But, is there any particular reason for using uniforms in Fragment shaders or is it just a way of passing data to the fragment shader?
Can anyone please clarify this for me?
Thanks.