Colored fog blending in a separate pass

jpprod

Newcomer
I'm developing a Direct3D graphics rendering engine which is being based around DX7 generation features, that is, fixed-function hardware T&L, cube mapping and dual texturing. The very cornerstone feature of the engine is arbitrary multitexturing, which naturally means heavy use of multipass techniques. Here are a couple of screenshots, using "programmer's art", if anyone's interested:

http://jt7-315a.tky.hut.fi/a2.jpg
http://jt7-315a.tky.hut.fi/a2.jpg

Besides the performance issues, the multipass rendering has a downside that it completely screws up the hardware fog blending stage. For any materials using other than basic alpha blendng, fog has to be done in a separate pass. I've spent countless hours on hitting my head on the wall on how to do this. Following works, but only produces black fog:

1) Set material color to white and no texture
2) Enable fog with desired range, and set color to black
3) Enable blending, and render objects the following way:
- Zero as source blending factor.
- Source color as destination blending factor. Thus vertexes up close end up the original color (DESTINATION * WHITE) and the far off vertexes end up black (DESTINATION * BLACK)

The vertex-based range fog is lightning fast on any GF-class hardware, and looks fantastic. Is there any way to render it in a separate blended pass on DX7 class hardware? I'd really hate to resort to pixel or vertex shaders, because the performance in software emulation mode would be horrid, since the game using the engine will have moderately high polycounts.
 
Render the whole scene with black fog first.

It works with normal blend and addition.
For multiply disable fog.
If you have other blending types, please tell, but it should work as well.

In the final (fog) pass, set material color to black, set final fog color, and render with addition.

If you don't need multiply at all you can do without a separate fog pass. Just set fog color to black when using additive blending.
 
Thanks for the excellent advice! The fogging has been bothering me for quite some time, but somehow changing the fog color according to blending function never crossed my mind.

Engine's also using multiply2x blending mode for detail textures, but as I understand it, this solution should work just fine there.
 
Back
Top