Godot 4 fog shader - how?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi. Does anyone know how to write a simple noise-based volumetric fog shader (ie, the fog() function)??

:bust_in_silhouette: Reply From: omggomb

For 3D there is a built in volumetric fog in the Environment settings, for 2D I can’t help, sorry.

:bust_in_silhouette: Reply From: horsecar123

float noise(vec2 coord){
vec2 i = floor(coord);
vec2 f = fract(coord);
// 4 corners of a rectangle surrounding our point
float a = rand(i);
float b = rand(i + vec2(1.0, 0.0));
float c = rand(i + vec2(0.0, 1.0));
float d = rand(i + vec2(1.0, 1.0));
vec2 cubic = f * f * (3.0 - 2.0 * f);
return mix(a, b, cubic.x) + (c - a) * cubic.y * (1.0 - cubic.x) + (d - b) * cubic.x * cubic.y;
}