XNA, light mapping, specular

jwatte's picture

I've been working on a GPU accelerated light map generator for XNA for a little while. I'm using the light map only to tell shadow/light for each surface for each light, and then solving the basic light equation (ambient + diffuse + specular + emissive) per pixel, multiplied by shadow.

This means I can store the shadow mapping information for four lights into a single texture -- and, ideally, that texture is just one bit per channel, but as there is no format that really lets me do that, I'll have to make do with something like RGBA2222, RGBA4444 or RGBA5551, depending on what's available on the target hardware (which, for all things XNA Game Studio, is really the Xbox 360).

Anyway, one of the most annoying bits of this entire endeavor has been that PIX for Windows keeps crashing for me. Sometimes, it crashes because I call some function wrong. However, because I'm debugging managed code, the debug output doesn't show up unless I run a separate debug viewer app. And when I try to catch API errors by setting "break on error" in the DirectX control panel, the program just hangs when it would desire to break.

Sometimes, PIX seems to crash just because it feels like it. Perhaps it, and the NVIDIA graphics driver, conspire to not like my data formats, or don't like that my shader might divide by zero, or try to take the square root of a negative number or something. Exactly the kind of things you'd want to debug in PIX. Sometimes, running with REF doesn't crash -- but, you know, getting anything done with REF is like watching paint dry. Slow-drying, eco-friendly, pet-hair-absorbent paint.

Anyway, I finally got to the point where shadows more or less line up with geometry, the normal/gloss/diffuse/specular/light maps all work, and my geometry builder (which parses a simple cell/portal text file format) can build a working level and light it using the GPU. Perhaps I won't ship light maps at all, but instead just light on loading (or re-build light maps in the background). It's certainly quick enough for simple geometry.

And here's a screen shot! Woot! Click on it for a bigger version.

screen shot

xna-shooter-game-20080130-lightmapped-specular.jpg179.37 KB