New built-in effects in XNA Game Studio 4.0

Originally posted to Shawn Hargreaves Blog on MSDN, Wednesday, April 28, 2010

This article is prerecorded. Shawn is away (getting married at the end of the week). Replies to comments will be delayed.

Remember the story about the chessboard and the grains of rice? Shader programmers have the same problem. We start with a bunch of options (lighting, texturing, vertex color, fog, animation, environment mapping, multitexturing), and want to support every possible combination of settings, but each boolean option doubles the number of shaders required. Exponential growth gets out of hand faster than you can say "2 to the N".

Programmable shaders are the perfect solution to this dilemma. Sure, the total number of permutations may be huge, but most games only actually use a few squares of the chessboard. With programmability, each developer is free to implement the specific feature combinations needed for their particular game.

But we don't have programmable shaders on Windows Phone right now.

Cue inevitable chorus of comments. Personally, I love shaders. I would love to someday enable them on Windows Phone. But we didn't have time to make that happen for this first release, and we have nothing to announce about future plans, and that's all I have to say about that :-)

Instead we provide a set of built-in effects, each of which has several configurable knobs. These effects are available (and I think will be useful especially for beginners) on Windows and Xbox, but they are mostly designed and optimized for Windows Phone, since the phone lacks the alternative of programmable shaders.

What features should these built-in effects provide?

Something had to give. The schedule was immovable. We cut the feature list, and cut some more, but it was too painful to cut all the way down to 6 features, so instead we abandoned the goal of supporting every possible combination of options. By choosing only the most useful combinations, we moved from the scary land of 2^N permutation explosion, into a more manageable linear problem space. Some features are supported consistently across the board, for instance all effects have the same World, View, and Projection matrices, and the same fog parameters. Others are supported by just a subset of effects, for instance BasicEffect and SkinnedEffect use the same lighting model, but DualTextureEffect does not support realtime lighting at all.

Game Studio 4.0 ended up with five built-in effects, implemented by 78 different shader permutations. Their features:

  BasicEffect SkinnedEffect EnvironmentMapEffect DualTextureEffect AlphaTestEffect
World, View, Projection Yes Yes Yes Yes Yes
DiffuseColor Yes Yes Yes Yes Yes
Alpha Yes Yes Yes Yes Yes
Fog Optional Optional Optional Optional Optional
Vertex color Optional No No Optional Optional
Diffuse lighting Optional Required Required No No
Specular lighting Optional Required No No No
PreferPerPixelLighting Optional Optional No No No
Texture Optional Required Required Required Required
Additional properties   WeightsPerVertex,
SetBoneTransforms
EnvironmentMap,
EnvironmentMapAmount,
EnvironmentMapSpecular,
FresnelFactor
Texture2 AlphaFunction,
ReferenceAlpha
Blog index   -   Back to my homepage