Godot-proposals: Allow using the sky background as fog color

Created on 3 Jun 2020  路  5Comments  路  Source: godotengine/godot-proposals

Describe the project you are working on:

Scenes with large procedural terrains.

Describe the problem or limitation you are having in your project:

When using a fixed fog color, that color often doesn't match the sky background in a visually satisfactory way. This is especially an issue when the horizon color and the sky color are different, causing the terrain to fade into an ambiguous looking tint.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:

It would be helpful if Godot allowed the fog color to fade not just to a single color, but to the sky background itself. Can be very useful for both image skies as well as procedural ones.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

The best solution would seem a float setting ranging between 0 and 1, determining how much the sky influences the fog output. At 0 (default) it's only the specified color, at 1 it fully blends to the background instead. Could work alongside the sun color parameter already existent for fog.

If this enhancement will not be used often, can it be worked around with a few lines of script?:

As far as I could tell, there isn't any script function that can achieve this for fog, unless it's modifying the universal fog color itself or playing with complex shaders; It's still a single color which won't look right from all positions and angles. My suggestion shouldn't otherwise change old or default behavior, it would be appreciated even as an optional setting.

Is there a reason why this should be core and not an add-on in the asset library?:

As mentioned above there isn't any way I'm aware of for a script to turn the fog into an alpha mask that can fade against the environment sky. This also seems like something that would work best as a parameter to the Environment node and its fog section, being a simple feature with several use cases. Someone else seconded my idea on the forum thread for this, including the suggestion to post it here... also attached an image I took showing why a single fog color sometimes looks bad.

I9W5P7u

rendering

Most helpful comment

In doing some other work on fog I came up with a solution that I think will resolve this proposal nicely. It is to use the existing radiance_cubemap (used for skybox reflections) as fog colour. This is based on a presentation about rendering in the uncharted games.

The idea is to read from lower mipmaps of the radiance_cubemap the further away a point is from the camera.

Below is an image comparison, my idea is on top, below is two attempts to manually select a fog colour:
Fog-colours

While this isn't exactly the same as using the sky background as the fog colour, it achieves more plausible results and would actually have better performance.

All 5 comments

I have some ideas for this as we implement a new fog system in 4.0.

It's not going to be as simple as just changing the fog color to match the sky. In real life fog color is not the same as sky color. Although distant fog tends to blend into a similar color as the distant sky.

I've been looking into implementing a form of precomputed atmospheric scattering that would allow us to have accurately coloured fog based on the same atmospheric properties as the sky.

For sky boxes, I guess exposing the radiance mip maps could be enough to allow users to achieve a nicer style fog.

@clayjohn That sounds great, can't wait to see that in 4.0! Realism is what I'm going for so whatever will look correct is welcome. It would be nice if something like god rays could work with fog in addition, but these would be suggestions of their own of course.

How about a custom gradient or cubemap to have a stylized fog not fully matching the sky too?

For example Firewatch uses stylized fog
https://www.youtube.com/watch?v=ZYnS3kKTcGg

Plus you could have a dark sky (night) or you are indoor but there's fog (maybe lit but artificial/magic/etc lights) and the artists wants to provide some color variation to that.

@vagrantG I imagine that could be achieved by offering different blend modes for the fog, between the existing fog color and sky background. The best solution feels like being able to tweak the mixture between the two for each use case, even with the classic 4 options such as "mix, multiply, add, subtract". Of course there might be better ways as well.

In doing some other work on fog I came up with a solution that I think will resolve this proposal nicely. It is to use the existing radiance_cubemap (used for skybox reflections) as fog colour. This is based on a presentation about rendering in the uncharted games.

The idea is to read from lower mipmaps of the radiance_cubemap the further away a point is from the camera.

Below is an image comparison, my idea is on top, below is two attempts to manually select a fog colour:
Fog-colours

While this isn't exactly the same as using the sky background as the fog colour, it achieves more plausible results and would actually have better performance.

Was this page helpful?
0 / 5 - 0 ratings