Created
March 28, 2026 16:13
-
-
Save twobob/f59d71971e65b52b47e0987a10371ed8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| shader_type canvas_item; | |
| //render_mode unshaded; <-- to remove lighting | |
| // The seamless noise texture that will create the cloudy pattern | |
| uniform sampler2D noise_texture : repeat_enable; | |
| // Your custom black & white mask (White = Fog, Black = Transparent) | |
| uniform sampler2D mask_texture; | |
| // Fog color settings | |
| uniform vec4 fog_default_color : source_color = vec4(0.5, 0.5, 0.5, 0.5); // Grey | |
| uniform vec4 fog_heaven_color : source_color = vec4(0.8, 0.8, 0.0, 0.5); // Dark Yellow | |
| uniform vec4 fog_hell_color : source_color = vec4(0.5, 0.0, 0.0, 0.5); // Dark Red | |
| // Sin level: -1.0 (Hell) to 1.0 (Heaven) | |
| uniform float sin_level : hint_range(-1.0, 1.0) = 0.0; | |
| // Direction and speed of the drifting wind over time | |
| uniform vec2 scroll_speed = vec2(0.05, 0.02); | |
| // Sharpness / thickness of the clouds | |
| uniform float fog_density : hint_range(0.0, 2.0) = 1.0; | |
| void fragment() { | |
| // 1. Scroll our UV coordinates over time to push the clouds | |
| vec2 scrolled_uv = UV + scroll_speed * TIME; | |
| // 2. Read the noise value at the moving coordinate (Red channel) | |
| float noise_val = texture(noise_texture, scrolled_uv).r; | |
| noise_val = clamp(noise_val * fog_density, 0.0, 1.0); | |
| // 3. Read the exact static Mask pixel where we currently are | |
| vec4 mask_val = texture(mask_texture, UV); | |
| // Support either Alpha-transparent PNGs or flat B&W JPEGs for the mask | |
| float mask_alpha = mask_val.a * mask_val.r; | |
| // Lerp fog color based on sin_level | |
| vec4 current_fog_color = fog_default_color; | |
| if (sin_level > 0.0) { | |
| current_fog_color = mix(fog_default_color, fog_heaven_color, sin_level); | |
| } else if (sin_level < 0.0) { | |
| current_fog_color = mix(fog_default_color, fog_hell_color, -sin_level); | |
| } | |
| // 4. Output the fog colour, multiplied by the noise clouds AND the hard mask edge! | |
| COLOR.rgb = current_fog_color.rgb; | |
| COLOR.a = noise_val * mask_alpha * current_fog_color.a; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment