Sign in to follow this  
supagu

HLSL - screen space to projective texture space

Recommended Posts

im sampling a texture in screen space. I'm then getting calculating a point in 3d screen space from this sample. Then im converting back to object space. After that i convert to the screen space of my projector, so i can do another a projective texture sample. vertex shader:
float4 hPos = mul(Po, worldViewProj);
    OUT.hPosition = hPos;
	OUT.uvScreen = hPos;

pixel shader:

// convert screen space to texture for projective lookup of depth texture
float2 screenTex = 0.5 * ((IN.uvScreen.xy / IN.uvScreen.w) + float2(1,1));
	screenTex.y = 1.0 - screenTex.y;

	float depthSample = depthTexture.Sample(samPointClamp, screenTex).r;

// convert my 3d screen space to object space
float4 oBack = mul(float4(IN.uvScreen.xy, depthSample, 1), worldViewProjInv);

// convert to projector screen space
float4 hLightBack = mul(oBack, projector.worldViewProj);

// convert for projective texture
float2 lightScreenTexFront = 0.5 * ((hLightFront.xy / hLightFront.w) + float2(1,1));
	lightScreenTexFront.y = 1.0 - lightScreenTexFront.y;

this seems to work sort of, i can see my texture being projected reasonably in the rough area, how ever moving the camera around causes this to jitter around significantly. any ideas what could be wrong?

Share this post


Link to post
Share on other sites
i've also tried converting back to world space instead of back to object space, but still not working :-/

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