This article is prerecorded. Shawn is away (getting married later today). Replies to comments will be delayed.
Plagiarizing my MIX talk, I thought it would be useful to summarize the performance implications of choosing between the different shader permutations of the five built-in effects in XNA Game Studio 4.0.
To oversimplify, options with fewer shader instructions tend to run faster. But before you rush off to choose the cheapest shaders available, be aware this will make no difference if your game is CPU rather than GPU bound, or if your bottleneck is a different part of the GPU.
There are four main versions of BasicEffect, depending on what lighting options are used:
Vertex Shader Pixel Shader LightingEnabled = false 5 1 One vertex light 40 1 Three vertex lights 60 1 PreferPerPixelLighting = true 18 50
The "one vertex light" version is used when:
These settings add extra shader instructions to the numbers from the previous table:
Vertex Shader Pixel Shader TextureEnabled = true +1 +2 FogEnabled = true +4 +2
There are three main versions of SkinnedEffect, depending on what lighting options are used:
Vertex Shader Pixel Shader One vertex light 55 4 Three vertex lights 75 4 PreferPerPixelLighting = true 33 51
The above is with WeightsPerVertex = 1. The default is 4, which matches the default ModelProcessor behavior. Specifying fewer weights will only give correct results if your vertex data matches the requested shader. Neat trick: you can use SkinnedEffect with WeightsPerVertex = 1 to implement shader based instancing.
These settings add extra shader instructions to the numbers from the previous table:
Vertex Shader Pixel Shader WeightsPerVertex = 2 +7 +0 WeightsPerVertex = 4 +13 +0 FogEnabled = true +0 +2
Unlike BasicEffect, SkinnedEffect has no option to disable lighting entirely, or to disable texturing.
There are two main versions of EnvironmentMapEffect, depending on what lighting options are used:
Vertex Shader Pixel Shader One vertex light 32 6 Three vertex lights 36 6
These settings add extra shader instructions to the numbers from the previous table:
Vertex Shader Pixel Shader FresnelFactor != 0 +7 +0 EnvironmentMapSpecular != 0 +0 +2 FogEnabled = true +0 +2
I will write more about Fresnel and specular sometime later.
This guy is really simple, with only one basic version:
Vertex Shader Pixel Shader DualTextureEffect 7 6
Plus a single setting that adds extra shader instructions:
Vertex Shader Pixel Shader FogEnabled = true +4 +2
Despite its simplicity, DualTextureEffect is the key to great looking and efficient rendering techniques such as lightmaps and detail textures. I will write more about this sometime later, too.
This fellow has two main versions, depending on what AlphaFunction is used:
Vertex Shader Pixel Shader <, <=, >=, > 6 6 ==, != 6 10
Plus a single setting that adds extra shader instructions:
Vertex Shader Pixel Shader FogEnabled = true +4 +2