Files
4kintro/2d_thing.frag

50 lines
1.4 KiB
GLSL

#ifdef GL_ES
precision mediump float;
#endif
const float PI = 3.14159265;
uniform vec2 u_resolution;
uniform float u_time;
vec3 palette(float t) {
vec3 a = vec3(0.5, 0.5, 0.5);
vec3 b = vec3(1.0, 1.0, 1.0);
vec3 c = vec3(1.0, 1.0, 1.0);
vec3 d = vec3(0.0, 0.6666, 0.3333);
return a + b * cos(6.28318 * (c*t+d));
}
mat2 rotate(float angle){
return mat2(cos(angle), -sin(angle), sin(angle), cos(angle));
}
float polygon(vec2 position, float radius, float sides){
float a = atan(position.x, position.y);
float slice = PI * 2.0 / sides;
return 1. - step(radius, cos(floor(0.5 + a / slice) * slice - a) * length(position));
}
float star(vec2 position, float radius, float sides){
float a = atan(position.x, position.y);
float slice = PI * 2. / sides;
return 1. - step(radius, cos(floor(-2.0 + a / slice) * slice - a));
}
void main() {
vec2 uv = (gl_FragCoord.xy * 2. - u_resolution.xy) / u_resolution.y;
vec3 color = vec3(0.08, 0.22, 0.39);
vec3 mixer = vec3(0.);
for(float i = 1.; i < 3.; i++){
vec2 translate = uv;
translate *= rotate(i*1.4/5.); // + u_time);
float sides = 11.;
mixer += vec3(star(translate, 0.06, sides))*vec3(0.5725, 0.8275, 0.9451)*(i*0.7)*0.2;
}
color = mix( color, mixer, 0.5);
// color = max(color, polygon(uv, 0.3, 6.)),
gl_FragColor = vec4(color, 1.0);
}