New built-in effects in XNA Game Studio 4.0

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?

  • We made a list of everything we thought would be useful for game developers. It was a LONG list.

  • We removed the things that would not run fast enough to be practical on mobile hardware. The list got shorter, but was still pretty long.

  • We looked at our schedule, and realized we had time to implement, optimize and test around 50 shaders.

  • log2(50) allows approximately 6 boolean options, but our list had way more than 6 features!

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,
Texture2 AlphaFunction,

Comments (12)

  1. nice ,, but is take the magic away from the programmer ,, to make that special game with the special shaders that makes your game stand out from all the others games on the market

    hope this is not the end of a shader programmer,,

    still hoping for custuom shaders, in a later release,, we doint whant 500 pong,space invaders,tetris games look the same rendered the same way but only a defferent color on the screen

  2. David Black says:

    They dont have to look the same. Fixed function games did not…

    Differentiating is easy, its mostly about art, but also multi pass, pre rendered lighting, interesting geometry etc etc.

    Shaders just make it easier and (in some ways) easier to achieve something specific.

  3. Chad Carter says:

    Congrats on getting married my friend!

    Thanks for putting so much work into getting these blog posts out.

  4. Erzengel says:

    >Shawn is away (getting married at the end of the week)

    Congratulations! Have a nice long honeymoon. Oh, and thanks for the pre-recorded blog posts. You didn’t have to do that, and we appreciate that.

    @Michael Hansen:

    This "magic" is only taken away from the programmer on the PHONE, and hopefully just for this release.

    Even so, Shawn said in the last post (where I asked if most programmers really did move away from BasicEffect): "I’ve been surprised how many awesome games made by awesomely skilled teams (especially on the XBLA side) achieve amazing graphical quality just from having great game design and great artists, and do all their drawing with SpriteBatch!"

  5. Cheers to getting married.

    And Cheers to pre-recorded blog posts 🙂

    Thanks a bunch.

  6. Rim says:

    Indeed cheers on getting married and thanks for finding time to still answer my pesky questions in what must have been a hectic week 🙂

  7. ShawnHargreaves says:

    Hurrah! I successfully became married and am now back at work 🙂

    > nice ,, but is take the magic away from the programmer ,, to make that special game with the special shaders that makes your game stand out from all the others games on the market

    Programmable shaders are not the only way to make a visually striking and distinctive game!

    Of course, the more control a programmer has, the more options they have to choose between, which is always a good thing. We totally get that.

    But I think it would be a mistake to focus too specifically on programmable shaders as the only way to achieve creative graphics rendering. HLSL is just one of many tools in our armory! Just like HLSL alone does not make for an interesting looking game, it is also possible to make many interesting games without HLSL.

    I think game creation is actually quite similar to many other forms of artwork. We are given a medium to work in, and a set of tools, and must then figure out how to make something fun, beautiful, surprising, scary, creative, moving, etc, using those tools.

    Some people try to do this by inventing a new lighting model, and writing HLSL shaders to implement it. If that is your plan, Windows Phone would be a poor platform to choose, since you do not have HLSL shaders there (but you could totally go this way using XNA on Windows or Xbox).

    Others achieve their artistic goals just by hiring talented artists, and getting them to build awesome models and draw great looking textures.

    Many (I would say most) of the best game developers choose a path somewhere down the middle. Shaders are certainly a part of their solution (and we do have shaders on Windows Phone: not totally programmable ones, but you can do environment mapping, skinning, multitexturing, etc), plus they use great artwork created by talented artists, and also combine the many interesting rendering techniques that do not require shaders at all (animation, particles, multipass blending, the many techniques based around procedural geometry generation, etc).

    Certainly, there are many things you can do on Xbox but not on a phone (modern phones are pretty powerful, but not yet at the level of a dedicated gaming console). But there are also many interesting things that you CAN do on the phone. The Harvest guys certainly figured out how to make it look cool! I think we will see many more such amazing looking games as people figure out how to apply the available tools in creative and unexpected ways.

    > we doint whant 500 pong,space invaders,tetris games look the same rendered the same way but only a defferent color on the screen

    Talented developers made creative and interesting games long before programmable shaders entered the picture! The Nintendo 64, Dreamcast, and Playstation II weren’t exactly filled up with Tetris clones rendered the same way just with different colors 🙂

    If you approach phone development trying to use all the same techniques that work well on Xbox 360, I fear this will be a frustrating experience. But if you look at the unique strengths of this new platform, and work out how to make best use of the tools and techniques it provides, I think you will find there is great potential to create exciting and original games on Windows Phone.

  8. Mike V says:

    I am really wanting to find any sort of tutorial on how to use these built-in effects to create different…well, "effects" in games.  For example, how would I make a simple LineList with lines that "glow"?  Or a triangle with a specular highlight?  I’m really hoping that tutorials of this sort exist, because I haven’t found them yet.

  9. kooksta says:

    So basically rendering water on the wp7 hardware is out the window I guess?

  10. zanlok says:

    It's been a while, but I'm starting a couple XNA 4.0 projects, and I'm interested if anyone has suggestions that answer Mike V's question above. Especially the one about making a LineList glow, because that sounds like a great way to get accustomed to integrating these effects into an existing drawing architecture.

    As far as 2D retro style games go (like my last few), the comment about heavy use of SpriteBatch is spot on. Whether it's a randomized but pre-captured (recorded) explosions or a glowing laser line, the blitting can tend to be an order of magnitude faster than doing many of the effects on the fly. Though, custom shaders to programatically generate the effects would still be extremely useful.

    Shawn, as long as you take as much regard in the care of your wife as you do for this awesome blog, you're in for a lifetime of happy 🙂

  11. David says:

    I have objects that require ALL those effects.. A single skinned mesh with parts that needs to be Alpha Tested and with an environment map and normal mapping. How do you combine them?

  12. ShawnHargreaves says:

    David: if this is on Windows or Xbox, you could write a custom shader that combines skinning with whatever other behaviors you like.

    If you are on Windows Phone, you could do the skinning on the CPU (see the CPU skinning sample on the AppHub site), then draw different pieces using whichever is appropriate of these built-in effects.

Skip to main content