Godot: Add exponential fog

Created on 25 Dec 2018  路  7Comments  路  Source: godotengine/godot

Godot version:
3.1, commit 10e9221c49eddc05cb36c0b582060cac9e4c8cef

The current implementation of fog is in my opinion visually not convincing (and I saw other issues stating the same). As the shader code states the fog is a smoothstep between the unfogged color and the color of the fog, based on the distance between the near and far value.

This gives, in combination with the custom depth curve much artistic controll, but is not based on any physical principles.

A more physically plausible result would probably be to use:
fog_amount = 1.0 - exp( -fog_z * fog_density )
where
float fog_z = length(vertex)
without any smoothstep.

To me, the results were much more convincing.
I don't know the theory behind the additional transmission effect for coloring the fog, but using exponential decay there as well produces visually very pleasing results which are at least more plausible even if still not physically correct.

This would replace the fog curves and distances with a single density parameter.

enhancement rendering

Most helpful comment

It cannot be just changed, it should be an option instead, because as you said it would prevent some artistic choices, such as having models crossing the far clip to blend with the horizon color.

All 7 comments

It cannot be just changed, it should be an option instead, because as you said it would prevent some artistic choices, such as having models crossing the far clip to blend with the horizon color.

Maybe it would be a solution to rename the current implementation to something like "fade to background" and add exponential fog as a physical based solution.

Probably the strength of spot or point lights should decrease with the distance too, as their emitted light gets absorbed from the fog in the same way.

If we rename or change anything it would break compatibility so it would be something for 4.0 in this case.

If it will be an option it would not break compatibility

Fade to background (skybox) is not easy to implement for now because it requires a texture unit and there are too many of them in use already. With Vulkan port it should be easy to add, as it can be bindless.

@reduz I was mostly mentionning that because it's possible to approximate it, as skyboxes can have a relatively uniform horizon.

Was this page helpful?
0 / 5 - 0 ratings