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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With