Prometheus Diary, Volume 2
Posted by Alex Jordan on
My girlfriend is out of town for a week, so when I'm not busy staring at the wall or imagining that my cell phone is vibrating, I've decided to spend more time shoring up Prometheus:
New and improved from the last video is, um, me knowing what the hell I'm doing for a change. The multi-pass lighting is now up and running, and I've even thrown in a first-person camera control system, a flashlight effect that follows the camera as if the player were pointing a flashlight at things, and even some normal mapping for gits and shiggles. Details on the multi-pass lighting below the fold:
The multi-pass lighting was created in a rare instance of me being able to perfectly articulate exactly what I wanted to do, and then going about doing it. It took some fiddling, but XNA allows excellent control over just about any system's graphics card, so I was able to do things my way.
The multi-pass lighting involves three passes. Each pass is drawn on models like the backdrop and the big hovering orb shown in the video. The first pass renders everything with a solid dark-gray matte, representing the "Ambient" pass, or the lowest possible light level that a given surface can be lit (or not lit) by. If I wanted, I could set the Ambient pass to pure black for complete shadowing.
The second pass is the "Lighting" pass, which is where the neat things start happening. It checks every single pixel in the scene and computes its lighting value based on the nearest light source (it even throws in all the little shadows from a normal map as well as any cast shadows). The lighting value is then scaled by how bright the light is at that given point. This means that wherever there's lighting, the Ambient matte is overwritten by the new lighting value. At the center of a white light, there will be the solid color white. At the center of a red light, there will be red. Near the edges of these lights, there will be the faintest color of white (or red) that has transitioned off mostly into the Ambient matte.
This second pass is run X times, where X is the numbers of lights in the scene. After all these passes are done, the scene will have information pertaining to (a) the color of each light, and (b) the brightness of each light, on a per-pixel basis.
Then comes the third pass, or the "Texture" pass. Instead of adding each model's texture to the scene (which would wipe out the work done by the previous passes), I override the graphic card's processing instructions and tell it to multiply the texture against the color and brightness data that was done in the previous passes. Multiplying has the interesting effect of keeping the texture data intact, but effectively shading it by another color... in this case, the lighting information beneath it. A white light will keep the texture exactly the way it was (how can you shade something white?), while a red light will shade the texture red. And the best part is that this process automatically adjusts for where lit areas of different colors overlap (check out the Red/Green lighting overlap).
I have lots more crap to add, and not just on the lighting system. But I'm pleased as punch by how this has turned out so far.