How to do a simple point omnidirectional light

Hi, I’m trying to do a simple point omniderectional light shader.

Here my code for vertex shader:

vec3 lightPos, vertexPos, normal, s;
varying float i;

void main()
    normal = normalize( gl_NormalMatrix * gl_Normal );
    vertexPos = vec3( gl_Vertex * gl_ModelViewMatrix );
    lightPos = vec3( 0, 0, 0 );

    s = normalize( lightPos - vertexPos );
    // The diffuse shading equation
    i = dot( s, normal );

    gl_Position = ftransform();

and this is my fragment shader:

varying float i;

void main (void)
    gl_FragColor = vec4( i, i, i, 1.0);

It doesn’t work fine. I see all my sphere black, and it is positionate in 0, 3, 0 coords.

Any help?

This should be reversed:

    vertexPos = vec3( gl_ModelViewMatrix * gl_Vertex );

The original version effectively transposes the matrix.

Lot of thanks for your response, it no works fin, but the problem now is that I moved the ball, and always recive the same lighting.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.