thebookofshaders/11/splatter.frag

45 lines
1.3 KiB
GLSL
Raw Normal View History

2015-09-09 14:32:52 +00:00
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
vec2 random2(vec2 st){
st = vec2( dot(st,vec2(127.1,311.7)),
dot(st,vec2(269.5,183.3)) );
return -1.0 + 2.0*fract(sin(st)*43758.5453123);
}
// Value Noise by Inigo Quilez - iq/2013
// https://www.shadertoy.com/view/lsf3WH
float noise(vec2 st) {
vec2 i = floor(st);
vec2 f = fract(st);
vec2 u = f*f*(3.0-2.0*f);
2017-08-19 10:11:58 +00:00
return mix( mix( dot( random2(i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ),
2015-09-09 14:32:52 +00:00
dot( random2(i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x),
2017-08-19 10:11:58 +00:00
mix( dot( random2(i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ),
2015-09-09 14:32:52 +00:00
dot( random2(i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y);
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
vec3 color = vec3(0.0);
float t = 1.0;
// Uncomment to animate
// t = abs(1.0-sin(u_time*.1))*5.;
2015-09-09 14:32:52 +00:00
// Comment and uncomment the following lines:
st += noise(st*2.)*t; // Animate the coordinate space
2015-09-09 14:32:52 +00:00
color = vec3(1.) * smoothstep(.18,.2,noise(st)); // Big black drops
color += smoothstep(.15,.2,noise(st*10.)); // Black splatter
color -= smoothstep(.35,.4,noise(st*10.)); // Holes on splatter
gl_FragColor = vec4(1.-color,1.0);
2017-08-19 10:11:58 +00:00
}