godot icon indicating copy to clipboard operation
godot copied to clipboard

Make depth fog aerial perspective use the first radiance mipmap

Open Calinou opened this issue 1 year ago • 3 comments

This makes the depth fog fade directly to the sharpest possible version of the sky, as opposed to a blurred version that is less suitable for open world fog fading.

Subtle differences may still be noticeable when using a sky material with nearest-neighbor filtered textures, as it's always sampled with bilinear filtering. I've been wondering how we can improve upon this (perhaps with a project setting to adjust this sampler like https://github.com/godotengine/godot-proposals/issues/8063), but it's not too noticeable in practice if your Camera3D's Far property is adjusted to match the fog's end distance. Doing so is also beneficial for performance anyway.

Given this makes https://github.com/godotengine/godot/pull/84792 a lot more useful for open world games and affects visuals of projects using that feature, it would be good to get this in for 4.3 if possible :slightly_smiling_face:

The appearance of exponential fog isn't affected by this PR.

  • This closes https://github.com/godotengine/godot/issues/97803.

Testing project: test_fog_sky_fade.zip

Preview

Forward+

Before After
Screenshot_20240328_214643 webp Screenshot_20240328_220355 webp

Mobile

Fog aerial perspective appears darker in general (both without and with this PR), similar to its screen_texture issue where screen contents appear darker.

Before After
Screenshot_20240328_221536 png webp Screenshot_20240328_221523 png webp

Compatibility

Fog aerial perspective isn't implemented yet in the Compatibility rendering method.

Calinou avatar Mar 28 '24 21:03 Calinou

This is an interesting proposal. On the one hand, it allows users to trivially fade objects into the background (albeit in a much more expensive way than just using ALPHA). On the other hand it breaks atmospheric perspective which is a cheap way to simulate sky light scattering through fog. If the far plane just uses the sky value exactly, then it will always appear to do a non-foggy fadeout near the far plane.

clayjohn avatar Apr 04 '24 03:04 clayjohn

On the one hand, it allows users to trivially fade objects into the background (albeit in a much more expensive way than just using ALPHA).

I thought this approach would actually be faster, since no objects go through the transparent pipeline. Also, you avoid any transparency sorting issues that would otherwise occur, and you're not locked out from features such as SSR appearing on those materials.

If the far plane just uses the sky value exactly, then it will always appear to do a non-foggy fadeout near the far plane.

I've tested this on master, but while blur is reduced in this situation, it's not using the first mip as I'd expect (and is therefore still blurrier than intended):

PR master
Screenshot_20240328_220355 webp Screenshot_20240404_163727 webp

Fog Depth Begin is set to 20, Fog Depth End is set to 40 and Camera3D's Z Far is set to 40.

Calinou avatar Apr 04 '24 14:04 Calinou

I've tested this on master, but while blur is reduced in this situation, it's not using the first mip as I'd expect (and is therefore still blurrier than intended):

Maybe blurrier than intended if you are intending this to a fadeout to the sky. Again, aerial perspective simulates the sky light dispersing through fog. It is not a simply a blend with the background.

I have nothing against implementing a feature to allow depth fog to blend to the background sky color, but isn't what aerial perspective does. In my opinion, we shouldn't be removing a feature while adding another. If we are serious about using fog to implement a general purpose blend to sky value for far plane fading, then I think that we should do it in a way that doesn't hijack an existing feature

clayjohn avatar Apr 04 '24 18:04 clayjohn

What if we make the aerial perspective toggle-able between the current one and this one from the fog property?

PiCode9560 avatar Sep 17 '25 07:09 PiCode9560