How to do post processing??

Started by
5 comments, last by FeverGames 15 years, 4 months ago
Can someone please tell me how to do post processing effects in DirectX using shaders?? ive been trying for days to use a simple blur shader found here: http://www.gamedev.net/community/forums/topic.asp?topic_id=427696 how do i use it to blur a preloaded texture (say a wallpaper)?? should i render the scene with a full screen quad and set the texture "ForegroundTexture" to the texture which i have already loaded?? is this the only way to do this?? I have tried this and all i get is a white screen!! i dont know what to do!! also in the link it says VertexShader=NULL; does that mean that there is no vertex shader at all in the pipeline or does it mean that the FFP vertex shader is used?? is it possible to use a pixel shader directly on a texture without rendering any geometry on the screen??? im extremely confused about everything ... Please explain step by step.. with an example code if possible..(not just the fx file i mean even the c++ code so that it would be clear as to how to implement it)!! thanks!
Advertisement
There are a few steps:

- Render your scene to a texture (and not to the screen! - keyword: SetRenderTarget)
- Blur that texture using a pixelshader, the vertexshader will only have the ability to move and change the vertices, you want to work with pixels (shader tutorials by wolfgang engel might be good)
- Render the result to the screen

You could look at rendermonkey as the workspace gives you a pretty good idea how the whole system works.
thanks for the reply !! however i think i didnt state my problem clearly... im wondering how to stream a set of pixels (like from a render target texture) through a pixel shader without calling a vertex shader... what are the functions needed to do this...??
do a search on transformed positions and pixel shaders, or try finding out how the spritebatch works... That does exacly what you want. A full screen quad render class.
You still need something which processes the vertices first (atleast afaik), you will have 4 vertices: one in the top left corner-, top right corner-, bottom left corner-, bottom right corner of your screen.
Those wouldn't have to be transformed (because you already have them in screen-space) or anything by the vertexshader so you could just forward them, you should have the same result if you use D3DFVF_XYZRHW in the fixed function pipeline.
Each of the rendered pixels would be processed by the pixelshader. You will have 2 triangles (using the vertices I mentioned above) which will cover the whole screen, so each pixel of the screen would be processed (and you could blur them for example)
thanks a lot!! this is what ive been doing so far... so i guess i must be making mistakes somewhere else.. but just one more thing.. supposing i wanted to do 3 or 4 consecutive full screen postprocess effects on a scene.. then how should i proceed??
something like this??:

1) render the base frame to texture1
2) send texture1 to the vertex shader via the quad
3) execute next pass
4) send output to texture2
5) send texture2 to the vertex shader via the quad
6) execute next pass
7) send output to texture3 etc...


until the final output is to the backbuffer????
is this how its supposed to be done?? or is there a better way??
Quote:Original post by rohith291991
thanks a lot!! this is what ive been doing so far... so i guess i must be making mistakes somewhere else.. but just one more thing.. supposing i wanted to do 3 or 4 consecutive full screen postprocess effects on a scene.. then how should i proceed??
something like this??:

1) render the base frame to texture1
2) send texture1 to the vertex shader via the quad
3) execute next pass
4) send output to texture2
5) send texture2 to the vertex shader via the quad
6) execute next pass
7) send output to texture3 etc...


until the final output is to the backbuffer????
is this how its supposed to be done?? or is there a better way??


First of all you send it to the pixel shader, not the vertex shader. The rest looks like a good way to do it. It's like a chain. You sort of take the backbuffer, render X times a fullscreen quad, apply an effect each time, and end up at the start again, rendering it to the backbuffer.

There are a lot of great tutorials about this subject, a lot of em in xna. They are easily translated to dx if you understand enough of the api's.

http://www.ziggyware.com/readarticle.php?article_id=121
http://www.ziggyware.com/news.php?readmore=750

and these are just two out of the hundreds...

This topic is closed to new replies.

Advertisement