|
| 1 | +// After Inigo Quilez adapted for processing by Martin Prout |
| 2 | +// The MIT License |
| 3 | +// Copyright © 2013 Inigo Quilez |
| 4 | + |
| 5 | +#ifdef GL_ES |
| 6 | +precision mediump float; |
| 7 | +precision mediump int; |
| 8 | +#endif |
| 9 | + |
| 10 | +uniform vec3 iResolution; |
| 11 | +uniform float iTime; |
| 12 | +uniform sampler2D texture; |
| 13 | + |
| 14 | +void mainImage( out vec4 fragColor, in vec2 fragCoord ); |
| 15 | + |
| 16 | +void main() { |
| 17 | + mainImage(gl_FragColor,gl_FragCoord.xy); |
| 18 | +} |
| 19 | + |
| 20 | +vec2 hash2( vec2 p ) |
| 21 | +{ |
| 22 | + // procedural white noise |
| 23 | + return fract(sin(vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3))))*43758.5453); |
| 24 | +} |
| 25 | + |
| 26 | +vec3 voronoi( in vec2 x ) |
| 27 | +{ |
| 28 | + vec2 n = floor(x); |
| 29 | + vec2 f = fract(x); |
| 30 | + |
| 31 | + //---------------------------------- |
| 32 | + // first pass: regular voronoi |
| 33 | + //---------------------------------- |
| 34 | + vec2 mg, mr; |
| 35 | + |
| 36 | + float md = 8.0; |
| 37 | + for( int j=-1; j<=1; j++ ) |
| 38 | + for( int i=-1; i<=1; i++ ) |
| 39 | + { |
| 40 | + vec2 g = vec2(float(i),float(j)); |
| 41 | + vec2 o = 0.5 + 0.5*sin( iTime + 6.2831 * hash2( n + g )); |
| 42 | + vec2 r = g + o - f; |
| 43 | + float d = dot(r,r); |
| 44 | + if( d<md ) |
| 45 | + { |
| 46 | + md = d; |
| 47 | + mr = r; |
| 48 | + mg = g; |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + //---------------------------------- |
| 53 | + // second pass: distance to borders |
| 54 | + //---------------------------------- |
| 55 | + md = 8.0; |
| 56 | + for( int j=-2; j<=2; j++ ) |
| 57 | + for( int i=-2; i<=2; i++ ) |
| 58 | + { |
| 59 | + vec2 g = mg + vec2(float(i),float(j)); |
| 60 | + vec2 o = 0.5 + 0.5*sin( iTime + 6.2831 * hash2( n + g ) ); |
| 61 | + vec2 r = g + o - f; |
| 62 | + if( dot(mr-r,mr-r)>0.00001 ) |
| 63 | + md = min( md, dot( 0.5*(mr+r), normalize(r-mr) ) ); |
| 64 | + } |
| 65 | + return vec3( md, mr ); |
| 66 | +} |
| 67 | + |
| 68 | +void mainImage( out vec4 fragColor, in vec2 fragCoord ) |
| 69 | +{ |
| 70 | + vec2 p = fragCoord/iResolution.xx; |
| 71 | + |
| 72 | + vec3 c = voronoi( 8.0*p ); |
| 73 | + |
| 74 | + // isolines |
| 75 | + vec3 col = c.x*(0.5 + 0.5*sin(64.0*c.x))*vec3(1.0); |
| 76 | + // borders |
| 77 | + col = mix( vec3(1.0,0.6,0.0), col, smoothstep( 0.04, 0.07, c.x ) ); |
| 78 | + // feature points |
| 79 | + float dd = length( c.yz ); |
| 80 | + col = mix( vec3(1.0,0.6,0.1), col, smoothstep( 0.0, 0.12, dd) ); |
| 81 | + col += vec3(1.0,0.6,0.1)*(1.0-smoothstep( 0.0, 0.04, dd)); |
| 82 | + |
| 83 | + fragColor = vec4(col,1.0); |
| 84 | +} |
0 commit comments