In my last post I called my lighting scheme "a bit flat", figuring that a few tweaks here and there would be enough to fix it up. Let's look at that screenshot again:
map01 in Gloom |
Not bad. But compare this to the same view in Doom:
map01 in Doom |
Unfortunately, while The Internet is more than happy to divulge exactly how the renderer in Doom works, the lighting algorithm seems to be a lot less exciting. So I went on an investigatory adventure past various blogs, lots of in-game testing, map editing, shader writing and even the Doom source code itself.
Now, while I'm still not completely sure how things work, or what *dest = dc_colormap[dc_source[(frac>>FRACBITS)&127]] means exactly, this is what I've gathered:
- Each sector in Doom has a brightness value between 0 and 1. A brightness of 0 means it's black and a brightness of 1 means it's fully lit.
- Actually, each sector has a brightness value between 0 and 2! Anything with a brightness of 1 or more is completely lit.
- If you move away from a sector, the brightness gradually decreases. The maximum distance modifies brightness by -1.
- So: sectors with a starting brightness value of more than 1 will never go completely dark, no matter how far you move away from them. A sector with an initial brightness of 2 won't ever go dark at all!
How does this look in-game, you ask? Well, have a look:
nailed it! |
Implementing this system meant that I had to chuck BasicEffect and write my own vertex and pixel shaders. Luckily XNA is great at providing templates and integrating shaders into the logic, so it wasn't as difficult as I had feared. Plus, in the end, we all learned something. And that's all that matters, right?
No comments:
Post a Comment