// Volumetric cloud fog shader — samples a 3D density texture
// Godot's volumetric fog system handles lighting from scene lights.
// We add emission variation for height-based shading.
shader_type fog;
uniform sampler3D cloud_density : filter_linear_mipmap, repeat_enable;
uniform float density_scale : hint_range(0.0, 20.0) = 8.0;
uniform vec3 cloud_albedo : source_color = vec3(0.95, 0.95, 0.97);
uniform vec3 cloud_dark : source_color = vec3(0.3, 0.32, 0.38);
uniform float emission_boost : hint_range(0.0, 2.0) = 0.3;
void fog() {
float d = texture(cloud_density, UVW).r;
// Edge fade: soften density near box boundaries
vec3 edge = smoothstep(vec3(0.0), vec3(0.08), UVW) * smoothstep(vec3(0.0), vec3(0.08), vec3(1.0) - UVW);
float edge_fade = edge.x * edge.y * edge.z;
DENSITY = d * density_scale * edge_fade;
// Height-based albedo: dark at bottom, bright at top
float height = UVW.y;
ALBEDO = mix(cloud_dark, cloud_albedo, smoothstep(0.0, 0.6, height));
// Self-emission for cloud tops catching light (supplements scene light)
EMISSION = cloud_albedo * emission_boost * smoothstep(0.4, 0.9, height) * d;
}