Hi, i’m trying to write point light shader, as listed.
When i use the light vector:
L = vec3(gl_LightSource[0].position - V4);
the position comes from GL_LIGHT and it’s already in eye-space.
And thats fine - it works correctly, but what i need is the
light position passed as vec4 vector, for example vec4(5,5,5,1).
What exactly transformations do I need to use to make vec4 behave
like GL_LIGHT position ?
please help me
void main(void)
{
vec3 camPos = vec3(100,20,100);
vec3 L,R,H,C,Cx,S,V,N;
vec4 diff,spec,V4,L4;
vec4 color = gl_FrontLightModelProduct.sceneColor;
float diffuse, specular, d ,att;
C = vec3(0.0,0.0,1.0);
vec4 parameter[2];
parameter[0] = vec4(5,5,5,1);
parameter[1] = vec4(1,1,1,0);
gl_FrontColor = vec4(0.0);
//V4 = gl_Vertex;
N = normalize(gl_NormalMatrix * gl_Normal);
//N = normalize(gl_Normal);
N = N * gl_NormalScale;
//V4 = gl_ModelViewMatrix * gl_Vertex;
V4 = gl_ModelViewMatrix * gl_Vertex;
//N = normalize(gl_Normal);
vec4 position = vec4(parameter[0]);
specular = 0.0;
//L = normalize(vec3(gl_ModelViewMatrix * vec4(parameter[i].xyz,1.0)));
L = vec3(gl_LightSource[0].position - V4);
//L = vec3(position - V4);
//Cx = -normalize(V);
L = normalize(L);
diffuse = max(0.0,dot(N,L));
H = normalize(L + C);
if(diffuse > 0.0)
specular = pow(max(0.0,dot(N,H)),gl_FrontMaterial.shininess);
diff = vec4(parameter[1].xyz,0.0) * diffuse;
spec = vec4(parameter[1].xyz,0.0) * specular;
color += diff * gl_FrontMaterial.diffuse + spec * gl_FrontMaterial.specular;
gl_FrontColor = color;
gl_Position = ftransform();
}