Jump to content
  • Advertisement
Sign in to follow this  
MegaPixel

Point Light in view space !

This topic is 3008 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

Hi All,

I've been reading loads of posts on the subject on this forum and this is my

third post on this issue. The thing is that I didn't get any reply concerning

my problem.

I tried checking my code over and over and I still couldn't find a fix for it.

I'm calculating the lighting for a point light in view space, as I'm

implementing a deferred renderer and my problem is that the point lights seems

to follow the camera ... I really really don't know why, I'm trying to figure

this out and I'm damn sure that everything is in view space ( as I verified it ). I rotate normals

in view space and transform the light position in view space (lightPos =

(x,y,z,1)*viewMatrix). Someone in one of my old posts, asked me to post some code, I did it. But

then no reply :(

everything seems correct to me... If necessary I'll post some relevant code (this would be the third time that I do that).

In the meantime this video will show the problem (point lights shading follow

the camera):

http://img706.imageshack.us/img706/4306/lightingissue.mp4

Thanks in advance for any help.

Share this post


Link to post
Share on other sites
Advertisement
Normalmapped lighting could be tricky. There're enough traps to get caught in. I can't really see any issues with your code posted in the other thread. I needed a some time until it worked for me (always discovering small glitches which leads to different bugs).

Potential bugs:
- bug in view matrix calculation
- bug in tangent space calculation
- bug in mapping normals from texture tangent space into camera space
- flipped or inversed normal coords

What helps to debug:
1. visualise normals
2. take surface normals instead of normals from normalmap

Share this post


Link to post
Share on other sites
Quote:
Original post by Ashaman73
Normalmapped lighting could be tricky. There're enough traps to get caught in. I can't really see any issues with your code posted in the other thread. I needed a some time until it worked for me (always discovering small glitches which leads to different bugs).

Potential bugs:
- bug in view matrix calculation
- bug in tangent space calculation
- bug in mapping normals from texture tangent space into camera space
- flipped or inversed normal coords

What helps to debug:
1. visualise normals
2. take surface normals instead of normals from normalmap


Hi Ashaman73 and thanks

I tried to visualise the normals of the normal map converted in view space and

they seem to be correct to me. Plus, tried to calculate the shading using just

the surface normals (no the one fetched from the normal map) and still the shading is following me ... :(

I'll post soon two videos: Normal map in view space and surface normal in view

space space, so that we can carry on from there for any reasoning...

Thanks again

Share this post


Link to post
Share on other sites
Surface normals:

http://img837.imageshack.us/img837/6471/surfacenormals.mp4

Normals from normal map:

http://img838.imageshack.us/img838/8520/normalmapnormals.mp4

Both in view space !

They seem to be correct to me !

Black pointing toward me, red on the right, black on the left, green pointing

up and so on ...

Therefore I exclude bugs in the TBN matrix as I use that matrix to transform

from tangent to view space and From the video they look correct to me. I can't

see any flipped or inversed normals etc.

Poisitions are in view space too obviously ...

then I still don't know what is going on ...

Share this post


Link to post
Share on other sites
Could it be that I forget to pass the world matrix of each mesh of the sponza model ? But still this is nonsense as every mesh is already in its object/world
space otherwise everything wasn't rendered already in place ... :( aaahhhhhhhhhh what the hell is going on :D

Share this post


Link to post
Share on other sites
3 things...


first... make a cornell box... put your lights in it. This will simplify your scene and make it real easy to see what is going on.

second... animate 1 light moving around in a circle inside the cornell box, then 2, then 3 lights.

nothing going wrong? Great!

third... while not/while the lights are animating... do simple camera movements.

This will isolate that you problem lies ONLY within your view matrix.
Once this is done, go into each light and figure out what their view space coordinates should be when the camera is backed up, and check if those calculations make sense.

it took me a long time to figure this out. but i didnt happen until i banged my head against a very simple test case.

[Edited by - AverageJoeSSU on July 19, 2010 11:12:55 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by AverageJoeSSU
3 things...


first... make a cornell box... put your lights in it. This will simplify your scene and make it real easy to see what is going on.

second... animate 1 light moving around in a circle inside the cornell box, then 2, then 3 lights.

nothing going wrong? Great!

third... while the lights are animating... do simple camera movements.

This will isolate that you problem lies ONLY within your view matrix.
Once this is done, go into each light and figure out what their view space coordinates should be when the camera is backed up, and check if those calculations make sense.

it took me a long time to figure this out. but i didnt happen until i banged my head against a very simple test case.


That means that you had the same problem ? And what was the reason in your case ? The viewmatrix was bugged ?... or what?

I remember I started with a plane and one sphere laying on it and If I'm not

wrong that was working quite fine ... but it passed so long since then that I

don't really remember if there was the same problem, since I still wasn't

facing it ...

Thanks for your suggestion I'll definitely build a simple testa case.

Share this post


Link to post
Share on other sites
yep... i had my lights following the camera, and the view matrix was being applied/calculated wrong. i found that treating lights as my game objects worked out well, since the game objects were behaving correctly.

Share this post


Link to post
Share on other sites
Quote:
Original post by AverageJoeSSU
yep... i had my lights following the camera, and the view matrix was being applied/calculated wrong. i found that treating lights as my game objects worked out well, since the game objects were behaving correctly.


But my viewMatrix seems correct, cause the animation as I fly through the scene

is handled correctly ( should this matter ? ). I calculate the viewMatrix

during the camera update using quaternions ... I mean if it was wrongly

calculated I should not be able to see the scene geometry correctly as well,

but actually as you can see from the video the scene geometry is moving fine

with respect to the camera as the camera moves around the scene ...

The only thing that is affected by this is the lighting ... dhu .. :(

Share this post


Link to post
Share on other sites
if you move the camera and the lights move with your camera... something is wrong with your viewmatrix for the lighting. again... simple test case....

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!