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

33 lines
735 B
GLSL
Raw Normal View History

2015-03-15 15:35:14 +00:00
// Author @patriciogv - 2015
2016-04-24 15:26:26 +00:00
// Title: Mosaic
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;
2017-08-19 10:11:58 +00:00
float random (vec2 st) {
2015-07-23 14:02:53 +00:00
return fract(sin(dot(st.xy,
2017-08-19 10:11:58 +00:00
vec2(12.9898,78.233)))*
2015-03-15 15:35:14 +00:00
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
2017-08-19 10:11:58 +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);
2017-08-19 10:11:58 +00:00
}