fuckingtech/public/assets/glsl/lygia/generative/gnoise.glsl
Elias Rhouzlane bf76c6b086 fix: code
2025-04-06 17:23:52 +02:00

73 lines
No EOL
2.8 KiB
GLSL

#include "random.glsl"
#include "srandom.glsl"
#include "../math/cubic.glsl"
#include "../math/quintic.glsl"
/*
contributors: Patricio Gonzalez Vivo
description: Gradient Noise
use: gnoise(<float> x)
license:
- Copyright (c) 2021 Patricio Gonzalez Vivo under Prosperity License - https://prosperitylicense.com/versions/3.0.0
- Copyright (c) 2021 Patricio Gonzalez Vivo under Patron License - https://lygia.xyz/license
*/
#ifndef FNC_GNOISE
#define FNC_GNOISE
float gnoise(float x) {
float i = floor(x); // integer
float f = fract(x); // fraction
return mix(random(i), random(i + 1.0), smoothstep(0.,1.,f));
}
float gnoise(vec2 st) {
vec2 i = floor(st);
vec2 f = fract(st);
float a = random(i);
float b = random(i + vec2(1.0, 0.0));
float c = random(i + vec2(0.0, 1.0));
float d = random(i + vec2(1.0, 1.0));
vec2 u = cubic(f);
return mix( a, b, u.x) +
(c - a)* u.y * (1.0 - u.x) +
(d - b) * u.x * u.y;
}
float gnoise(vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
vec3 u = quintic(f);
return -1.0 + 2.0 * mix( mix( mix( random(i + vec3(0.0,0.0,0.0)),
random(i + vec3(1.0,0.0,0.0)), u.x),
mix( random(i + vec3(0.0,1.0,0.0)),
random(i + vec3(1.0,1.0,0.0)), u.x), u.y),
mix( mix( random(i + vec3(0.0,0.0,1.0)),
random(i + vec3(1.0,0.0,1.0)), u.x),
mix( random(i + vec3(0.0,1.0,1.0)),
random(i + vec3(1.0,1.0,1.0)), u.x), u.y), u.z );
}
float gnoise(vec3 p, float tileLength) {
vec3 i = floor(p);
vec3 f = fract(p);
vec3 u = quintic(f);
return mix( mix( mix( dot( srandom3(i + vec3(0.0,0.0,0.0), tileLength), f - vec3(0.0,0.0,0.0)),
dot( srandom3(i + vec3(1.0,0.0,0.0), tileLength), f - vec3(1.0,0.0,0.0)), u.x),
mix( dot( srandom3(i + vec3(0.0,1.0,0.0), tileLength), f - vec3(0.0,1.0,0.0)),
dot( srandom3(i + vec3(1.0,1.0,0.0), tileLength), f - vec3(1.0,1.0,0.0)), u.x), u.y),
mix( mix( dot( srandom3(i + vec3(0.0,0.0,1.0), tileLength), f - vec3(0.0,0.0,1.0)),
dot( srandom3(i + vec3(1.0,0.0,1.0), tileLength), f - vec3(1.0,0.0,1.0)), u.x),
mix( dot( srandom3(i + vec3(0.0,1.0,1.0), tileLength), f - vec3(0.0,1.0,1.0)),
dot( srandom3(i + vec3(1.0,1.0,1.0), tileLength), f - vec3(1.0,1.0,1.0)), u.x), u.y), u.z );
}
vec3 gnoise3(vec3 x) {
return vec3(gnoise(x+vec3(123.456, 0.567, 0.37)),
gnoise(x+vec3(0.11, 47.43, 19.17)),
gnoise(x) );
}
#endif