Volumetric Fog glitches when looking to the sides (Godot 4.2.2)

Godot Version

4.22

Question

With some fog setups that use box shapes, depending on the player’s view, the fog gets glitched and dissapears on one of the screen’s edges (top, bottom, left, right)

For instance, the following fog volume:

Dissapears on the side when looking at the right (happens on both editor and runtime)

This same issue is highlighted in Volumetric Fog shows artifacts at camera edge at certain angles inside Fog Volumes · Issue #74790 · godotengine/godot · GitHub, though the offered solution involves .cpp changes within the engine as far as I understand.

Is there a way to fix this through the shader code instead?

// NOTE: Shader automatically converted from Godot Engine 4.2.2.stable's FogMaterial.

shader_type fog;

uniform float density : hint_range(0, 1, 0.0001) = 1.0;
uniform vec4 albedo : source_color = vec4(1.0);
uniform vec4 emission : source_color = vec4(0, 0, 0, 1);
uniform float height_falloff = 0.0;
uniform float edge_fade = 0.1;
uniform sampler3D density_texture: hint_default_white;


void fog() {
    DENSITY = density * clamp(exp2(-height_falloff * (WORLD_POSITION.y - OBJECT_POSITION.y)), 0.0, 1.0);
    DENSITY *= texture(density_texture, UVW).r;
    DENSITY *= pow(clamp(-2.0 * SDF / min(min(SIZE.x, SIZE.y), SIZE.z), 0.0, 1.0), edge_fade);
    ALBEDO = albedo.rgb;
    EMISSION = emission.rgb;
}

The rest of the parameters are:

While I could change Godot version, I’d like to keep 4.2.2 for compatibility reasons with some plugins

Thank you!

While I could change Godot version, I’d like to keep 4.2.2 for compatibility reasons with some plugins

Have you tried a supported version? Unless this is a configuration issue the solution is to upgrade, and I think it’s better to not try to get support for outdated versions as the universal answer is to upgrade

The plugin I’m using (Qodot), was retired past version 4.2.2. Even though there is an alternative, it would involve major changes in all of the scenes, which is too much work for the development stage I’m currently in. That’s the reason I asked for a fix within the shader or the fog volume material as a termporary solution until I am able to change versions.

You could rebuild 4.2.2 from source with the fixes?

If it works in a recent version you can try to backport the changes to 4.2.2, but I don’t expect it to be a proper fix