Jump to content
  • Advertisement
Sign in to follow this  
Unreal

OpenGL Lighting problem - math Problem. Problem with rotations/translations. Plz help!

This topic is 5472 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post


Link to post
Share on other sites
Advertisement
>>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 <<

i didnt test the demo or look at the code but it sounds like youre not scecifying where the lightsource relative to the camera, with shaders this is treated exactly like standard opengl ie after u move the camera u have to update the lights

Share this post


Link to post
Share on other sites
ok... Now At the place I Rotate the level I multiply the light position with with the tranpose modelViewMatrix of the level and it works!!! But If I move the camera then... all hell... Any idea how to fix this?
Here is my code:
http://rafb.net/paste/results/uFbPH586.html

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!