Problem with light position

So I’ve been following a few tutorials about GLSL per-fragment lighting in OpenGL 2.0 and I’ve finaly managed to write simple shader for that, here’s result:

The overal lighting effect is, in my opinion very good and I’m satisfied with it but I have problem with positioning my point light, actually light follows my camera all the time even if I want it to stay at vec3(0,0,0) in world space.

I’m pretty new to GLSL and 3D math so I’d like to know where are I’m doing mistake, any code and explaination would be highly appericated as I’ve already spent lots of time trying diferent combinations and I cant continue my project without getting this thing done.

Here’s my vertex shader:

#version 110

varying vec3 position;
varying vec3 normal;

void main()
    vec4 eyeCoordPos = gl_ModelViewMatrix * gl_Vertex;

    position = / eyeCoordPos.w;
    normal = normalize(gl_NormalMatrix * gl_Normal);

    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    gl_TexCoord[0] = gl_MultiTexCoord0;    

and my fragment shader:

#version 110

uniform sampler2D colorMap;
uniform float shininess;

uniform vec4 lightPos;
uniform float lightRadius;

uniform vec4 lightColorAmbient;
uniform vec4 lightColorDiffuse;
uniform vec4 lightColorSpecular;

varying vec3 position;
varying vec3 normal;

void main()
    vec3 l = -;
    float d = length( l );
    float atten = 1.0 - (d/lightRadius);

    l = normalize(l);

    vec3 n = normalize( normal );
    vec3 v = normalize( -position );
    vec3 h = normalize( l + v );
    float nDotL = max(0.0, dot(n, l));
    float nDotH = max(0.0, dot(n, h));
    float power = (nDotL == 0.0) ? 0.0 : pow(nDotH, shininess);
    vec4 ambient = lightColorAmbient * atten;
    vec4 diffuse = lightColorDiffuse * nDotL * atten;
    vec4 specular = lightColorSpecular * power * atten;
    vec4 color = ambient + diffuse + specular;
    gl_FragColor = color * texture2D( colorMap, gl_TexCoord[0].st );

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