Repository: godot
Issue: Volumetric fog exhibits dark edges in bright scenes
Labels: bug,topic:rendering,confirmed,topic:3d

### Tested versions

reproducible in: v4.4.dev [d19147e09], 4.3.stable

### System information

Godot v4.4.dev (d19147e09) - macOS Sequoia (15.2.0) - Multi-window, 2 monitors - Metal (Forward+) - integrated Apple M1 (Apple7) - Apple M1 (8 threads)

Godot v4.3.stable (77dcf97d8) - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 Ti (NVIDIA; 32.0.15.6614) - Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz (8 Threads)

### Issue description

fog volumes have a pronounced halo around the edge, visible especially in bright scenes.

![Image](https://github.com/user-attachments/assets/493b8ee2-2829-4027-811c-a6b1f7d6cc20)

looked like an alpha mul issue to me so i applied the following workaround locally, but i have only tested that it helps in my specific cases and didn't look deeper into it.

```diff
diff --git a/servers/rendering/renderer_rd/shaders/environment/sky.glsl b/servers/rendering/renderer_rd/shaders/environment/sky.glsl
index 105a42d708..35bebfffa0 100644
--- a/servers/rendering/renderer_rd/shaders/environment/sky.glsl
+++ b/servers/rendering/renderer_rd/shaders/environment/sky.glsl
@@ -270,7 +270,10 @@ void main() {
 
 	if (sky_scene_data.volumetric_fog_enabled) {
 		vec4 fog = volumetric_fog_process(uv);
-		frag_color.rgb = mix(frag_color.rgb, fog.rgb, fog.a * sky_scene_data.volumetric_fog_sky_affect);
+		if (fog.a > 0.0) {
+			float rcp_fog = 1.0 / fog.a;
+			frag_color.rgb = mix(frag_color.rgb, fog.rgb * rcp_fog, fog.a * sky_scene_data.volumetric_fog_sky_affect);
+		}
 	}
 
 	if (custom_fog.a > 0.0) {
diff --git a/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl b/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl
index 096e099391..ffc76abe5f 100644
--- a/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl
+++ b/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl
@@ -2756,8 +2756,10 @@ void fragment_shader(in SceneData scene_data) {
 #endif
 
 #ifndef FOG_DISABLED
-	diffuse_buffer.rgb = mix(diffuse_buffer.rgb, fog.rgb, fog.a);
-	specular_buffer.rgb = mix(specular_buffer.rgb, vec3(0.0), fog.a);
+	if (fog.a > 0.0) {
+		diffuse_buffer.rgb = mix(diffuse_buffer.rgb, fog.rgb / fog.a, fog.a);
+		specular_buffer.rgb = mix(specular_buffer.rgb, vec3(0.0), fog.a);
+	}
 #endif //!FOG_DISABLED
 
 #else //MODE_SEPARATE_SPECULAR
@@ -2773,7 +2775,9 @@ void fragment_shader(in SceneData scene_data) {
 
 #ifndef FOG_DISABLED
 	// Draw "fixed" fog before volumetric fog to ensure volumetric fog can appear in front of the sky.
-	frag_color.rgb = mix(frag_color.rgb, fog.rgb, fog.a);
+	if (fog.a > 0.0) {
+		frag_color.rgb = mix(frag_color.rgb, fog.rgb / fog.a, fog.a);
+	}
 #endif //!FOG_DISABLED
 
 #endif //MODE_SEPARATE_SPECULAR

```

result:
![Image](https://github.com/user-attachments/assets/5876dc69-4312-4338-bbf7-65a685cebda5)


### Steps to reproduce

run MRP, should be visible immediately in editor and when running. always present with fog volumes. (open fog.tscn if it errors on load, not sure why it does that)

### Minimal reproduction project (MRP)

MRP without / with workaround:

![Image](https://github.com/user-attachments/assets/18d92dda-5f87-421a-a375-838c9e4428eb)

![Image](https://github.com/user-attachments/assets/d3fc3c95-7144-4109-9755-63367ff46d4c)

[volumetric_halo.zip](https://github.com/user-attachments/files/18402653/volumetric_halo.zip)

MRP tested in 4.3 and v4.4.dev [d19147e09]