Post-Processing glow shader

I'm trying to get the Glow shader technique discussed in a Gamasutra article (http://www.gamasutra.com/features/20040526/james_pfv.htm) implemented in my XNA project but am struggling with certain aspects of it. The blur of the scene takes place in two separate passes, one for each axis. So when you do the horizontal blur pass, you pass it your scene which you've rendered to a RenderTarget2D. Then for the vertical blur pass which follows, you have to pass it the resulting texture from the previous pass. This is where I don't really understand anymore... what is the proper way to set this up so that you can extract the results of the first pass and give it to the second pass when you already have an Effect activated


Answer this question

Post-Processing glow shader

  • day10

    I suggested a solution here: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1211515&SiteID=1

    I didn't test it, and the initial poster didn't confirm if the second version of the code works, but you might give it a try.


  • nagual20

    If you need the effects of previous passes you will probably have to resolve the RenderTarget2D again and render it again. However if you want to do a multipass rendering, you can just use blending to achieve the same results. If you want to see how I have done things for my glow shader (http://jsedlak.org/node/109), you can look at Xna5D's SceneManager and RenderGroup. Note that more passes is reaallly expensive, my X800 has a hard time handling anything more than 3-4 passes because of its pixel throughput.

  • saarar

    I don't think thats going to work for me because the Glow technique requires a vertex shader that passes 8 sets of texture coordinates to the pixel shader, so i'm using a vertex shader with my own screen quad instead of a SpriteBatch.

  • XycsoscyX

    it makes no difference.

    Just replace the SpriteBatch code with your rendering code. It isn't that hard to do, if you put a little effort in it.


  • SOTY_Programmer

    Ok.

    The code I posted in only intended for the post-processing step, where you render only one quad to cover the screen, and apply post-processing effects on it. It isn't intended for model rendering. That should be done normally, before any post effects are applied.

    Resolving the render target doesn't "unset" it. So after resolving it to a texture, I simply act as if the rendertarget is empty, and draw over it.

    And also, the SpriteBatch doesn't have to fit in with evetything. It is simply a replacement from drawing a full-screen quad yourself. If you don't need it, just don't use it.

    Later in the development of my game, I'll revisit my post-processing code (right now it is kinda hacky). After that, I will try to post a tutorial covering the methods I used. But don't expect it too soon, since the gameplay is more of a priority right now.


  • kawano1h

    Catalin,

    Sorry, but I've tried tooling around with the code you posted, but it doesn't seem that simple. When you are rendering a Mesh like I am, you don't call Effect.Begin() and Effect.End() manually... its done automatically by ModelMesh.Draw() as far as I can tell. Same goes for the pass.begin() and pass.end() methods. So I have no idea how all the SpriteBatch stuff fits in with the way I've got my stuff set up.

    And then there is the fact that the code you wrote resolves the render target, but then never again sets a render target. How is that supposed to work

  • Sportsdude

    I'm surprised there are so few examples out there of XNA projects with multipass screen effects. Anyway, I think I found an example that I might be able to work from... the PostScreenGlow class in RocketCommander uses a 5-pass post processing shader that has a bunch of different render targets that are each resolved at the end of each pass. Its a little tough to read through because he wraps so many helper classes around the native XNA methods, but it appears to have the basis of what i'm looking to do.

    For everyone else's point of reference, the XNA version of Rocket Commander can be downloaded here: http://exdream.no-ip.info/blog/PermaLink.aspx guid=442152d0-a014-47de-b9b1-4e8aed1d9bd3

  • Post-Processing glow shader