Weird "fog" problem

I’m running into a weird problem with Unity’s fog function. I’m simulating an underwater scene and am using fog to simulate distance cue. I have a terrain, a vehicle and several other objects, all appear properly except one. Attached is a screen shot that illustrates the problem. The camera is not moving. As I move the object down, portions of it (the vertical posts) appear to be more effected by fog than others. This object is a single mesh, created in Blender and saved without any materials. The problem occurs no matter what I change in Blender or Unity. Any ideas what might be going on?

Update: Well, it doesn’t look like it’s an import problem. I took the same mesh and imported it into Wings, Carrara and Modo, then saved it to .OBJ and .FBX and imported them into Unity. The same problem occurs with all versions of the file.

What’s even more weird is that the problem doesn’t always appear in the game preview window, but it always appears in a stand alone game.

The problem appears to be how Unity handles fog for vertical cylinders. Box shapes seem to work OK.

Well, I think I found the solution. Unity apparently doesn’t like very long, narrow polygons. So I gave my long cylinders a couple “loop-subdivides”, and suddenly the fog is working correctly -and- my framerates doubled. Never thought I’d double my framerates by -increasing- my poly count! :wink: Just glad I figured it out…

It’s the way fog works on the graphics cards - if the card supports it we enable “radial fog”, which calculates fog density at vertices based on the actual distance to the eye, and then interpolates that over the polygon.

So if you have one vertex that is way to the side of the screen, and the other that is way to the other side, both will be fogged because they are actually far away from the eye. Then these “strongly fogged” values will be interpolated over the whole polygon.

Why we do use radial fog - it’s because in the majority of the cases (except your’s :)) it actually looks better. With non-radial fog you’d have fog density changing on non moving objects as you rotate the camera - which looks quite bad.

Why smaller polygons run faster - my best guess would be that some cards are slower to clip very large polygons against screen boundaries. Most cards have a thing called “guard band” that is some area around the screen where polygons can be clipped/culled really fast. Further than that they use a slower algorithm. Well, that’s my guess :slight_smile:

Thanks for that explanation Aras. That really makes a lot of sense, and in retrospect, using such long, narrow poly’s caused other problems (like UV mapping). By dividing the cylinder by 4, everything now works fine.

Not sure how the graphics card in my iMac works, so your explanation on the framerate thing sounds as plausible as any. Thanks again for your help. I learned something new… again!