Multiple Passes

Apr 15, 2009 at 10:30 PM
How would you go about using multiple passes in a shader using this system.  For instance lets say I had a 2 pass shader and after the first pass wanted to change the textures, how would I go about doing this?
Apr 15, 2009 at 10:40 PM
Edited Apr 15, 2009 at 10:45 PM
For a large number of reasons, I chose not to support changing the render state in a shader. The side effect was that multi-pass shaders were close to useless in such a case.
Your only option is to create a technique for each pass, which will create a shader class for each pass. Then manually perform the two pass rendering, with the render state changes needed, etc. This, in my opinion, is actually a better solution than multi-pass shaders, which require you support multi-pass with every single shader you use (even though most will be single pass)

I'm curious what exactly is it you are trying to do?

Apr 16, 2009 at 4:23 AM
That is not really a viable option when the 2nd pass is a PS pass only.  I would want to use it for terrain splatting something like

technique Shader

   pass P0 
       VertexShader = compile vs_2_0 Transform(); 
       PixelShader  = compile ps_2_0 Splat1(); 
   pass P1 
       PixelShader  = compile ps_2_0 Splat2(); 
Apr 16, 2009 at 8:32 AM
Edited Apr 16, 2009 at 8:36 AM

Well in either case both passes use the same vertex shader. The internal code in xen is smart enough to recognize that, and it won't recreate the vertex shader twice. Saying it's a 'PS pass only' isn't really accurate, the vertex shader is still going to run twice, draw calls will be made twice, etc.

My impression is that you might need to reconsider your shaders. If you can't get your terrain splatting effect within the 8 textures + 64 instructions that shader model 2 gives you in a single pass, then something needs rethinking. Such a complex shader would be very bad for performance anyway.