VOGONS


First post, by lizard78

User metadata
Rank Newbie
Rank
Newbie

Recently I was working on a DirectX 5 backend for my retro project and I encountered the same inconsistent table fog a lot of late 90s titles suffered from. There are extensive threads on here already discussing which driver works and what doesn't, but I didn't see anyone clearly explain why this happens. I'll give you a couple examples from my owning testing on my own project:
3dfx cards - worked fine, no surprises there.
ATI cards - worked fine, with later drivers.
S3 Savage IX8 - No fog, no surprise there right? It's a mobile chipset it probably doesn't support it

Well, then I checked the device caps, and it actually claimed to support table based fog (D3DPRASTERCAPS_FOGTABLE). I also checked it under wine d3d - same problem, no fog but also reporting fog table support. Just want to clear up before moving on I'm not talking about range or vertex based fog support at all here, this is only table fog.

At that point I figured I had to be doing something wrong, so I did some digging and found what I believe to be the answer. Behind the scenes DirectX supported both Z and W based table fog, but the Z based modes were only used in software rendering originally. With the Z based fog it expects FOGSTART / FOGEND to be in a normalized range (0 - 1) but W based table fog should be specified in world units. Due to the lack of the Z based fog in hardware at the time, if the device reported fog table support you could just assume it was W based and "get away with it". If you provide world units and the driver is assuming z based table fog, however, you'll get the all too familiar no fog look.

I eventually figured out based off a bit of testing that the driver was trying to do a Z based fog in this normalized range. Eventually I stumbled upon this old Nvidia document. Turns out for the correct W fogging in Direct3D (side note, this isn't required at all in Glide since it only uses W fog) you need to provide a perspective matrix so the driver can optionally perform Z based table fogging. Essentially it just checks if the last column of the matrix is affine and if it is it assumes Z based fogging (unless the driver does w based table fog).

So the bottom line I guess is that most of the problematic games likely aren't setting the perspective matrix in the correct way as it is very poorly documented (In fact the Directx5 sdk makes zero mention of it). They "just work" on drivers that natively use W based table fog or force it, but break on ones that require the perspective matrix to perform z based table fog. When I added the perspective matrix the Nvidia document calls for fog just started working everywhere, including the S3 card. I'm sure others who have written wrappers etc have bumped into this but I found it interesting to discover some of this on my own. Anyone else looked into this at all? I'm sure what I wrote here isn't the full story.

Reply 1 of 9, by marxveix

User metadata
Rank Oldbie
Rank
Oldbie

You are using Win9x or WinXP? Catalyst 7.11 drivers are good for table fog @ WinXP
From earliest ATi cards, Rage XL gives broken table fog with Thief II Game @ Win9x

Best ATi Rage3 drivers for 3DCIF / Direct3D / OpenGL / DVD : ATi RagePro drivers and software
30+MiniGL / OpenGL Win 9x dll files for all ATi Rage3 cards : Re: ATi RagePro OpenGL files

Reply 2 of 9, by rinale

User metadata
Rank Newbie
Rank
Newbie

Been researching this lately and from what I've could find the correct rendering of either vertex or pixel fog varies depending on the GPU architecture which physically implemented such fog support in one way or another, I am aware for example the ATi Radeon 7000 series cannot do Pixel Fog properly so is either vertex or offer an emulated workaround thru the driver or game to achieve Pixel Fog for example.

Vertex Fog is the most compatible and performant setting for all these old cards such as Nvidia TNT/TNT2/VANTA, Ati RAGE/7000 and such, 3dfx voodoo can do Pixel Fog without issues too (and I think S3 Savage can do it as well..)

Moreover the issues with each type of fog only affects very old GPUs by the time the Geforce 256 or Radeon 8000 released everything became more homogeneous with the same performance and support for either type of fog setting being handled entirely as shaders by the drivers from here on.

This is so so what i've been able to understand I might be wrong too

Reply 3 of 9, by lizard78

User metadata
Rank Newbie
Rank
Newbie
marxveix wrote on 2025-11-08, 11:57:

You are using Win9x or WinXP? Catalyst 7.11 drivers are good for table fog @ WinXP
From earliest ATi cards, Rage XL gives broken table fog with Thief II Game @ Win9x

I was running under Windows XP for the ATI test I did. Haven't tested that game specifically, it was my own project I was playing around with.

rinale wrote on 2025-11-08, 12:20:
Been researching this lately and from what I've could find the correct rendering of either vertex or pixel fog varies depending […]
Show full quote

Been researching this lately and from what I've could find the correct rendering of either vertex or pixel fog varies depending on the GPU architecture which physically implemented such fog support in one way or another, I am aware for example the ATi Radeon 7000 series cannot do Pixel Fog properly so is either vertex or offer an emulated workaround thru the driver or game to achieve Pixel Fog for example.

Vertex Fog is the most compatible and performant setting for all these old cards such as Nvidia TNT/TNT2/VANTA, Ati RAGE/7000 and such, 3dfx voodoo can do Pixel Fog without issues too (and I think S3 Savage can do it as well..)

Moreover the issues with each type of fog only affects very old GPUs by the time the Geforce 256 or Radeon 8000 released everything became more homogeneous with the same performance and support for either type of fog setting being handled entirely as shaders by the drivers from here on.

This is so so what i've been able to understand I might be wrong too

Yes, I think you hit the nail on the head - the behavior is pretty much vendor specific. After I made this topic I read the DirectX 6 docs (The table fog API was included in 5 but it's poorly documented there) and they also elude to this.
"Pixel fog can be applied using any of the fog formulas identified by members of the D3DFOGMODE enumerated type. Pixel-fog formula implementations are driver-specific, and if a driver doesn't support a complex fog formula, it should degrade to a less complex formula."

It seems like some drivers don't correctly degrade to a vertex based fog though, they just display no fog.

Reply 4 of 9, by marxveix

User metadata
Rank Oldbie
Rank
Oldbie

Nice if someone would figure out table fog and ati @ windows 98 as well. there is some registry tweaks, but its not 100% accurate.
I may test older cards, like ATi RageXL and Rage128 with Win XP if i have free time, but not gona promise anything at the moment.

Best ATi Rage3 drivers for 3DCIF / Direct3D / OpenGL / DVD : ATi RagePro drivers and software
30+MiniGL / OpenGL Win 9x dll files for all ATi Rage3 cards : Re: ATi RagePro OpenGL files

Reply 6 of 9, by lizard78

User metadata
Rank Newbie
Rank
Newbie
BEEN_Nath_58 wrote on 2025-11-09, 15:31:

Reminds me of the modern day Nvidia condition:
https://github.com/narzoul/DDrawCompat/commit … cd8537fa41e3564

Yes, this is the same issue. Unfortunately I think all of this confusion / different implementations around pixel fog is due to poor API design by Microsoft. There should have been a separate render state for W based fog instead of trying to shoehorn it into the same states as Z based (and trying to guess what the game wants based off a range of values passed to fogstart / fogend or the projection matrix). I'm not sure why it was implemented like that because W buffers and Z buffers have separate render states, fog should have been the same.

Reply 7 of 9, by BEEN_Nath_58

User metadata
Rank l33t
Rank
l33t

Iirc, in ATI cards, certain versions rendered table fog correctly while others didn't. I couldn't understand what was the necessity to change/optimise that code of driver

previously known as Discrete_BOB_058

Reply 8 of 9, by lizard78

User metadata
Rank Newbie
Rank
Newbie
BEEN_Nath_58 wrote on 2025-11-10, 06:13:

Iirc, in ATI cards, certain versions rendered table fog correctly while others didn't. I couldn't understand what was the necessity to change/optimise that code of driver

Probably trying to fix the behavior for one game and breaking it in another if I had to guess.

Reply 9 of 9, by BEEN_Nath_58

User metadata
Rank l33t
Rank
l33t
lizard78 wrote on 2025-11-10, 14:47:
BEEN_Nath_58 wrote on 2025-11-10, 06:13:

Iirc, in ATI cards, certain versions rendered table fog correctly while others didn't. I couldn't understand what was the necessity to change/optimise that code of driver

Probably trying to fix the behavior for one game and breaking it in another if I had to guess.

Well since DDrawcompat uses that fix by default, I am yet to encounter a game that is fixed by "what the driver follows".

previously known as Discrete_BOB_058