Skip to main content
GameDev.net gamedev.net
🔒 Locked

problem with texturecoordinates for renderToTexture-texture

Started by genesys Oct 11, 2005 at 3:00 AM 1 replies 700+ views
Original Post
genesys
genesys
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!
lxxxk
lxxxk
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);
Supernat02
Supernat02
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?
Chris ByersMicrosoft DirectX MVP - 2005

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.