Jump to content
  • Advertisement
Sign in to follow this  

HLSL - screen space to projective texture space

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

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
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!