Techniques and Passes

Started by
2 comments, last by JWalsh 13 years, 1 month ago
I know that these concept will come up later in the workshop, but maybe someone can tell us what techniques and passes are.


effect.View = view;
effect.Projection = projection;

Matrix world = Matrix.Identity;
effect.World = world;
effect.EnableDefaultLighting();

foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1,
VertexPositionNormalTexture.VertexDeclaration);
}


What does the foreach part in the code actually mean? Thanks! :)
Advertisement
Hi Zee,

Within any Effect (or corresponding HLSL file), there can be multiple techniques. Think of a technique as a specific style of drawing. Each technique is made up of one or more passes. Most of the Effects you'll be using as a beginning programmer will have only one technique in it, and the techniques you'll be using as a beginning programmer will likely have only a single pass - meaning your geometry will only be drawn once. However as your rendering code gets more complex, you may have more textures to draw than can be sent to the video card in a single pass, or you may be attempting some other technique that requires your geometry to be drawn multiple times. In this case, you frequently take advantage of frame buffer alpha in order to blend each of the pass together.

That foreach loop reads exactly as it is written. For each pass in the current technique, apply the vertex and pixel shader and then draw the Geometry.

As you're probably using BasicEffect, which has only a single pass, it's also safe to just say:


effect.CurrentTechnique.Passes[0].Apply();

graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1,
VertexPositionNormalTexture.VertexDeclaration);
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Is there a way to change the number of Passes in a BasicEffect? If not, then I can say that I can use this code whenever I'm just using basic effect. Am I correct? Thanks JWalsh! :)

[color=#1C2837][size=2][color=#000000]effect[color=#666600].[color=#660066]CurrentTechnique[color=#666600].[color=#660066]Passes[color=#666600][[color=#006666]0[color=#666600]].[color=#660066]Apply[color=#666600]();[color=#000000]

graphics[color=#666600].[color=#660066]GraphicsDevice[color=#666600].[color=#660066]DrawUserPrimitives[color=#666600]([color=#660066]PrimitiveType[color=#666600].[color=#660066]TriangleList[color=#666600],[color=#000000] vertices[color=#666600],[color=#000000] [color=#006666]0[color=#666600],[color=#000000] [color=#006666]1[color=#666600],[color=#000000]
[color=#660066]VertexPositionNormalTexture[color=#666600].[color=#660066]VertexDeclaration[color=#666600]);

Is there a way to change the number of Passes in a BasicEffect? If not, then I can say that I can use this code whenever I'm just using basic effect. Am I correct? Thanks JWalsh! :)

[color="#1C2837"][color="#000000"]effect[color="#666600"].[color="#660066"]CurrentTechnique[color="#666600"].[color="#660066"]Passes[color="#666600"][[color="#006666"]0[color="#666600"]].[color="#660066"]Apply[color="#666600"]();[color="#000000"]

graphics[color="#666600"].[color="#660066"]GraphicsDevice[color="#666600"].[color="#660066"]DrawUserPrimitives[color="#666600"]([color="#660066"]PrimitiveType[color="#666600"].[color="#660066"]TriangleList[color="#666600"],[color="#000000"] vertices[color="#666600"], [color="#006666"]0[color="#666600"], [color="#006666"]1[color="#666600"], [color="#660066"]VertexPositionNormalTexture[color="#666600"].[color="#660066"]VertexDeclaration[color="#666600"]);


Zee,

You are correct. Both the Techniques collection as well as Pass collection on an Effect object is read-only. You cannot change the number of techniques or passes in a technique for any given effect. So any time you know you're using BasicEffect, it's safe to just apply Passes[0].
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints

This topic is closed to new replies.

Advertisement