Advertisement Jump to content
Sign in to follow this  

Pixel shader, appliing on entire screen

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


I dont know if somebody had done this ever... maybe I wont give clear question...

I have a small pixelshader function, which distorts the screen (manipulating the output .u, .v coordinates). Lets imagine I have a "glasses" wrapped to a "window" looking a player through.

In 2D, I successfully did this. In other words, I have a "backroundTexture" variable. If this is 0, I want to apply this PS to the backbuffer, if not 0, I have a normal texture to apply to this. It worked, and only good for total 2D purposes:

- backgroundTex = target textures (IDirect3DTexture8) turn Z buffering off
- SetVertexShader (D3DFVF_XYZRHW or D3DFVF_TEX2)
- SetTexture (0, BackgroundTexture)
- SetTexture (1, BumpmapTexture)
- SetStreamSource (0, BumpVertex) [bumpvertex is {p: TD3DXVector4; u1,v1,u2,v2 : float;}
- SetPixelShader (compiled PS)
- DrawPrimitive draw the texture+pshader
- SetTeture 0,1, NULL
- Enabling Z buffer

here's the PS routine, if somebody is interested in:
sampler2D input0 : register(s0);
sampler2D input1 : register(s1);
float4 main(float4 uv : TEXCOORD0, float4 uv2 : TEXCOORD1) : COLOR
float4 Color = tex2D(input1, uv2.xy);
uv2.x = uv.x + Color.r - 0.5;
uv2.y = uv.y + Color.g - 0.5;
return tex2D(input0, uv2.xy);

well that's OK. Works, but now I want to distort not a specific texture, but a backbuffer. I know, backbuffer is a "surface" and not texture.
Somehow I should copy the backbuffer and make a texture from it. And also I should think of the stencil buffer.

How to solve this all? Any idea please?

Share this post

Link to post
Share on other sites
You don't apply it to the back buffer. What you do is create a back buffer sized render target. Render your scene to that instead of the back buffer. You can then use that render target as the texture input to your shader.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!