The delights of DualTextureEffect

When I started on my AppWeek game, I wanted to build the game using the Reach profile as much as possible so I could more easily reuse the graphics part on Windows Phone. I was pretty close; the only piece of my game that didn’t directly convert to Windows Phone was the 3D Particles I was using. So when it came to lighting, I decided the best option was lightmaps.

Lightmaps were originally used in Quake, but they are still around as a big part of almost all commercial game engines such as Unity, Unreal, and id Tech 5. Because they are precomputed, you get all the high quality ambient occlusion, soft shadows, and a relatively infinite number of lights (capped only at how long you want to wait for the lighting to bake) and yet they are also incredibly cheap to apply being just another texture lookup and a few operations to blend with the diffuse texture.

As Shawn shows, DualTextureEffect is one of the more interesting built-in effects for XNA Game Studio 4.0. While it’s a simple concept, the ability to combine two textures easily enables lightmaps and detail textures across all platforms supported by XNA Game Studio 4.0. DualTextureEffect ended up being my silver bullet that got me the great look I wanted without having to compromise on portability to Windows Phone.

I used 3D World Studio to generate my levels and lightmaps, but many of the 3D modeling packages support baking lightmaps such as 3D Studio Max, Maya, Blender, and likely many more. Once a lightmap was generated, I could easily use DualTextureEffect across all of my platforms to add lighting to my game. See Shawn’s post for more details on how to get your content to use DualTextureEffect in the games.

Here’s a small comparison of what a level looks like without and with the lightmap turned on. You’ll see that not only does the lightmap add high quality shadows, but the lights also contribute a color to the scene which helps the world feel warmer and more real. So if you’re planning a 3D game for Windows Phone or Xbox LIVE Indie Games, make sure you consider lightmaps when thinking of ways to increase your game’s visual quality.

Unlit Level

Lit Level

Comments (5)

  1. Jamie says:

    One thing I have always wonder is one could do this approach for outdoors under a moving sun? Would you bake a handful of different lightmaps for the sun at different angles? Or is using lightmaps a bad idea for this case? (I bring this up because I always see lightmaps used indoors but rarely outdoors)

  2. NickGravelyn says:

    You can easily use lightmaps for outdoor scenes and get all the same benefits; it just makes it harder to support changing time-of-day. You probably could find ways to blend/animate between baked lightmaps, but you could also consider whether the game needs dynamic time-of-day altogether. 😉

  3. Stefan Kamoda says:

    I've written a ton of posts on XNA and lightmaps on my blog 🙂

    The most recent post shows a character and environment lit with a static light volume and a dynamic sun with shadows. The combination works quite well.

    I've also written a fast global illumination lightmap renderer in XNA which runs on the GPU. Recent posts cover light volume rendering but older posts talk about the light map renderer.

  4. Roger Sall says:

    Please give us some code ,thanks a lot.

  5. Antti says:

    How are you setting the UV coords for your textures? I mean you must be using tiling for the textures, so multiple faces have the same UV coords, right? So, how can you set the UV coords for the ambient occlusion texture so that they are not tiling?

Skip to main content