Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do multiple pass shaders work in HLSL?

Tags:

xna

I'm new to shaders and HLSL, having done enough with BasicEffect class. I understand how the pipeline works, especially for shaders with only 1 pass. However, incase of 2-pass or N-pass shaders, i don't quite understand how the results of the 2(or N) shaders outputs get combined.

Can you please explain the how the combination takes? And if possible, an example where you'd prefer using a multi-pass shader rather than multiple single-pass shaders?

like image 210
shreedhar Avatar asked Jul 22 '11 08:07

shreedhar


1 Answers

Multi-pass shaders simply ADD the results to the previous pass(es). They can be used to support multiple lights, particularly when the GPU's shader model does not have enough instructions to support the required number of lights in a single pass.

Unless you really need to, I wouldn't recommend using more than one pass as it does complicate things such as alpha blending and fog. You'll need to set up your blend states differently in the first pass to subsequent passes.

[EDIT] AS per Melchior Blausand's comment, it is more correct to say that the output each pass is combined with the current value according to the current blend operation and blend modes, where the current value is the result of combining all the previous passes. It is common for multi-pass shaders to use the ADD blend mode to combine multiple lights. Also note that the alpha channel can be combined with different blend modes to the colour channels.

like image 63
Aranda Avatar answered Jan 03 '23 06:01

Aranda