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!


