lygia
/generative
/wavelet
)Wavelet noise https://www.shadertoy.com/view/wsBfzK
Dependencies:
Use:
<vec2> worley(<vec2|vec3> pos)
#ifndef FNC_WAVELET
#define FNC_WAVELET
float wavelet(vec2 p, float phase, float k) {
float d = 0.0, s = 1.0, m=0.0, a = 0.0;
for (float i = 0.0; i < 4.0; i++) {
vec2 q = p*s;
a = random(floor(q)) * 1e3;
#ifdef WAVELET_VORTICITY
a += phase * random(floor(q)) * WAVELET_VORTICITY;
#endif
q = (fract(q) - 0.5) * rotate2d(a);
d += sin(q.x * 10.0 + phase) * smoothstep(.25, 0.0, dot(q,q)) / s;
p = p * mat2(0.54,-0.84, 0.84, 0.54) + i;
m += 1.0 / s;
s *= k;
}
return d / m;
}
float wavelet(vec3 p, float k) {
return wavelet(p.xy, p.z, k);
}
float wavelet(vec3 p) {
return wavelet(p, 1.24);
}
float wavelet(vec2 p, float phase) {
return wavelet(p, phase, 1.24);
}
float wavelet(vec2 p) {
return wavelet(p, 0.0, 1.24);
}
#endif
Dependencies:
Use:
<float2> worley(<float2|float3> pos)
#ifndef FNC_WAVELET
#define FNC_WAVELET
float wavelet(float2 p, float phase, float k) {
float d = 0.0, s = 1.0, m=0.0, a = 0.0;
for (float i = 0.0; i < 4.0; i++) {
float2 q = p*s;
a = random(floor(q)) * 1e3;
#ifdef WAVELET_VORTICITY
a += phase * random(floor(q)) * WAVELET_VORTICITY;
#endif
q = (fract(q) - 0.5) * rotate2d(a);
d += sin(q.x * 10.0 + phase) * smoothstep(.25, 0.0, dot(q,q)) / s;
p = p * matrix<float, 2, 2>(0.54,-0.84, 0.84, 0.54) + i;
m += 1.0 / s;
s *= k;
}
return d / m;
}
float wavelet(float3 p, float k) {
return wavelet(p.xy, p.z, k);
}
float wavelet(float3 p) {
return wavelet(p, 1.24);
}
float wavelet(float2 p, float phase) {
return wavelet(p, phase, 1.24);
}
float wavelet(float2 p) {
return wavelet(p, 0.0, 1.24);
}
#endif
Dependencies:
Use:
<vec2> worley(<vec2|vec3> pos)
const WAVELET_VORTICITY: f32 = 0.0;
fn wavelet(p: vec2f, phase: f32, scale: f32) -> f32 {
var d = 0.0;
var s = 1.0;
var m = 0.0;
var a = 0.0;
var tmp = p;
for (var i = 0.0; i < 4.0; i += 1.0) {
var q = tmp*s;
a = random2(floor(q)) * 1e3;
a += phase * random2(floor(q)) * WAVELET_VORTICITY;
q = (fract(q) - 0.5) * rotate2d(a);
d += sin(q.x * 10.0 + phase) * smoothstep(.25, 0.0, dot(q,q)) / s;
tmp = tmp * mat2x2(0.54,-0.84, 0.84, 0.54) + i;
m += 1.0 / s;
s *= scale;
}
return d / m;
}
fn waveletScaled3(p: vec3f, scale: f32) -> f32 {
return wavelet(p.xy, p.z, scale);
}
fn wavelet3(p: vec3f) -> f32 {
return wavelet(p.xy, p.z, 1.24);
}
fn waveletScaled2(p: vec2f, phase: f32) -> f32 {
return wavelet(p, phase, 1.24);
}
fn wavelet2(p: vec2f) -> f32 {
return wavelet(p, 0.0, 1.24);
}
LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.
Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).
It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository