Sign in to follow this  
Aldoric

Multi-Pass Shader - how?

Recommended Posts

Hi! I never used shader before. But before I continue writing my game engine I'd like to get some informations about using shaders. Well single-pass shaders are easy to implent. But how does multi-pass shader work? As far as I know, I'll have to create a third buffer beyond back- and front-buffer for that pass? Is that correct. Could someone maybe even post a short pseudo-language code and give me some functions that could be useful? Thanks :)

Share this post


Link to post
Share on other sites
What shader language? HLSL, GLSL, Cg? This makes a difference in some ways.

If you're using OpenGL and want to make another render target look into FBOs. Not sure what the D3D alternative is called.

But we need more info I think before we can give you real answers.

Share this post


Link to post
Share on other sites
If you need to render to a offscreen buffer, sure use a FBO.

If you will be using GLSL, you might want to put

gl_Position = ftransform();

in each VS to make sure output vertices are always identical, else you might get some visual artifacts. Other languages don't have that feature.

Share this post


Link to post
Share on other sites
multipass?
u need to define the question better

multipass is normally just redrawing the model (with blending enabled) + with a diferent material
shaders have very little to do with it

Share this post


Link to post
Share on other sites
Quote:
Original post by zedz
multipass?
u need to define the question better

multipass is normally just redrawing the model (with blending enabled) + with a diferent material
shaders have very little to do with it

You're a little off here - advanced shaders use multiple passes a lot. A prominent example are shaders that are too big (i.e instruction count exceeds hardware capabilities) and thus need to be split up into multiple passes.
There are other uses for multipass shaders, too. Certain post-processing shaders may require multiple passes as well as HDR and bloom effects.

Cheers,
Pat

Share this post


Link to post
Share on other sites
Quote:
Original post by Aldoric
Well single-pass shaders are easy to implent. But how does multi-pass shader work?
That's tricky. Historically, multipassing were being used to accumulate light contributions.
As such, the passes were combined simply by blending them one over the other with additive blend. thus obtaining (col * light0) + (col * light1) + ... = col * (light0 + light1 + ...).

Unluckly, for shaders it's no more so easy. A shader may output a procedural alpha mask which needs to be fetched back for the second pass. How exactly this is arranged to be "given" to the next pass is no more trivial. Simple blend tricks may cut it anyway but in general I would say you need more advanced machinery.
Quote:
Original post by Aldoric
As far as I know, I'll have to create a third buffer beyond back- and front-buffer for that pass? Is that correct.
Yes and no. You don't strictly need this but having another render target for ping-pong rendering does have several advantages - mainly because the blend operations do become programmable - I am confident most (if not all) apps out there use ping-pong rendering to some degree.
Quote:
Original post by Aldoric
Could someone maybe even post a short pseudo-language code and give me some functions that could be useful?
I don't know what you mean by "functions" but for language CgFX and MS'FX are good candidates. Collada also features an internal SLANG but I'm not confident with it.
I suggest CgFX because it does include a bit of integration with FX composer, which may come useful as a design help.

Share this post


Link to post
Share on other sites
Quote:
You're a little off here - advanced shaders use multiple passes a lot. A prominent example are shaders that are too big (i.e instruction count exceeds hardware capabilities) and thus need to be split up into multiple passes.
There are other uses for multipass shaders, too. Certain post-processing shaders may require multiple passes as well as HDR and bloom effects.
that still doesnt really have anything to do with shaders, i think u mean taking the resulting input from a calculation + inputing it into another calculation. that is nothing shader specific to it, also splitting shaders up(?) same deal, but this has nothing to do with shaders.
one of us is misunderstanding what the OP wants (it could be me)
like i said he need's to define the question better

Share this post


Link to post
Share on other sites
Ok, I'll explain a bit how we handle multi-pass so you can have a basic idea.

Firstly we have a material class, this is what is applied to meshes. It can have multiple textures, normal map, diffuse map, etc. attached to it. It also attaches shaders to it (any number you want). A material is saved in a file for us with references to all the above info. It also saves how many passes a specific shader gets and the orders. So you can say material 1 uses shaders 3-5 (just random ID's I made up) but that shader 5 runs first for two loops then shader 3 once, shader 4 once then shader 3 one more time.

Then the renderer makes all the magic happen! Well this is how we handle shadesr and multiple passes, others likely handle it much differently. Hopefully this helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this