Files
galaxy/sky.gdshader
T
2024-06-16 02:47:40 +02:00

36 lines
1.2 KiB
Plaintext

shader_type sky;
uniform sampler2D base;
uniform vec3 base_color : source_color;
uniform float base_speed : hint_range(0,1) = 0.1;
uniform sampler2D layer;
uniform sampler2D layer_two;
uniform float NOISE : hint_range(0,1) = 0.5;
float random(vec2 coords) {
return fract(sin(dot(coords.xy, vec2(12.9898,78.233))) * 43758.5453);
}
void sky() {
float NOISE_GRANULARITY = NOISE / 100.0;
vec2 base_coords = vec2(SKY_COORDS.x+TIME*base_speed*0.05, SKY_COORDS.y);
vec4 base_pix = texture(base, base_coords);
float noise = mix(-NOISE_GRANULARITY, NOISE_GRANULARITY, random(base_coords));
float base_alpha = base_pix.a;
//if (base_alpha < 0.01 && base_alpha > 0.0) {
//base_alpha += noise;
//}
vec2 star_coords = vec2(SKY_COORDS.x-TIME*base_speed*0.05, SKY_COORDS.y);
vec4 star_pix = texture(layer_two, star_coords)*0.5;
vec2 galaxy_coords = vec2(SKY_COORDS.x-TIME*base_speed*0.01, SKY_COORDS.y);
vec4 galaxy_pix = max(vec4(0,0,0,0),texture(layer, galaxy_coords));
COLOR = vec3(0,0,0) + star_pix.rgb * star_pix.a + base_pix.rgb * base_alpha + + galaxy_pix.rgb * galaxy_pix.a;
// Called for every visible pixel in the sky background, as well as all pixels
// in the radiance cubemap.
}