Skip to content

Instantly share code, notes, and snippets.

@KHN190 KHN190/simplex.frag Secret
Created Sep 23, 2019

Embed
What would you like to do?
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
vec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
vec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); }
float snoise(vec2 v) {
const vec4 C = vec4(0.211324865405187,
0.366025403784439,
-0.577350269189626,
0.024390243902439);
vec2 i = floor(v + dot(v, C.yy) ); // skewing, project to simplex
vec2 x0 = v - i + dot(i, C.xx); // unskewing, get simplex's vertex
vec2 i1;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
i = mod289(i);
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
+ i.x + vec3(0.0, i1.x, 1.0 ));
vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
m *= 1.2;
// gradient contribution from 3 verteces
vec3 g;
g.x = h.x * x0.x + x.x * x0.y;
g.yz = h.yz * x12.xz + x.yz * x12.yw;
return 80.0 * dot(m, g);
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
vec3 color = vec3(0.0);
vec2 pos = vec2(st * 10.);
float DF = 0.0;
float a = 0.0;
vec2 vel = vec2(0.0);
DF += snoise(pos + vel) *.25 + .25;
vel = vec2(u_time * .1);
DF += snoise(pos + vel) * .25 + .25;
color = vec3( smoothstep(.2, .25, abs(DF) * 2.0 - 1.0) );
gl_FragColor = vec4(1.0 - color, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.