thebookofshaders/10/2d-random-mosaic.frag

32 lines
755 B
GLSL
Raw Normal View History

2015-03-15 15:35:14 +00:00
// Author @patriciogv - 2015
// http://patriciogonzalezvivo.com
2015-05-05 14:19:16 +00:00
2015-03-15 15:35:14 +00:00
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
2015-05-01 20:05:55 +00:00
uniform vec2 u_mouse;
2015-03-15 15:35:14 +00:00
uniform float u_time;
2015-07-23 14:02:53 +00:00
float random (vec2 st) {
return fract(sin(dot(st.xy,
2015-03-15 15:35:14 +00:00
vec2(12.9898,78.233)))*
43758.5453123);
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
2015-07-23 19:45:08 +00:00
st *= 10.0; // Scale the coordinate system by 10
2015-07-23 14:02:53 +00:00
vec2 ipos = floor(st); // get the integer coords
vec2 fpos = fract(st); // get the fractional coords
2015-03-15 15:35:14 +00:00
2015-07-23 19:45:08 +00:00
// Assign a random value based on the integer coord
2015-07-23 14:02:53 +00:00
vec3 color = vec3(random( ipos ));
2015-03-15 15:35:14 +00:00
2015-07-23 19:45:08 +00:00
// Uncomment to see the subdivided grid
2015-07-23 14:02:53 +00:00
// color = vec3(fpos,0.0);
2015-03-15 15:35:14 +00:00
gl_FragColor = vec4(color,1.0);
}