Rendering to texture, applying pixelshader, then displaying?

Started by
6 comments, last by DvDmanDT 19 years, 1 month ago
Hello.. Some of you read the rotation topic, where I explained what I want I think.. For those of you who didn't: I want to apply a pixelshader to the entire screen instead of to every single polygon.. So people said I should render to a texture, then apply the ps to it, then render the texture.. So.. How do I do that? I'm a newbie.. Should I use SetRenderTarget() to render to texture? Should I call beginscene and endscene twice each frame (once when I render to texture, and once when I render that to the screen)? All help appreciated..
Advertisement

You don't need to call beginscene/endscene every pass. You can go like this:

BeginScene
First pass:
SetRenderTarget()
Render everything.
- note that your pixel shader must save colors, normals, positions, whatever your shader needs to textures, which means you may need multiple render targets.

SetPixelShader()
SetRenderTarget()
SetTexture()
Render full-screen quad
EndScene
Ok.. Umm.. So.. How do I do different rendering passes? :S

My goal is to have a big global pixelshader that will shade the entire screen.. That will shade the texture that is generated.. Do you mean that if I want to have more pixel shaders (well, shade each polygon, like I do now), I have to shade to different textures than the render target? Why is that?
The 'rendering' is Draw(Indexed)Primitive calls, is that what you mean? The begin and end scene represent an entire 'frame'.
Begin scene
- set render target to the texture (or it's surface, whatever)
- clear the texture
- render the scene as you would normally

- set render target back to the device's surface
- clear the surface
- render your textured quad with your vertex/pixel shader post processing effect, using the texture you rendered to before as your quad's texture. The vertex shader should move the quad in front of the camera for you, assuming you have it do that.
End Scene
But textures must be quads, don't they? Like, both sides must be equally long, and that should be an exponent of 2 as well.. I've figured how to render to a surface (those can rectangular, right?), but not what to do next.. I can't apply a surface as a texture..

My current plan is to do the following:
Create a LPD3DXRENDERTOSURFACE, and just call BeginScene with a LPDIRECT3DSURFACE9 that will then be drawn to.. Then I call EndScene on the LPD3DXRENDERTOSURFACE thingy.. But.. How do I get the data on the surface to the screen, after applying the pixel shader?



[Edit 5 mins later]
Ok, now I've learnt that a texture can be rectangular, and that sure made my life 50 times easier.. Thanks everyone for your help.. I think I get it now..
Vær så god ;)

("jag" kann ikke svensk:P)

The texture will be stretched to fit your screen, and also the render target will determine the resolution, so a texture thats 256x256 representing 800x600 will look poor & stretched (obviously).
Accutually, I made a texture with the size of the resolution (1024x768).. At first I saw some gfx bugs, and I thougth it was caused by the size.. Later on I realized it was caused by my bad math.. I had set the right vertexes x value to 1024.0 instead of 1023.0 as it should be (as it starts on 0).. Same with height, so therefore there was some gfx bugs, but now it works pretty lovely..

This topic is closed to new replies.

Advertisement