Glowing Square
A glowing square shader.
#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
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;
vec2 uvs = fract(uv * 6.);
vec2 ipos = floor(uvs);
vec2 fpos = fract(uvs);
uv = fpos * 2.0 - 1.0;
float circle_dist = square(uv, 0.75 + 0.45*random(ipos));
float glow_circle = glow(circle_dist, 0.328, 0.56);
vec3 color = vec3(glow_circle);
gl_FragColor = vec4(color * vec3(.3,.4,.65), 1.0);
}