   Problem setting a point light in GLSL.
  I want to create a Point Light using GLSL, but since I'm a shader n00b, I'm needing some help.I started with the brick shader from the OpenGL Shading Language book(2nd edition. Yep, I have the book.), but as I put the shader to work in my C++ game, the things does not work correctly. The main problem, is that the point light follows the camera, but I don't want that. I want that a torch for example in the scene, iluminates a small area, and don't follow the dammit camera. What I can do to fix this problem? I'm having problems to understand the logic behind the shader programming. I have read the book, read the sources of variuos shaders, but keep undertanding almost nothing... but I'll keep trying until I undertand this thing :D   
  That's not a shader issue, it exists in the fixed function pipeline as well. The issue is with passing the light coordinates in world space or view space. If you want the light to stay stationary, transform its coordinates using the Current Transformation Matrix and pass those to the shader. If you want the light to move with the camera, pass the coordinates untransformed.EDIT: on a second thought, it entirely depends on how you are doing your lighting calculations. Are you doing lighting calculations in eye coordinates or world coordinates?   ;  world coordinates. But so I multiply the LightPosition by what? I don't get the point.   ;  I can't remember the exact way to do this in world coordinates, but you can try a few things and you'll get it right eventually.- Multiply the light's position by the current transformation matrix.- Multiply the light's position by the the inverse of the current transformation mastrix.- Keep the world matrix and the view matrix separate (as in DirectX) and try using those matrices instead.I can't give you a definite answer because it all depends on: matrix row major vs column major order in the shader, premultiplication vs postmultiplication of coordinates, calculating normals in world space, eye space or clip space, etc There are so many factors, it's not event funny :-)If you can post the shader code and the OpenGL code, I can help you better.EDIT: Basically, your problem right now is that your light is not getting transformed by the camera, so it always stays in the same spot on the screen. That's why it's moving with the camera, instead of staying stationary in the world. If you transform the light's position correctly, it will behave like you want.   ;uniform vec3 LightPosition;const float SpecularContribution = 0.3;const float DiffuseContribution  = 1.0 - SpecularContribution;varying float LightIntensity;varying vec2  MCposition;void main(){    vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);    vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);    vec3 lightVec   = normalize(LightPosition - ecPosition);    vec3 reflectVec = reflect(-lightVec, tnorm);    vec3 viewVec    = normalize(-ecPosition);    float diffuse   = max(dot(lightVec, tnorm), 0.0);    float spec = 0.0;    if (diffuse > 0.0)    {   spec = max(dot(reflectVec, viewVec), 0.0);   spec = pow(spec, 16.0);    }    LightIntensity  = DiffuseContribution * diffuse +  SpecularContribution * spec;    MCposition = gl_Vertex.xy;    gl_Position= ftransform();}uniform vec3  BrickColor, MortarColor;uniform vec2  BrickSize;uniform vec2  BrickPct;varying vec2  MCposition;varying float LightIntensity;void main(){    vec3  color;    vec2  position, useBrick;   position = MCposition / BrickSize;    if (fract(position.y * 0.5) > 0.5)   position.x += 0.5;    position = fract(position);    useBrick = step(position, BrickPct);    color  = mix(MortarColor, BrickColor, useBrick.x * useBrick.y);    color *= LightIntensity;    gl_FragColor = vec4(color, 1.0);};  Aaaah, so you are doing lighting calculatins in eye space. Then it's quite easy, just transform the light's position by the modelview matrix (in OpenGL code) and pass that into the shader. If you are too lazy to do that (it's tricky in OpenGL) you can change the GLSL code do do just that, but it's kind of wasteful:vec3 lightVec = vec3(normalize(gl_ModelViewMatrix * vec4(LightPosition, 1.0) - ecPosition));EDIT: I think the above will only work if you are not moving your objects around. If you are, then the light will be moving with the objects!The reason why you need to do that is because your lighting calculations should be done in one coordinate system, you can't just mix up world space with eye space with clip space and expect it to work.   ;  I thowed away the code that render the procedural bricks. So the code become this:uniform vec3 LightPosition;const float SpecularContribution = 0.3;const float DiffuseContribution  = 1.0 - SpecularContribution;varying float LightIntensity;void main(){vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);vec3 lightVec   = vec3(normalize(gl_ModelViewMatrix * vec4(LightPosition, 1.0) - ecPosition));vec3 reflectVec = reflect(-lightVec, tnorm);vec3 viewVec    = normalize(-ecPosition);float diffuse   = max(dot(lightVec, tnorm), 0.0);float spec = 0.0;if (diffuse > 0.0){spec = max(dot(reflectVec, viewVec), 0.0);spec = pow(spec, 16.0);}LightIntensity  = DiffuseContribution * diffuse +SpecularContribution * spec;gl_Position= ftransform();}varying float LightIntensity;void main(){vec3  color;color = LightIntensity;gl_FragColor = vec4(color, 1.0);}But the things become dark. When I move the camera(is a FPS style camera), randomly I see my ground. But strangely, I see the things very clearer in the floor away above. In other words, doen't work correctly. I'm positioning the light(passing to the shader) at 0,0,0.I just want something that works like the fixed functionality of OpenGL. Is that hard to program shaders like this one?;  Arghhh... never mind. I was thinking Cg and DirectX. GLSL and OpenGL works a little bit differently. When you use glLight() function, OpenGL automatically transforms the light position into eye space using the Current Transformation Matrix. That means that the shader receives the light position in eye space, so you don't need to do gl_ModelViewMatrix * vec4(LightPosition, 1.0) in the shader.So, to solve your problem, you must modify the C++ code. To make the light stationary, apply a viewing transformation, set the light position and then apply a world transformation.Here is some pseudocode:glLoadIdentity();gluLookAt(...); //viewing transformationglLightfv(...); //set the light's position and transform it using the above matrixglPushMatrix(); //start drawing the objectglTranslatef(...); //apply translation on the object (and not the light)glRotatef(...); //apply a rotation on the object (and not the light)glPopMatrix();;  Look at the screenshot. Without the multiplication, the light follows the camera. Like before... But with the multiplication, things does not work correctly.[link]http://geocities.yahoo.com.br/megaspeedlinux/und/screens/sp01.jpg[/link][link]http://geocities.yahoo.com.br/megaspeedlinux/und/screens/sp02.jpg[/link]And yes, I'm doing the rendering like you said.   ;  Did you change that line of code in the shader back to vec3 lightVec = normalize(LightPosition - ecPosition);EDIT: GLSL has a built-in light uniform. You can use gl_LightSource[0].position instead of LightPosition. It will get mapped to glLightfv.   