Skip to main content
gamedev.net
🔒 Locked

'Multi pass' question

Started by ZealousEngine Jul 12, 2006 at 1:58 AM 3 replies 1k views
Original Post
ZealousEngine
ZealousEngine
Im trying to figure out how to do multiple passes inside a hlsl shader (specifically a post process shader). So lets say for example I want to downfilter my a image, then blur it. I know how to write a technique that calls both 'shaders' one at a time, but I dont understand how the downfilter shader 'passes' info on to the blur shader. I mean when I output a color from my downfilter shader, where does it go!? Something like this...



//-----------------------------------------------------------------------------
// Pixel Shader: DownFilter
// Desc: Perform a high-pass filter and on the source texture and scale down.
//-----------------------------------------------------------------------------
float4 DownFilter( in float2 Tex : TEXCOORD0 ) : COLOR0
{
    float4 Color = 0;

    for (int i = 0; i < 16; i++)
    {
        Color += tex2D( g_samSrcColor, Tex + TexelCoordsDownFilter.xy );
    }

    return Color / 16;
}

//-----------------------------------------------------------------------------
// Pixel Shader: HorizontalBlur
// Desc: Blurs the image horizontally
//-----------------------------------------------------------------------------
float4 HorizontalBlur( float2 Tex : TEXCOORD0 ) : COLOR0
{
    float4 Color = 0;

    for (int i = 0; i < g_cKernelSize; i++)
    {    
        Color += tex2D( g_samSrcColor, Tex + TexelKernel.xy ) * BlurWeights;
    }
    
    return Color;
}

//--------------------------------
// tech
//--------------------------------
technique PostProcess
{
    pass p0
    {
        VertexShader = null;
        PixelShader = compile ps_2_0 DownFilter();
        ZEnable = false;
    }
    pass p1
    {
        VertexShader = null;
        PixelShader = compile ps_2_0 HorizontalBlur();
        ZEnable = false;
    }
}


Help!
HellRaiZer
HellRaiZer
Quote:

I mean when I output a color from my downfilter shader, where does it go!?

It goes to the currently active render target (probably a texture). After finishing the first pass (downfilter) you must use this texture as input to the blur shader and output the result to another texture (or on screen).

HellRaiZer
HellRaiZer
ZealousEngine
ZealousEngine
AKk I just read a couple things from various sites. It sounds like the only way to share data from one pass to another is render the output of the first pass to a texture, then sample that texture in the next pass. That cant be..

There is a "post process" sample in the directx sdk. It lets you stack on multiple effects like I described above (downfilter, then blur, then ect...). Youre saying that after EVERY single process, the result is rendered to a texture? Thats a LOT of textures to keep track of, some of them even change sizes/resolutions, and they ALL need to be textured to the object so they can be sampled.... what a nightmare!

There has to be another way! Or am I just missing something?

*edit

A single object can only have 8 textures right? So if you do 4+ passes, that means each pass needs to render to a texture, and that texture needs to be applied to the object (so it can be sampled by the next pass). Doesnt seem like you have a lot of room to work... This whole architecture just seems nuts.. Will shader model 3 solve any of this?
Matt Aufderheide
Matt Aufderheide
Well, as far as using the results of a previous pass directly, yes you must render it to an offscreen surface, and set that as a texture in the next pass. This is really not so difficult, as long as you keep track of everyhting. I assume you are using D3D, just create all your textures beforehand...it can be a pain, but its the only way.

In my post-processing shaders, i have a different texture for every step, so i dont overwwrite anything or whatever. so for instance when i want to blur the framebuffer for somehting like bloom , i will strechrect from the framebuffer to a small texture, use another blur texture for x, and a final blur texture for y. The blur y texture will be the final one I would use..
HellRaiZer
HellRaiZer
Quote:

There is a "post process" sample in the directx sdk. It lets you stack on multiple effects like I described above (downfilter, then blur, then ect...). Youre saying that after EVERY single process, the result is rendered to a texture? Thats a LOT of textures to keep track of, some of them even change sizes/resolutions, and they ALL need to be textured to the object so they can be sampled.... what a nightmare!

You don't need to use a new texture for every step, unless it is absolutely necessary. In the SDK sample you mentioned, they say in the docs that they use 9 render targets to do all the effects, with whatever stack depth. Simply you swap textures between effects. Also note that you won't need all 9 rt in case to implement simple effects. You can get away with only 3 color rts. The other 6 are for normal and position data, which you may not need.

HellRaiZer
HellRaiZer

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.