Files
Blockline/scripts/portrait_sun.gdshader
T

32 lines
1.3 KiB
Plaintext

shader_type sky;
uniform sampler2D portrait : source_color, filter_linear_mipmap;
uniform vec3 sun_direction = vec3(0.0, 0.8, 0.6);
void sky() {
vec3 direction = normalize(EYEDIR);
float elevation = max(direction.y, 0.0);
vec3 base = mix(vec3(0.56, 0.56, 0.46), vec3(0.09, 0.20, 0.33), pow(elevation, 0.45));
if (direction.y < 0.0) base = mix(vec3(0.56, 0.56, 0.46), vec3(0.22, 0.15, 0.09), min(-direction.y * 3.0, 1.0));
vec3 sun = normalize(sun_direction);
vec3 right = normalize(cross(sun, vec3(0.0, 1.0, 0.0)));
vec3 up = normalize(cross(right, sun));
float facing = dot(direction, sun);
vec2 disk = vec2(dot(direction,right), -dot(direction,up)) / 0.135;
float radius = length(disk);
if (facing > 0.0) {
float halo = exp(-radius * radius * 1.35);
base += vec3(1.0, 0.53, 0.12) * halo * 0.65;
float edge = 1.0 - smoothstep(0.87, 1.04, radius);
vec3 golden = vec3(1.65, 0.98, 0.27);
if (!AT_CUBEMAP_PASS) {
// Frame the face, excluding the photograph's border and most of the torso.
vec2 uv = vec2(0.49, 0.365) + disk * vec2(0.235, 0.245);
vec3 face = texture(portrait, clamp(uv, vec2(0.0), vec2(1.0))).rgb;
face = face * vec3(1.65, 1.24, 0.72) + vec3(0.16, 0.085, 0.015);
float blend = 1.0 - smoothstep(0.60, 0.94, radius);
golden = mix(golden, face, blend);
}
base = mix(base, golden, edge);
}
COLOR = base;
}