I encountered what looks like a bug or a poorly written shader. Here’re the problem and scenario. I included two pictures below to visualize the problem.
I created a water surface with Water2 (I also tried Water4, but the same result).
I set exponential fog.
I created a far textured background mesh mostly hidden by the fog.
I used Unity 5 beta 14
The problem:
The water surface reflects the textured background as if there was no fog!
Observations:
The closer I am to the water surface, the less fog there is. The clearer it is to see the background hidden by the fog.
As I move the camera away from the water surface, the more fog is drawn on the water. It tends to be more realistic when farther. However, the water surface should be more foggy than the air.
I also saw that thread from a guy having the same issue, but still no solution.
Bottom line: Seeing that graphic glitch really annoys me. The water reflection does not add value to the scene. Instead, it creates an annoying distraction and it makes me want to remove the reflection instead of having a glitch like this.
Should I fill a bug to report that problem?
Does anyone know if this is going to be fixed?
I’m thinking about a hack like a semi-transparent surface over the water to simulate the fog part over the water.
Did either of you guys find a solution to this? I have the same exact problem. Most of my game’s visuals come from fog and water reflections too…
In addition, with Unity 5 fog does not render on the surface of the water object. It did in Unity 5.
I tested it, and if you switch to the standard shader, fog will render.
(However, this is just the standard shader, and obviously doesn’t have the water reflection/refraction effect).
Fog and water reflections seem to be a pretty tough problem. From my experience:
It used to work in Unity 4 Direct X9 with forward rendering path.
With any other combination (Unity 5 OR Direct X 11 OR deferred rendering path), it doesn’t.
I think an explanation for this is that, in any of the latest cases, fog seems to be performed in camera clipping space, which means, for the reflection effect, AFTER having projected the world to the camera space WITH AN OBLIQUE projection matrix. This totally distorts the depth-to-clipspace relationship by changing the far clipping plane, and thus fog computations are totally ruined. If you’re into maths, see the magic details here: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf.
If you want to have correct fog in reflections, the solutions I can think of are few, and not easy:
rewrite every shader with fog computation in world space, thus avoiding the oblique camera projection problem, but this might be quite long, and it might slow down rendering performances.
use “hacks”, like creating artificial fog zones that are only visible in reflection (using camera render layers) to compensate for the missing fog; for example a huge sphere which renders some kind of blended color depending on the real distance to the camera, with soft edges, etc… This could get quite tricky and it can’t be a “perfect” solution anyways, because it won’t be as consistent as the real fog computation algorithm. But it may do the trick.
I hope this can shed some light on the problem. Maybe someone has other ideas?
@markefus : About the fog on the water itself in Unity 5, it seems that fog now has to be handled explicitly in vertex/fragment shaders, as stated here: http://docs.unity3d.com/Manual/UpgradeGuide5-Shaders.html. I think evey new shader in Unity 5 is fog compatible, but if you use old shaders or custom-made shaders, you have to handle the fog code yourself.