Sign in to follow this  

[solved] world to screen/uv-space conversion problems

Recommended Posts

i want to implement a lightshaft shader (details: gpu-gems3-lightshafts) but have problems in transforming my light-worldposition to screenspace uv-coordinates. basically i do the following: vertex shader:
vOut.posLight =  mul(float4(gLight.pos, 1.0f), gWVP);

where gLight.pos is my light position in world-space and gWVP is my world * view * proj matrix then i convert this position in my pixel-shader to uv-coordinates in screenspace:
float2 posL = float2(pIn.posLight.x / pIn.posLight.w,pIn.posLight.y / pIn.posLight.w);
posL.x = posL.x * 0.5f + 0.5f;
posL.y = -posL.y * 0.5f + 0.5f;

after this, i thought posL should have the uv-coordinates of my light in screenspace (for example (0.5f, 0.5f) when in middle of screen) but unfortunately this doesnt work - and i dont know why - anybody knows whats wrong with my calculations? thanks in advance! [Edited by - mancubit on March 28, 2010 7:26:18 PM]

Share this post

Link to post
Share on other sites
..oh man - i shouldnt multiply with the world-matrix if the light position is already in world-space - stupid little mistake that cost me about 6 hours

now it works perfectly

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this