37 lines
1.4 KiB
Plaintext
37 lines
1.4 KiB
Plaintext
shader_type fog;
|
|
|
|
uniform float density = 0.5525;
|
|
uniform float surface_height = 0.45;
|
|
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;
|
|
float billow = noise(p * 0.9 + vec2(fog_time * 0.12, -fog_time * 0.08));
|
|
float detail = noise(p * 2.1 + vec2(-fog_time * 0.09, fog_time * 0.15));
|
|
float patches = noise(p * 0.32 + vec2(fog_time * 0.025, -fog_time * 0.018));
|
|
float coverage = mix(0.08, 1.8, smoothstep(0.32, 0.68, 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);
|
|
}
|