Files

39 lines
1.5 KiB
Plaintext
Raw Permalink Normal View History

shader_type fog;
uniform float density = 0.38675;
uniform float surface_height = 0.45;
uniform vec2 drift_velocity = vec2(0.16, -0.07);
uniform vec3 player_position = vec3(0.0);
uniform float fog_time = 0.0;
float hash(vec2 p) {
return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
}
float noise(vec2 p) {
vec2 cell = floor(p);
vec2 f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(hash(cell), hash(cell + vec2(1.0, 0.0)), f.x),
mix(hash(cell + vec2(0.0, 1.0)), hash(cell + vec2(1.0)), f.x), f.y);
}
void fog() {
vec2 p = WORLD_POSITION.xz;
vec2 flow = p - drift_velocity * fog_time;
float billow = noise(flow * 0.9 + vec2(fog_time * 0.02, -fog_time * 0.015));
float detail = noise(flow * 2.1 + vec2(-fog_time * 0.025, fog_time * 0.02));
float patches = noise(flow * 0.32);
float coverage = mix(0.02, 1.5, smoothstep(0.42, 0.76, patches));
float top = surface_height + (billow - 0.5) * 0.22;
float layer = 1.0 - smoothstep(top - 0.23, top + 0.10, WORLD_POSITION.y);
vec2 edge_distance = (vec2(0.5) - abs(UVW.xz - vec2(0.5))) * SIZE.xz;
float border = smoothstep(0.0, 0.5, min(edge_distance.x, edge_distance.y));
// A small moving opening makes the heroine's legs part the low clouds.
float wake = smoothstep(0.2, 0.75, distance(p, player_position.xz));
DENSITY = density * coverage * layer * border * mix(0.6, 1.25, billow * 0.7 + detail * 0.3)
* mix(0.45, 1.0, wake);
ALBEDO = vec3(0.66, 0.70, 0.69);
EMISSION = vec3(0.045, 0.052, 0.051) * layer * coverage * (density / 1.3);
}