L.BB
03-02-2006, 07:20 AM
Hi,
I wanted to ask if it is possible to assign a normal vector to every pixel in a shader, and if yes how to do that. I want to declare a polygon and then assign different colour depending on the normal vector of the pixel (which I got from a normal map), the light direction and the light colour. How would I go about doing that. I so far have this fragment shader that I am tring to change now:
vec3 n,halfV,viewV,ldir;
float NdotL,NdotHV;
vec4 color = ambient;
/* a fragment shader can't write a verying variable, hence we need a new variable to store the normalized interpolated normal */
n = normalize(normal);
/* compute the dot product between normal and ldir */
NdotL = max(dot(n,lightDir),0.0);
if (NdotL > 0.0) {
halfV = normalize(halfVector);
NdotHV = max(dot(n,halfV),0.0);
color += gl_FrontMaterial.specular *
gl_LightSource[0].specular * pow
(NdotHV,gl_FrontMaterial.shininess);
color += diffuse * NdotL;
}
gl_FragColor = color;
But how would I go about specifying a different normal for every pixel?? I would appreciate any tipps or even if I this can be done or not etc. cause am only starting out with GLSL
I wanted to ask if it is possible to assign a normal vector to every pixel in a shader, and if yes how to do that. I want to declare a polygon and then assign different colour depending on the normal vector of the pixel (which I got from a normal map), the light direction and the light colour. How would I go about doing that. I so far have this fragment shader that I am tring to change now:
vec3 n,halfV,viewV,ldir;
float NdotL,NdotHV;
vec4 color = ambient;
/* a fragment shader can't write a verying variable, hence we need a new variable to store the normalized interpolated normal */
n = normalize(normal);
/* compute the dot product between normal and ldir */
NdotL = max(dot(n,lightDir),0.0);
if (NdotL > 0.0) {
halfV = normalize(halfVector);
NdotHV = max(dot(n,halfV),0.0);
color += gl_FrontMaterial.specular *
gl_LightSource[0].specular * pow
(NdotHV,gl_FrontMaterial.shininess);
color += diffuse * NdotL;
}
gl_FragColor = color;
But how would I go about specifying a different normal for every pixel?? I would appreciate any tipps or even if I this can be done or not etc. cause am only starting out with GLSL