godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.43k stars 21.27k forks source link

Volumetric Fog overlaps over Distance Fog #95165

Open ricky-daniel13 opened 3 months ago

ricky-daniel13 commented 3 months ago

Tested versions

System information

Godot v4.3.rc2 - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1650 (NVIDIA; 32.0.15.5612) - AMD Ryzen 3 2200G with Radeon Vega Graphics (4 Threads)

Issue description

When you enable both Volumetric fog and Distance fog, any point where both fogs overlap, the volumetric fog will lit up/uncover any surface that are expected to be covered by the distance fog. My expected outcome is for the distance fog to always cover the surfaces that are meant to be hidden by it. Not sure if theres a perspective where the expected outcome is the current one.

Captura de pantalla 2024-08-05 090654 Windows to black background at end of hallway.

Captura de pantalla 2024-08-05 093252 Window completely hidden by fog at end of hallway

Captura de pantalla 2024-08-05 090634 Volumetric fog being lit up by the indirect lighing (SDFGI), overlapping the distance fog, lighting up the surfaces previously covered by the distance fog

Captura de pantalla 2024-08-05 090745 Volumetric fog being lit up by a spotlight with volumetric enabled, overlapping the distance fog, lighting up the surfaces previously covered by the distance fog

Steps to reproduce

  1. Open the project and the TestScene.tscn
  2. Move the camera behind SpotLight3D1, looking towards the window
  3. Observe the wall and windows, previously covered by fog, become visible
  4. Enable SDFGI in the WorldEnviroment node
  5. Move the camera behind SpotLight3D2, looking towards the window
  6. Observe the wall and windows, previously covered by fog, become visible

Minimal reproduction project (MRP)

MultiFogTest.zip

Calinou commented 3 months ago

Fog is drawn here in Forward+: https://github.com/godotengine/godot/blob/3978628c6cc1227250fc6ed45c8d854d24c30c30/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl#L1122-L1158

Most notably, see this comment:

Draw "fixed" fog before volumetric fog to ensure volumetric fog can appear in front of the sky.

This change was made in https://github.com/godotengine/godot/pull/42837 a while ago to address https://github.com/godotengine/godot/issues/42820.

ricky-daniel13 commented 3 months ago

Interesting, the behaviour outlined in the solved issue doesn't strike me as correct either. Wonder what could address both.

clayjohn commented 3 months ago

Interesting, the behaviour outlined in the solved issue doesn't strike me as correct either. Wonder what could address both.

Perhaps we need to do a min or max of the two fogs instead of applying one after another. Or perhaps there is a way we could process them together

Calinou commented 3 months ago

Perhaps we need to do a min or max of the two fogs instead of applying one after another. Or perhaps there is a way we could process them together

They already seem to be blended using some formula, not sure what it's supposed to be exactly:

https://github.com/godotengine/godot/blob/4359c28feafb39dd0157744a52f6746d49a38c37/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl#L1139-L1148