Created
November 10, 2022 15:30
-
-
Save liamegan/75d6805f18dc509d0c986e482a498f64 to your computer and use it in GitHub Desktop.
GLSL value noise with
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
uniform sampler2D s_noise; | |
float pn( in vec3 p ) { | |
vec3 i = floor(p); p -= i; p *= p*(3. - 2.*p); | |
p.xy = texture(s_noise, (p.xy + i.xy + vec2(37, 17)*i.z + .5)/256., -100.).yx; | |
return mix(p.x, p.y, p.z); | |
} | |
float hash(float h) { | |
return pn(vec3(h, -h, h + 134.23453)); | |
} | |
float noise(vec3 x) { | |
vec3 p = floor(x); | |
vec3 f = fract(x); | |
f = f * f * (3.0 - 2.0 * f); | |
float n = p.x + p.y * 157.0 + 113.0 * p.z; | |
return mix( | |
mix(mix(hash(n + 0.0), hash(n + 1.0), f.x), | |
mix(hash(n + 157.0), hash(n + 158.0), f.x), f.y), | |
mix(mix(hash(n + 113.0), hash(n + 114.0), f.x), | |
mix(hash(n + 270.0), hash(n + 271.0), f.x), f.y), f.z) * 2. - 1.; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment