Jump to content
  • Advertisement
Sign in to follow this  
manxankur

Deferred: From World to View [SOLVED]

This topic is 3175 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, Ok, i want to change my deferred so that it is using view space instead of world space for the lighting calculations. From what i've read on the forums and internet i have to: Transform the normals to view space Transform the camera position to view space (this will just be (0,0,0), right?) Transform the light direction/position/interest to view space I've done this with a simple mul( vector, g_view ) in the vertex or pixel shader but this causes the directional light to move around when the camera moves. If i use the transpose of the inverse of the view matrix then the scene is nearly all black. oh, by the way, I'm working in XNA. Can someone please give me a step by step explanation as to what needs doing and possibly how to do it? EDIT: I forgot to mention, when i just set the camera position to (0,0,0) then the directional light works. So, all the normals and the direction light vector are still in the world position. The directional light is currently set to (0,1,0). [Edited by - manxankur on October 14, 2009 6:31:27 AM]

Share this post


Link to post
Share on other sites
Advertisement
Camera position in view-space is indeed (0,0,0)

You have to be careful with when you should and shouldn't translate vectors by the view matrix. Anything that's a position (like light position, vertex position, etc.) should be translated. To ensure it gets translated, make sure you've converted it to a float4 with the w component set to 1. If you leave it as a float3 or set w to 0 you won't get any translation. For anything that's a normalized direction (light direction, light-to-pixel, etc.) you want to only rotate it which means you should leave it as a float3.

Share this post


Link to post
Share on other sites
Hi MJP,

Ok, i've done what you told me to do and now the directional lights are nearly working. I'll explain what i'm doing now:

- Initial pass in deferred (Vertex shader):

// It's normal view matrix; not inversed or transposed.
// Input.Normal and output.Normal are float3
output.Normal = mul(Input.Normal, mul(World, View));



- Directional light pass (Pixel shader):

//Camera position is set to (0,0,0)
// g_lightDir is a float3.
float3 unit_light_dir = normalize(mul(g_lightDir, View));



The directional light is set to (0,1,0) and this is what i'm getting when i'm looking down at the scene:


And this is what i should get (i'm getting this result from using world space)


Is there something else i might be doing wrong?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!