Sign in to follow this  

Rendering to texture, applying pixelshader, then displaying?

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

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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites

This topic is 4661 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this