stick-the-quick/vfx/sky.gdshader

110 lines
2.7 KiB
Plaintext
Raw Normal View History

shader_type sky;
#include "res://vfx/util.gdshaderinc"
const vec3 COLOR_DAY = vec3(0.0, 0.41, 0.8);
const vec3 COLOR_TWILIGHT = vec3(1.0, 0.29, 0.0);
const vec3 COLOR_NIGHT = vec3(0.01, 0.0, 0.03);
const vec3 COLOR_CLOUDS_LIGHT = vec3(2.0);
const vec3 COLOR_CLOUDS_HEAVY = vec3(0.25);
const vec3 COLOR_STARS = vec3(1.0);
const vec3 RADIANCE_DAY = vec3(0.625);
const vec3 RADIANCE_TWILIGHT = COLOR_TWILIGHT/2.0;
const vec3 RADIANCE_NIGHT = 3.0*COLOR_NIGHT;
const float RADIANCE_OVERCAST = 0.875;
uniform sampler2D cloud_map: TEXTURE_HINTS;
uniform sampler2D star_map: TEXTURE_HINTS;
uniform float night = 0.0;
uniform float overcast = 0.25;
uniform float windy = 0.25;
uniform float bright = 0.25;
uniform float twist = 0.0;
uniform float psychedelic = 0.0;
float index_cloud_map(vec2 uv) {
return mix(texture(cloud_map, uv).r, 0.0, 2.0*abs(0.5 - uv.y))*overcast;
}
float index_star_map(vec2 uv) {
return mix(texture(star_map, uv).r, 0.0, 2.0*abs(0.5 - uv.y));
}
vec4 clouds(vec2 uv) {
float m = index_cloud_map(uv);
return vec4(
vec3(mix(
COLOR_CLOUDS_LIGHT,
COLOR_CLOUDS_HEAVY,
overcast
))*mix(1.0, 0.125, night)*(m + 3.0)/4.0,
mix(m, 1.0,
mix(overcast,
overcast*overcast*overcast*overcast*overcast,
night))
);
}
vec4 stars(vec2 uv) {
return vec4(COLOR_STARS, mix(0.0, index_star_map(uv), night))*bright*4.0;
}
vec4 psychedelic_overlay(vec2 uv) {
return vec4(
hsv2rgb(vec3(
fract(uv.x),
mix(0.5, 0.0, 2.0*(0.5 - uv.y)*(0.5 - uv.y)),
2.0*abs(0.5 - uv.y)
)).rgb,
psychedelic
);
}
vec3 bgcolor(float y) {
vec3 top = mix(COLOR_DAY, COLOR_NIGHT, night);
vec3 bottom = mix(top, COLOR_TWILIGHT, 1.0 - abs(0.5 - night)*2.0);
return mix(top, bottom, y);
}
vec3 radiance() {
return mix(
mix(RADIANCE_DAY, RADIANCE_NIGHT, night),
RADIANCE_TWILIGHT,
0.5 - abs(0.5 - night)
)*mix(1.0, RADIANCE_OVERCAST, overcast)*bright*4.0;
}
vec3 composite(vec2 uv) {
float wind_factor = TIME*windy*windy*0.25;
vec2 uv_after_twist = vec2(
fract(uv.x + sin(TIME*uv.y*twist/180.0)),
uv.y
);
vec2 uv_after_wind = vec2(fract(uv.x + wind_factor), uv.y);
vec2 uv_after_both = vec2(
fract(uv.x + sin(TIME*uv.y*twist/180.0) + wind_factor),
uv.y
);
vec4 color = vec4(bgcolor(uv.y), 1.0);
color = alpha_blend(stars(
mix(mix(uv, uv_after_wind, psychedelic), uv_after_both, twist)
), color);
color = alpha_blend(clouds(uv_after_wind), color);
//color = alpha_blend(psychedelic_overlay(uv_after_both), color);
vec4 psych = psychedelic_overlay(uv_after_both);
color = vec4(mix(color.rgb, mix(
color.rgb*psych.rgb,
color.rgb + psych.rgb,
night
), psych.a), 1.0);
return color.rgb;
}
void sky() {
vec2 uv = SKY_COORDS;
if (AT_CUBEMAP_PASS) {
COLOR = radiance();
} else {
COLOR = composite(uv);
}
}