2015-04-15 19:30:08 +00:00
|
|
|
// Author @patriciogv - 2015
|
|
|
|
// http://patriciogonzalezvivo.com
|
|
|
|
|
2015-05-03 12:53:37 +00:00
|
|
|
#ifdef GL_OES_standard_derivatives
|
|
|
|
#extension GL_OES_standard_derivatives : enable
|
|
|
|
#endif
|
|
|
|
|
2015-04-15 19:30:08 +00:00
|
|
|
#ifdef GL_ES
|
|
|
|
precision mediump float;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PI 3.14159265359
|
|
|
|
#define TWO_PI 6.28318530718
|
|
|
|
|
|
|
|
uniform vec2 u_resolution;
|
|
|
|
uniform vec2 u_mouse;
|
|
|
|
uniform float u_time;
|
|
|
|
|
|
|
|
float shape(vec2 st, int N){
|
|
|
|
st = st *2.-1.;
|
|
|
|
float a = atan(st.x,st.y)+PI;
|
|
|
|
float r = TWO_PI/float(N);
|
|
|
|
return cos(floor(.5+a/r)*r-a)*length(st);
|
|
|
|
}
|
|
|
|
|
2015-05-03 12:53:37 +00:00
|
|
|
// Antialiazed Step function
|
|
|
|
// from http://webstaff.itn.liu.se/~stegu/webglshadertutorial/shadertutorial.html
|
|
|
|
float aastep(float threshold, float value) {
|
2015-05-05 14:19:16 +00:00
|
|
|
#ifdef GL_OES_standard_derivatives
|
2015-05-03 12:53:37 +00:00
|
|
|
float afwidth = 0.7 * length(vec2(dFdx(value), dFdy(value)));
|
|
|
|
return smoothstep(threshold-afwidth, threshold+afwidth, value);
|
2015-05-05 14:19:16 +00:00
|
|
|
#else
|
|
|
|
return step(threshold, value);
|
|
|
|
#endif
|
2015-05-03 12:53:37 +00:00
|
|
|
}
|
|
|
|
|
2015-04-15 19:30:08 +00:00
|
|
|
void main(){
|
|
|
|
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
|
|
|
st.x *= u_resolution.x/u_resolution.y;
|
|
|
|
vec3 color = vec3(0.0);
|
|
|
|
float d = 0.0;
|
|
|
|
|
2015-05-03 12:53:37 +00:00
|
|
|
d = min(shape(st,3),shape(st+vec2(0.,0.19),4));
|
|
|
|
|
|
|
|
gl_FragColor = vec4(vec3(1.0-aastep(.2,d)),1.0);
|
2015-04-15 19:30:08 +00:00
|
|
|
}
|