Jump to content
  • Advertisement
Sign in to follow this  
GroZZleR

RenderToSurface, Pixel Shaders and Post Processing [Unsolved]

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

Hey all, I'm working on a system for my 2D engine to add some image post processing. Basically I'm following the pretty standard procedure of rendering the scene to a texture then using a shader to modify that texture. I've hit a little snag though and I'm not quite sure what the solution is. I render the scene to the texture, loop through the scene processing shader, apply the effects and draw the quad. But I have to draw this quad at the end of every shader pass, which ends up overlapping the one previous to it. So really the only post-processing effect I see is the one last applied. I thought about just enabling some sort of blending mode to merge the two images, but I'm not sure if that's the correct solution to the problem, as I'm new to shaders AND render surfaces (heh). Here's the shader technique:
technique TestTechnique
{
    pass P0
    {
        VertexShader = NULL;
        PixelShader  = compile ps_2_0 TestPS();
    }
    pass P1
    {
        VertexShader = NULL;
        PixelShader  = compile ps_2_0 TestPSGreyscale();
    }
}


Here's the render surface rendering:
_device.Clear(Direct3D.ClearFlags.Target, Color.Black, 1.0f, 0);

_device.BeginScene();

_effect.Technique = "TestTechnique";
_effect.SetValue("WorldViewProj", worldViewProj);
_effect.SetValue("Time", (float)Kernel.Instance.Time.TotalTime);

int numPasses = _effect.Begin(0);
for (int pass = 0; pass < numPasses; pass++)
{
	_effect.BeginPass(pass);

	_device.SetTexture(0, _renderTexture);

	_graphics.DrawRectangle(new Point(0, 0), Kernel.Instance.Window.ClientSize);
	_graphics.Flush();

	_effect.EndPass();
}

_effect.End();

_device.EndScene();

_device.Present();


So what's the deal? Is blending the way to go or have I done something wrong? Thanks for your help. (_graphics is my own class for rendering sprites and such) [Edited by - GroZZleR on August 8, 2005 1:26:30 PM]

Share this post


Link to post
Share on other sites
Advertisement
I think blending is a perfectly good solution for combining post-process effects. You can set the blending mode in the effect technique, so that your effect is properly combined with previous effect.

Alternative solution would be to use multitexturing. Use your rendertarget-texture in multiple texture stages and use the pixel shader to combine effects.

Btw, how are you integrating post-process effects to your rendering pipeline? I'm interested in this because I'm also in the process of writing a 2D engine.

Share this post


Link to post
Share on other sites
Come to think of it, I don't think blending is going to work.

If it's not using the pixels from the previous pass, it's not going to look correct. For example, if I blur on the first pass and greyscale on the second, it's going to be sampling the wrong colours.

Any other ideas?

(I'm not sure how it's going to fit into the pipeline just yet, I'm still working on figuring out all the kinks.)

Share this post


Link to post
Share on other sites
You could use a chain of render target textures, and pass the results forward through them until you reach the backbuffer.

It is worth noting that the less steps you take, the faster your program will be - so try to combine the shaders into as few steps as possible.

Share this post


Link to post
Share on other sites
Hate to jump in here, but is there any built-in support for these "chains" or would one have to program this specifically?

Share this post


Link to post
Share on other sites
Quote:
Original post by sirob
Hate to jump in here, but is there any built-in support for these "chains" or would one have to program this specifically?

No, there's no built-in render target chains, you'll have to do it yourself. Unless I'm missing something here...

Share this post


Link to post
Share on other sites
By "chains" I meant something like this:


  1. Render effect 1 to rendertarget 1.
  2. Render effect 2 to rendertarget 2 using rendertarget 1 as input.
  3. Render effect 3 to rendertarget 3 using rendertarget 2 as input.
  4. Repeat above steps as necessary.
  5. Render the final effect to the backbuffer.


There isn't a limit to how many render target textures you can create, other than the available video memory.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!