Last active
July 20, 2018 00:28
-
-
Save native-m/f7031f937f3a742b44e823cca4f2065c to your computer and use it in GitHub Desktop.
🅱ractal 🅱ois 👌
This file contains hidden or 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 p) | |
{ | |
return fract(sin(dot(p, vec2(34.8313, 90.1394))) * 9813.91); | |
} | |
float noise(vec2 p) | |
{ | |
vec2 f = fract(p); | |
vec2 i = floor(p); | |
float noise[4]; | |
noise[0] = rand(i); | |
noise[1] = rand(i + vec2(1,0)); | |
noise[2] = rand(i + vec2(0,1)); | |
noise[3] = rand(i + vec2(1,1)); | |
return mix(mix(noise[0], noise[1], f.x), | |
mix(noise[2], noise[3], f.x), | |
smoothstep(0.0, 1.0, f.y)); | |
} | |
float fbm(vec2 p, int octave) | |
{ | |
float amp = 0.5; | |
float ret = 0.0; | |
while(octave != 0) | |
{ | |
ret += amp * noise(p); | |
amp *= 0.5; | |
//p *= float(octave) / 2.0; | |
p *= 2.0; | |
octave--; | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment