Rotate Loop Square
Looping rotating square with a glow effect.
#ifdef GL_ES
precision mediump float;
#define GLSLIFY 1
#endif
uniform vec2 u_resolution;
uniform float u_time;
uniform vec2 u_mouse;
#define GLSLIFY 1
mat2 rotate2d(float _angle){
return mat2(cos(_angle),-sin(_angle), sin(_angle),cos(_angle));
}
float random (vec2 st) {
return fract(sin(dot(st.xy, vec2(12.9898,78.233)))*43758.5453123);
}
#define M_SQRT_2 1.41421356
float square(vec2 P, float size){
return abs(max(abs(P.x), abs(P.y)) - size/(2.0*M_SQRT_2));
}
float glow(float d, float str, float thickness){
return thickness / pow(d, str);
}
void main() {
vec2 uv = gl_FragCoord.xy/u_resolution.xy;
// uv.x *= u_resolution.x/u_resolution.y;
//grid repetition
vec2 uvs=uv*6.;
vec2 ipos = floor(uvs); // get the integer coords
vec2 fpos = fract(uvs); // get the fractional coords
uv= fpos*2.0-1.0;
uv*= rotate2d(random(ipos)*3.14159+u_time*0.5);
//drawing distance function
float draw = square(uv, 0.362);//sdFish(1.0, uv, 0.1),
// square(uv, 0.362), heart(uv, 0.5)
//float glow_draw = smoothstep(0.003,0.00,draw); //1st method
float glow_draw = glow(draw, 0.5, 0.076); //2nd method
//float glow_draw = exp(-draw*800.0); //3rd method
gl_FragColor = vec4(vec3(glow_draw),1.0);
}