Jump to content
  • Advertisement
Sign in to follow this  
genesys

problem with texturecoordinates for renderToTexture-texture

This topic is 4725 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! I've got some problems. I'm creating effects by rendering a certain scene with certain shaders to a renderToTexture target and then lay this texture over objects in a secound pass. For the right projection (what i wan't is to project the image from the camera - so that it has exactly the same output as if the rendering goes directly to the backbuffer - if you understand what i mean...) for doing this, i use the following technique to generate the UV's which will be used for the tex2D image lookup: float4 pPos = mul(matViewProjection, float4(Input.Position.xyz,1)); float3 eyeLinear; eyeLinear.x = 0.5 * (pPos.z + pPos.x); eyeLinear.y = 0.5 * (pPos.z - pPos.y); eyeLinear.z = pPos.z; float2 uvset; uvset = eyeLinear.xy/eyeLinear.z; I've got this technique from the RenderMonkey examples... It's working - but not very good - because the texture is dependant to the window aspect ration - means if i stretch the window, the textureprojection get's alos stretched. Therefore it's only working if the window is quadratic. (But even then the projected texture doesn't fit the actual backbuffer rendering verry good - there are always some differences) Can someone help me with that? Please - I just don't get it to work like i want it... Thx for help!

Share this post


Link to post
Share on other sites
Advertisement
You can try it by this way, I copy it from my shader and comment it, hope me understand what you mean ;)

// in vs
oPos = mul(position, mWVP); // position: input vertex's position
// mWVP: matrix of World*View*Projection
oUv1 = mul(position, mProjTex);
// mProjTex:
// 0.5 0 0 0
// 0 -0.5 0 0
// 0 0 0.5 0
// 0.5 0.5 0.5 1

// in ps
// you may project a texture on this model with uv1
half4 reflectObjColor = tex2Dproj(s2, uv1);

Share this post


Link to post
Share on other sites
It may not be an issue with the shader. It may be with how you handle a resizing of the window. Do you reset the proper elements, such as the presentation parameters and the perspective matrix upon a resize?

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!