Created
September 22, 2019 16:54
-
-
Save AlainBarrios/d1833ac535e48811a606ad883c514050 to your computer and use it in GitHub Desktop.
Fractal Brownian Motion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float rand (vec2 st) { | |
return fract(sin(dot(st.xy, | |
vec2(12.9898,78.233)))* | |
43758.5453123); | |
} | |
float noise(vec2 p){ | |
vec2 ip = floor(p); | |
vec2 u = fract(p); | |
u = u*u*(3.0-2.0*u); | |
float res = mix( | |
mix(rand(ip),rand(ip+vec2(1.0,0.0)),u.x), | |
mix(rand(ip+vec2(0.0,1.0)),rand(ip+vec2(1.0,1.0)),u.x),u.y); | |
return res*res; | |
} | |
float fbm(vec2 x) { | |
float v = 0.0; | |
float a = 0.5; | |
vec2 shift = vec2(100); | |
// Rotate to reduce axial bias | |
mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.50)); | |
for (int i = 0; i < NUM_OCTAVES; ++i) { | |
v += a * noise(x); | |
x = rot * x * 2.0 + shift; | |
a *= 0.5; | |
} | |
return v; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment