Skip to main content
gamedev.net
🔒 Locked

Consecutive shader processing

Started by gOOze Sep 14, 2010 at 7:39 AM 2 replies 1.1k views
Original Post
gOOze
gOOze

Hi,

I'm wondering what is the good method to process my rendered image using several consecutive pixel shaders.

Let's say I have a 3D model I want to render, and 3 different pixel shaders A, B, C that perform effects (for example gaussian blur filter + sepia + inverse color, let's say I can't put them all together in a single shader for some reason). What is the good way to send the output of the first pixel shader (A) to the next one (B)?

I was thinking about a render to target for the first vertex/pixel shader (A) and then apply it to a quad taking the whole screen that I then render using the next vertex/pixel shader (B).
In that case I have:

Model > vertex Shader > pixel sh. A > to target > texture the quad > vertex sh. > pixel sh. B > to target > texture the quad > vertex sh. > pixel sh. C > final output

but I don't need to re-project and re-rasterize the whole thing between each shader. I just want the pixels to be processed by the next shader as they are. I'm wondering what is the "clean way" to do so.

I hope my explanation makes sense.
Thanks!
Hodgman
Hodgman
The types of shaders that you're talking about are usually "post process" shaders, not "model drawing" shaders.
e.g. running a Gaussian blur while drawing a model is ridiculously complex. But running a Gaussian blur on a 2D image is easy.

You'd draw your model as usual, to render-target A.
Then you'd use render-target A as a texture and draw a quad render-target B (using the first post-process shader).
Then you'd use render-target B as a texture and draw a quad render-target A (using the second post-process shader). etc..
gOOze
gOOze
Thanks for your answer. So I have to have a quad textured with my previous rendered image between each processing step. I suppose the quad is drawn using an ortho camera to avoid any visual artifacts?
kvark
kvark
It is *your* shader -> quad doesn't need to be projected by any camera. Just pass it's vertex coordinates directly to the output to cover the [-1,1] range.

The only 'direct' way of passing the pixel value to the next shader without an intermediate storage is to combine your shaders into the one. So basically you have to rasterize the same quad many times and use the texture storage.

Topic Locked

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

Sign in to reply to this topic.