Hello Guys!
I Have a problem with lighting when i use Matrix Operations In OpenGL.
I have a Shader in ARB_fragment_program (ASM-like) to render the World. THis is the Shader code:
http://rafb.net/paste/results/dtSw5A83.html
I am 100% sure that the shader is correct.
And also have a moving light that i control it from the keyboard.
I render the world and everything is perfect. I move the light and works correct.
Now the if i try to rotate the world but have the light in the same place then the lighting is not correct the lighting
“follows” the rotation but not the ligh coords. This has as the result to have exactly the same lighting as before no mater
how much rotations/translations or what translations/rotations i Do.
Well… this is correct if you think this:
Lets Say i have a light at position(0,0,0) and i have a triangle that face the light. Lets say that the one vertex of the
triangle is (5,5,5).
If i render the scene the triangle will be lighten (forget the attenuation).
Now if I translate the triangle with glTranslatef(-1,-1,-1) the triangle should be lighten again but the lighting will not
exactly the same. it maybe more or less bright.
This is my problem. no matter what ranslations/rotations i do i get the same result!
This happen because the shader BEFORE the translation takes for input (0,0,0) for the light coords and (5,5,5) and 2 more
vertex coord for the vertex coords.
AFTER the translation the shader still gets the SAME values (because glTranslatef does not change the actual vertex value
e.g.: triangle.vertices[0])
I hope you understand my problem. Any idea what to do to fix this? Maybe some math magin? a matrix multiplication or
something?
this is the code for rendering a polygon:
http://rafb.net/paste/results/SXH3E980.html
Here is a demo with the problem:
http://briefcase.pathfinder.gr/download/unrealbek/27026/319546/0/light+prob.rar
You will see the problem if you move the light a little and start rotate the level(if you not mmove the light and only rotate
the level you will not see the problem because the light is at (0,20,0) position and the level rotate around thes point at
the y axis)
The Keys for this game is:
W, A, S, D and mouse For moving the camera.
R For Reset the level in the origin position
O, P for rotating the world
NumPad 4, 5, 6, 8 for moving the light
The demo requires gfx card Supporting ARB_fragment_program and OGL Shading Language (not used here)