thebookofshaders/09/grid.frag
Patricio Gonzalez Vivo 34826d6759 fixing some stuff
2015-06-20 08:39:58 -04:00

36 lines
759 B
GLSL

// Author @patriciogv ( patriciogonzalezvivo.com ) - 2015
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform float u_time;
vec2 tile(vec2 _st, float _zoom){
_st *= _zoom;
return fract(_st);
}
float box(vec2 _st, vec2 _size){
_size = vec2(0.5)-_size*0.5;
vec2 uv = smoothstep(_size,_size+vec2(1e-4),_st);
uv *= smoothstep(_size,_size+vec2(1e-4),vec2(1.0)-_st);
return uv.x*uv.y;
}
void main(void){
vec2 st = gl_FragCoord.xy/u_resolution.xy;
vec3 color = vec3(0.0);
// Repat the space
st = tile(st,10.0);
// Draw a rectangle in each one
color = vec3(box(st,vec2(0.9)));
// Show the space coordinates
// color = vec3(st,0.0);
gl_FragColor = vec4(color,1.0);
}