Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In XNA (and Direct3D in general AFAIK), rather than creating individual vertex and fragment shaders, you bundle potentially many related shaders into 'Effects'. When you come to use an effect you select a 'technique' (or iterate through all of them) and then each 'technique' has a number of 'passes'. You loop through the each pass it selects the relevant vertex and fragment shader and you draw the geometry.

What I'm curious about though is what you would need multiple passes for? I understand in the early days of 3d you only had one texture unit and then you had 2 and that often still wasn't enough if you also wanted to do environment mapping. But on modern devices, even in the mobile class, you can sample 8 or more textures and do as many lighting calculations as you'd want to in a single shader.

Can the more experienced here offer practical examples of where multi-pass rendering is still needed, or is this just over-engineering on the part of XNA/Direct3d?

share|improve this question
up vote 5 down vote accepted

Any time you're doing post-process effects on a set of captured buffers would be a reasonable time to use a multi-pass effect, i.e. toon outlining, motion blur, SSAO, bloom. The idea being that the first pass would be where you'd render everything out to the appropriate buffers, and each subsequent pass would handle each post-process effect.

Like Ranieri mentioned about the XNACC example, they're using multiple passes to render a huge number of lights. Though in that example, they're executing the same pass, just once for each light.

Keep in mind that Shader Model 2 and before can't handle having anywhere near as many instructions as Shader Model 3 or 4 in each shader, yet another reason to split an effect into multiple passes -- to support older hardware.

share|improve this answer
Can you give an example where an XNA Effect object where you loop through EffectPasses has more than one pass as opposed to using different effects and why? – Jason Goemaat Dec 31 '10 at 9:38

As pointed out in the other replies, multi-pass rendering (drawing a single mesh multiple times with different shaders/parameters), as suggested in other replies, is definitely still used, primarily for lighting and special effects

D3DX Effect passes could be used for this kind of thing. But it could also be implemented with more than one shader/effect.

The original intention of passes was to help with implementing complex shaders on lower-end (pre-shader-2.0) hardware, where the restrictions on the number of texture stages and shader instructions per pass were quite limiting.

In the example of multi-pass lighting, are there any significant performance gains to be had by using passes instead of switching effects?

share|improve this answer

In addition to the lighting thing that everyone mentioned, another major use of this is blur. Horizontal and vertical are done in separate passes (so to get a 9x9 blur, only 18 pixels need to be sampled for each output pixel instead of 81). This is used for bloom/HDR, depth of field, glow, etc

share|improve this answer
Possibly, but most I think blur implementations would use the same shader for the horizontal and vertical passes - and just pass in the sampling offsets (as shader constants or per-vertex data)? – bluescrn Aug 10 '10 at 22:32
@bluescrn - Bloom is typically thought of as a 4-pass effect: one to extract the bright areas & downscale, one to blur horizontally, one to blur vertically, one to combine/upscale the blurred image with the original. While shader parameters could be used to control these, branching would be needed to differentiate all but the two blur passes – Robert Fraser Aug 11 '10 at 23:12

The example on the XNA creators' website uses multiple passes to compute lighting from many (hundreds) of light sources.

share|improve this answer

As Ranieri said, you can use multiple passes for multiple lights, for instance with a single material you may have an 'ambient' pass, an additive pass per point light, another additive pass per spotlight and then a decal pass to multiply in the diffuse texture (I've used a setup like this in the past and it's about the most flexible way of handling a lighting shader I've seen without getting into deferred shading).

Also, I believe most fur shaders use multiple passes.

share|improve this answer

Shadow maps for creating shadows can be done using multi-pass. Just a note, some multi-pass effects can be done in one pass if the video card supports the same number of texture units as the number of passes. So, if you don't have enough texture units, then you will have to use multiple passes. One fixed hardware platforms (like game consoles), you can probably code just using multi-texturing because you know the number of texture units. But for PCs, there are infinite number of hardware configurations. If you want to have the broadest reach to consumers, you'll probably want to break up some of your more complex effects into multiple passes so that users with lower grade hardware (i.e. don't have as many texture units on GPU) can still see the effect. Briefly, shadow maps are created by first creating a shadow map of the scene from the perspective of the light in one pass. Then the shadow map texture is blended into the scene with the other textures of the scene.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.