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

52 lines
No EOL
1.3 KiB
Text

#include "random.msl"
/*
contributors: Patricio Gonzalez Vivo
description: Worley noise
use: <float2> worley(<float2|float3> pos)
examples:
- /shaders/generative_worley.frag
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_WORLEY
#define FNC_WORLEY
float worley(float2 p){
float2 n = floor( p );
float2 f = fract( p );
float dis = 1.0;
for( int j= -1; j <= 1; j++ )
for( int i=-1; i <= 1; i++ ) {
float2 g = float2(i,j);
float2 o = random2( n + g );
float2 delta = g + o - f;
float d = length(delta);
dis = min(dis,d);
}
return 1.0-dis;
}
float worley(float3 p) {
float3 n = floor( p );
float3 f = fract( p );
float dis = 1.0;
for( int k = -1; k <= 1; k++ )
for( int j= -1; j <= 1; j++ )
for( int i=-1; i <= 1; i++ ) {
float3 g = float3(i,j,k);
float3 o = random3( n + g );
float3 delta = g+o-f;
float d = length(delta);
dis = min(dis,d);
}
return 1.0-dis;
}
#endif