Cyclic Noise
0b5vr
code:cyclic_noise.glsl
mat3 getOrthogonalBasis( vec3 z ) {
z = normalize( z );
vec3 up = abs( z.y ) < 0.99 ? vec3( 0.0, 1.0, 0.0 ) : vec3( 0.0, 0.0, 1.0 );
vec3 x = normalize( cross( up, z ) );
return mat3( x, cross( z, x ), z );
}
// Alternative totetmatt
mat3 orth(vec3 z){
z = normalize(z);
vec3 up = normalize(vec3(z.z,0.,-z.x));
return mat3(up,normalize(cross(z,up)),z);
}
vec3 cyclicNoise( vec3 p, float pump ) {
vec4 sum = vec4( 0.0 );
mat3 basis = getOrthogonalBasis( vec3( -1.0, 2.0, -3.0 ) );
for ( int i = 0; i < 5; i ++ ) {
p *= basis;
p += sin( p.yzx );
sum += vec4(
cross( cos( p ), sin( p.zxy ) ),
1.0
);
sum *= pump;
p *= 2.0;
}
return sum.xyz / sum.w;
}
Based on wrighter
Wrighter
https://scrapbox.io/files/65c358ce1a89430024c01754.png
code:cyclic_noise.glsl
mat3 getOrthogonalBasis(vec3 direction){
direction = normalize(direction);
vec3 right = normalize(cross(vec3(0,1,0),direction));
vec3 up = normalize(cross(direction, right));
return mat3(right,up,direction);
}
float cyclicNoise(vec3 p){
float noise = 0.;
// These are the variables. I renamed them from the original by nimitz
// So they are more similar to the terms used be other types of noise
float amp = 1.;
const float gain = 0.6;
const float lacunarity = 1.5;
const int octaves = 8;
const float warp = 0.3;
float warpTrk = 1.2 ;
const float warpTrkGain = 1.5;
// Step 1: Get a simple arbitrary rotation, defined by the direction.
vec3 seed = vec3(-1,-2.,0.5);
mat3 rotMatrix = getOrthogonalBasis(seed);
for(int i = 0; i < octaves; i++){
// Step 2: Do some domain warping, Similar to fbm. Optional.
p += sin(p.zxy*warpTrk - 2.*warpTrk)*warp;
// Step 3: Calculate a noise value.
// This works in a way vaguely similar to Perlin/Simplex noise,
// but instead of in a square/triangle lattice, it is done in a sine wave.
noise += sin(dot(cos(p), sin(p.zxy )))*amp;
// Step 4: Rotate and scale.
p *= rotMatrix;
p *= lacunarity;
warpTrk *= warpTrkGain;
amp *= gain;
}
return 1. - abs(noise)*0.5;
return (noise*0.25 + 0.5);
}