float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
float dir(vec2 a, vec2 b, vec2 c)
{
return (a.x - c.x) * (b.y - c.y) - (b.x - c.x) * (a.y - c.y);
}
bool insideTri(vec2 p, vec2 a, vec2 b, vec2 c)
{
bool b1 = dir(p, a, b) < 0.0;
bool b2 = dir(p, b, c) < 0.0;
bool b3 = dir(p, c, a) < 0.0;
return ((b1 == b2) && (b2 == b3));
}
void applyColor(vec3 paint, inout vec3 col, vec2 p, vec2 a, vec2 b, vec2 c)
{
if (insideTri(p, a, b, c)) col = mix(col, paint, 0.4);
}
void rotate(inout vec2 point, float r) {
point = vec2(point.x*sin(r) +point.y*cos(r), point.x*cos(r)- point.y*sin(r));
}
float PI = 3.14159265358979323846264;
void drawTri(vec2 offset1, vec2 offset2, float size, float rotation, vec3 triColour, inout vec3 col, vec2 pos) {
float oneThirdPhase = PI*2.0/3.0;
float twoThirdPhase = PI*4.0/3.0;
vec2 triTop = vec2(0, 1) * size + offset1;
vec2 triBL = vec2(sin(oneThirdPhase),cos(oneThirdPhase)) * size + offset1;
vec2 triBR = vec2(sin(twoThirdPhase),cos(twoThirdPhase)) * size + offset1;
rotate(triTop, rotation);
rotate(triBL, rotation);
rotate(triBR, rotation);
applyColor(triColour, col, pos, triTop + offset2, triBL+offset2, triBR+ offset2);
}
void drawStar(vec2 offset, float size, float rotation, vec3 triColour, inout vec3 col, vec2 pos) {
vec2 topTriOff = offset;
vec2 bottomTriOff = offset;
float topTriRot = PI + rotation;
float bottomTriRot = rotation;
drawTri(vec2(0), topTriOff, size, topTriRot, triColour, col, pos);
drawTri(vec2(0), bottomTriOff, size, bottomTriRot, triColour, col, pos);
}
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void drawCircle(vec2 offset, float rad2, vec3 circColour, inout vec3 col, vec2 pos) {
if (length(offset-pos)<rad2) {
col = mix(col, circColour, 0.52);
}
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy / iResolution.xy;
fragColor.rgb = vec3(0.75,0.8,1.0);
vec3 starColourHSV = vec3(0,1,1);
float starheight = 0.0;
for (int i=0; i<100; ++i) {
starheight = rand(vec2(float(i),5.0));
starColourHSV.x = 0.9-starheight;
drawStar(vec2(0.1+mod((float(i)+iGlobalTime)/12.0,0.8), 0.1+starheight/8.0+sin(uv.x*PI)/4.0), 0.03, iGlobalTime+rand(vec2(float(i),3)), hsv2rgb(starColourHSV),fragColor.rgb, fragCoord.xy/iResolution.x);
}
for (int i = 0; i < 10; ++i) {
vec2 cloudOffset = vec2(0.1+rand(vec2(float(i),8))/12.0, 0.2+rand(vec2(float(i), 9))/12.0);
drawCircle(cloudOffset,0.05, vec3(1.0), fragColor.rgb, fragCoord.xy/iResolution.x);
}
for (int i = 0; i < 10; ++i) {
vec2 cloudOffset = vec2(0.85+rand(vec2(float(i),8))/12.0, 0.19+rand(vec2(float(i), 9))/12.0);
drawCircle(cloudOffset,0.05, vec3(1.0), fragColor.rgb, fragCoord.xy/iResolution.x);
}
}