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

Recommended Posts

mancubit    536
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 on other sites
mancubit    536
..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