From 2b4bb3085c0354671e2a6c0d5f0076e1f8c6c005 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Date: Thu, 20 Aug 2020 17:03:19 +0100 Subject: [PATCH] Added the missing 2d-vnoise.frag in chapter 11 --- 11/2d-vnoise.frag | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 11/2d-vnoise.frag diff --git a/11/2d-vnoise.frag b/11/2d-vnoise.frag new file mode 100644 index 0000000..4f4f4ec --- /dev/null +++ b/11/2d-vnoise.frag @@ -0,0 +1,40 @@ +#ifdef GL_ES +precision mediump float; +#endif + +uniform vec2 u_resolution; +uniform vec2 u_mouse; +uniform float u_time; + +float 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( dot( st.xy, vec2(12.9898,78.233) ) ) * 43758.5453123); +} + +// Gradient 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); + + return mix( mix( random2( i + vec2(0.0,0.0) ), + random2( i + vec2(1.0,0.0) ), u.x), + mix( random2( i + vec2(0.0,1.0) ), + random2( i + 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); + + vec2 pos = vec2(st*10.0); + + color = vec3( noise(pos)*.5+.5 ); + + gl_FragColor = vec4(color,1.0); +}