BasicEffect Fog question

Hi, I have to add fog to a minecraft-like engine I’m trying to do.

I have a problem with fog (which actually I’ve had before, but it is too annoying to ignore it in this project), and it is that the fog seems not to be “consistent” across the screen. I mean, when I’m focusing a mountain in the middle of the screen, the fog happens at some degree, but as I move the camera and the mountain moves out of the screen, the mountain appears gradually “less foggy”

I’ve added a video which makes the problem evident:

Does anybody knows what causes it and how to solve it?

The FOV is high (~65) but it also happens with smaller FOVs.

Thanks,
Kak

I assume fog is computed using only the Z coordinate (into the screen), as this is an easy distance formula, though it is incorrect. Fog is not computed using both X (left-right) and Z, which would require Pythagorean distance = sqrt(X^2 + Z^2).

If you play Doom 1993, you can see the same effect. Doom 1993 has a horizontal (left-right) FOV of 90, which is very close to your vertical FOV of 65. The higher the FOV, the more this is visible – because the smaller the Z value is at the screen edges. You can see something better (less fog) if you rotate the camera so the object is at the edge of the screen, since its Z coordinate is closer than when it’s in the center of the screen. Consider that the objects are moving around you like a circle, so its Z coordinates are closer on the edges, and furthest when directly in front.

To fix this, I would take a look at ApplyFog() here:

Just my 2 cents. This looks like the visibility range is being calculated by a “cube” modifier that has the camera in the center. It probably means you need to change that to a sphere.