thebookofshaders/12/cellnoise-01.frag

47 lines
922 B
GLSL
Raw Normal View History

2016-05-02 21:19:51 +00:00
// Author: @patriciogv
// Title: CellularNoise
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
vec2 random2( vec2 p ) {
return fract(sin(vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3))))*43758.5453);
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
vec3 color = vec3(.0);
2017-08-19 10:11:58 +00:00
// Scale
2016-05-02 21:19:51 +00:00
st *= 3.;
2017-08-19 10:11:58 +00:00
2016-05-02 21:19:51 +00:00
// Tile the space
vec2 i_st = floor(st);
vec2 f_st = fract(st);
2016-05-03 13:41:52 +00:00
vec2 point = random2(i_st);
vec2 diff = point - f_st;
2017-08-19 10:11:58 +00:00
2016-05-03 13:41:52 +00:00
float dist = length(diff);
2016-05-02 21:19:51 +00:00
// Draw the min distance (distance field)
2016-05-03 13:41:52 +00:00
color += dist;
2016-05-02 21:19:51 +00:00
// Draw cell center
2016-05-03 13:41:52 +00:00
color += 1.-step(.02, dist);
2017-08-19 10:11:58 +00:00
2016-05-02 21:19:51 +00:00
// Draw grid
color.r += step(.98, f_st.x) + step(.98, f_st.y);
2017-08-19 10:11:58 +00:00
2016-05-02 21:19:51 +00:00
// Show isolines
2016-05-03 13:41:52 +00:00
// color -= step(.7,abs(sin(27.0*dist)))*.5;
2017-08-19 10:11:58 +00:00
2016-05-02 21:19:51 +00:00
gl_FragColor = vec4(color,1.0);
2017-08-19 10:11:58 +00:00
}