ComfyUI Node
NOISE PERLIN (JOV_GL)
Classic Perlin noise
NOISE PERLIN (JOV_GL)
- iRes
- RGBA
- RGB
- MASK
◄frequency1.00►
◄amplitude1.00►
◄octaves4►
◄lacunarity2.00►
◄persistence0.50►
◄offset0.00►
◄seed0►
◄FRAGMENT// name: NOISE PERLIN
// desc: Classic Perlin noise
// category: NOISE
// control: res, seed
#ifndef LIB_NOISE_PARAMS
#define LIB_NOISE_PARAMS
#ifndef MAX_OCTAVES
#define MAX_OCTAVES 16
#endif
struct NoiseParams {
float frequency; // Base frequency multiplier
float amplitude; // Base amplitude multiplier
int octaves; // Number of octaves
float lacunarity; // Frequency multiplier per octave
float persistence; // Amplitude multiplier per octave (same as 'gain' in some functions)
float offset; // For ridge noise
int seed; // Seed
};
NoiseParams defaultNoiseParams() {
NoiseParams params;
params.frequency = 1.0;
params.amplitude = 1.0;
params.octaves = 4;
params.lacunarity = 2.0;
params.persistence = 0.5;
params.offset = 1.0;
params.seed = 0;
return params;
}
#endif
#ifndef LIB_NOISE_PERLIN
#define LIB_NOISE_PERLIN
#ifndef LIB_NOISE_RAND
#define LIB_NOISE_RAND
//------------------------------------------------------------------------------
// RANDOM VALUE GENERATORS
// These functions generate pseudo-random values using different input dimensions
//------------------------------------------------------------------------------
float noise_rand(float x) {
return fract(sin(x * 12.9898) * 43758.5453);
}
float noise_rand(vec2 co) {
return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453123);
}
float noise_rand(vec3 co) {
return fract(sin(dot(co, vec3(12.9898, 78.233, 45.678))) * 43758.5453123);
}
float noise_rand(vec4 co) {
return fract(sin(dot(co, vec4(12.9898, 78.233, 45.678, 94.673))) * 43758.5453123);
}
#endif
//------------------------------------------------------------------------------
// NOISE PERLIN
//------------------------------------------------------------------------------
// Generate 2D Perlin noise
float noise_perlin(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = smoothstep(0.,1.,f);
float a = noise_rand(i);
float b = noise_rand(i + vec2(1.0, 0.0));
float c = noise_rand(i + vec2(0.0, 1.0));
float d = noise_rand(i + vec2(1.0, 1.0));
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}
// 3D Perlin Noise function
float noise_perlin(vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
vec3 u = smoothstep(0.,1.,f);
float a = noise_rand(i);
float b = noise_rand(i + vec3(1.0, 0.0, 0.0));
float c = noise_rand(i + vec3(0.0, 1.0, 0.0));
float d = noise_rand(i + vec3(1.0, 1.0, 0.0));
float e = noise_rand(i + vec3(0.0, 0.0, 1.0));
float f0 = noise_rand(i + vec3(1.0, 0.0, 1.0));
float g0 = noise_rand(i + vec3(0.0, 1.0, 1.0));
float h0 = noise_rand(i + vec3(1.0, 1.0, 1.0));
return mix(mix(mix(a, b, u.x), mix(c, d, u.x), u.y), mix(mix(e, f0, u.x), mix(g0, h0, u.x), u.y), u.z);
}
// 4D Perlin Noise function
float noise_perlin(vec4 p) {
vec4 i = floor(p);
vec4 f = fract(p);
vec4 u = smoothstep(0.,1.,f);
float a = noise_rand(i);
float b = noise_rand(i + vec4(1.0, 0.0, 0.0, 0.0));
float c = noise_rand(i + vec4(0.0, 1.0, 0.0, 0.0));
float d = noise_rand(i + vec4(1.0, 1.0, 0.0, 0.0));
float e = noise_rand(i + vec4(0.0, 0.0, 1.0, 0.0));
float f0 = noise_rand(i + vec4(1.0, 0.0, 1.0, 0.0));
float g0 = noise_rand(i + vec4(0.0, 1.0, 1.0, 0.0));
float h0 = noise_rand(i + vec4(1.0, 1.0, 1.0, 0.0));
float i1 = noise_rand(i + vec4(0.0, 0.0, 0.0, 1.0));
float j1 = noise_rand(i + vec4(1.0, 0.0, 0.0, 1.0));
float k1 = noise_rand(i + vec4(0.0, 1.0, 0.0, 1.0));
float l1 = noise_rand(i + vec4(1.0, 1.0, 0.0, 1.0));
float m1 = noise_rand(i + vec4(0.0, 0.0, 1.0, 1.0));
float n1 = noise_rand(i + vec4(1.0, 0.0, 1.0, 1.0));
float o1 = noise_rand(i + vec4(0.0, 1.0, 1.0, 1.0));
float p1 = noise_rand(i + vec4(1.0, 1.0, 1.0, 1.0));
return mix(mix(mix(a, b, u.x), mix(c, d, u.x), u.y), mix(mix(e, f0, u.x), mix(g0, h0, u.x), u.y), u.z);
}
//------------------------------------------------------------------------------
// PARAMETERS
//------------------------------------------------------------------------------
#define NOISE_PERLIN(vec_type) float noise_perlin(vec_type p, NoiseParams params) { \
float value = 0.0; \
float frequency = params.frequency; \
float amplitude = params.amplitude; \
float maxValue = 0.0; \
for(int i = 0; i < min(params.octaves, MAX_OCTAVES); i++) { \
value += amplitude * noise_perlin(p * frequency); \
maxValue += amplitude; \
frequency *= params.lacunarity; \
amplitude *= params.persistence; \
} \
return value / maxValue; \
}
NOISE_PERLIN(vec2)
NOISE_PERLIN(vec3)
NOISE_PERLIN(vec4)
#endif
uniform float frequency; // 1.; 1.; 100.; 0.01 | Base frequency multiplier
uniform float amplitude; // 1.; 1.; 100.; 0.01 | Base amplitude multiplier
uniform int octaves; // 4; 1; 12; 1 | Number of octaves
uniform float lacunarity; // 2.; 0.; 100.; 0.01 | Frequency multiplier per octave
uniform float persistence; // 0.5; 0.; 100.; 0.01 | Amplitude multiplier per octave (same as 'gain' in some functions)
uniform float offset; // 0.; 0.; 100.; 0.01 | For ridge noise
void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
vec2 uv = fragCoord / iResolution.xy;
NoiseParams nparam = defaultNoiseParams();
nparam.frequency = frequency;
nparam.amplitude = amplitude;
nparam.octaves = octaves;
nparam.lacunarity = lacunarity;
nparam.persistence = persistence;
nparam.offset = offset;
nparam.seed = iSeed;
float perlin = noise_perlin(uv, nparam);
fragColor = vec4(perlin, perlin, perlin, 1.);
}►
CategoryJOV_GL 🌈/NOISE
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| frequencyopt | FLOAT | 1.001–100 | Base frequency multiplier |
| amplitudeopt | FLOAT | 1.001–100 | Base amplitude multiplier |
| octavesopt | INT | 41–12 | Number of octaves |
| lacunarityopt | FLOAT | 2.000–100 | Frequency multiplier per octave |
| persistenceopt | FLOAT | 0.500–100 | Amplitude multiplier per octave (same as 'gain' in some functions) |
| offsetopt | FLOAT | 0.000–100 | For ridge noise |
| iResopt | VEC2INT | 512,512 | Width and Height as a Vector2 Integer (x, y) |
| seedopt | INT | 00–9223372036854776000 | Number of frames to generate. 0 (continuous mode) means continue from the last queue generating the next single frame based on iFrameRate. |
| FRAGMENTopt | STRING | // name: NOISE PERLIN // desc: Classic Perlin noise // category: NOISE // control: res, seed #ifndef LIB_NOISE_PARAMS #define LIB_NOISE_PARAMS #ifndef MAX_OCTAVES #define MAX_OCTAVES 16 #endif struct NoiseParams { float frequency; // Base frequency multiplier float amplitude; // Base amplitude multiplier int octaves; // Number of octaves float lacunarity; // Frequency multiplier per octave float persistence; // Amplitude multiplier per octave (same as 'gain' in some functions) float offset; // For ridge noise int seed; // Seed }; NoiseParams defaultNoiseParams() { NoiseParams params; params.frequency = 1.0; params.amplitude = 1.0; params.octaves = 4; params.lacunarity = 2.0; params.persistence = 0.5; params.offset = 1.0; params.seed = 0; return params; } #endif #ifndef LIB_NOISE_PERLIN #define LIB_NOISE_PERLIN #ifndef LIB_NOISE_RAND #define LIB_NOISE_RAND //------------------------------------------------------------------------------ // RANDOM VALUE GENERATORS // These functions generate pseudo-random values using different input dimensions //------------------------------------------------------------------------------ float noise_rand(float x) { return fract(sin(x * 12.9898) * 43758.5453); } float noise_rand(vec2 co) { return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453123); } float noise_rand(vec3 co) { return fract(sin(dot(co, vec3(12.9898, 78.233, 45.678))) * 43758.5453123); } float noise_rand(vec4 co) { return fract(sin(dot(co, vec4(12.9898, 78.233, 45.678, 94.673))) * 43758.5453123); } #endif //------------------------------------------------------------------------------ // NOISE PERLIN //------------------------------------------------------------------------------ // Generate 2D Perlin noise float noise_perlin(vec2 p) { vec2 i = floor(p); vec2 f = fract(p); vec2 u = smoothstep(0.,1.,f); float a = noise_rand(i); float b = noise_rand(i + vec2(1.0, 0.0)); float c = noise_rand(i + vec2(0.0, 1.0)); float d = noise_rand(i + vec2(1.0, 1.0)); return mix(mix(a, b, u.x), mix(c, d, u.x), u.y); } // 3D Perlin Noise function float noise_perlin(vec3 p) { vec3 i = floor(p); vec3 f = fract(p); vec3 u = smoothstep(0.,1.,f); float a = noise_rand(i); float b = noise_rand(i + vec3(1.0, 0.0, 0.0)); float c = noise_rand(i + vec3(0.0, 1.0, 0.0)); float d = noise_rand(i + vec3(1.0, 1.0, 0.0)); float e = noise_rand(i + vec3(0.0, 0.0, 1.0)); float f0 = noise_rand(i + vec3(1.0, 0.0, 1.0)); float g0 = noise_rand(i + vec3(0.0, 1.0, 1.0)); float h0 = noise_rand(i + vec3(1.0, 1.0, 1.0)); return mix(mix(mix(a, b, u.x), mix(c, d, u.x), u.y), mix(mix(e, f0, u.x), mix(g0, h0, u.x), u.y), u.z); } // 4D Perlin Noise function float noise_perlin(vec4 p) { vec4 i = floor(p); vec4 f = fract(p); vec4 u = smoothstep(0.,1.,f); float a = noise_rand(i); float b = noise_rand(i + vec4(1.0, 0.0, 0.0, 0.0)); float c = noise_rand(i + vec4(0.0, 1.0, 0.0, 0.0)); float d = noise_rand(i + vec4(1.0, 1.0, 0.0, 0.0)); float e = noise_rand(i + vec4(0.0, 0.0, 1.0, 0.0)); float f0 = noise_rand(i + vec4(1.0, 0.0, 1.0, 0.0)); float g0 = noise_rand(i + vec4(0.0, 1.0, 1.0, 0.0)); float h0 = noise_rand(i + vec4(1.0, 1.0, 1.0, 0.0)); float i1 = noise_rand(i + vec4(0.0, 0.0, 0.0, 1.0)); float j1 = noise_rand(i + vec4(1.0, 0.0, 0.0, 1.0)); float k1 = noise_rand(i + vec4(0.0, 1.0, 0.0, 1.0)); float l1 = noise_rand(i + vec4(1.0, 1.0, 0.0, 1.0)); float m1 = noise_rand(i + vec4(0.0, 0.0, 1.0, 1.0)); float n1 = noise_rand(i + vec4(1.0, 0.0, 1.0, 1.0)); float o1 = noise_rand(i + vec4(0.0, 1.0, 1.0, 1.0)); float p1 = noise_rand(i + vec4(1.0, 1.0, 1.0, 1.0)); return mix(mix(mix(a, b, u.x), mix(c, d, u.x), u.y), mix(mix(e, f0, u.x), mix(g0, h0, u.x), u.y), u.z); } //------------------------------------------------------------------------------ // PARAMETERS //------------------------------------------------------------------------------ #define NOISE_PERLIN(vec_type) float noise_perlin(vec_type p, NoiseParams params) { \ float value = 0.0; \ float frequency = params.frequency; \ float amplitude = params.amplitude; \ float maxValue = 0.0; \ for(int i = 0; i < min(params.octaves, MAX_OCTAVES); i++) { \ value += amplitude * noise_perlin(p * frequency); \ maxValue += amplitude; \ frequency *= params.lacunarity; \ amplitude *= params.persistence; \ } \ return value / maxValue; \ } NOISE_PERLIN(vec2) NOISE_PERLIN(vec3) NOISE_PERLIN(vec4) #endif uniform float frequency; // 1.; 1.; 100.; 0.01 | Base frequency multiplier uniform float amplitude; // 1.; 1.; 100.; 0.01 | Base amplitude multiplier uniform int octaves; // 4; 1; 12; 1 | Number of octaves uniform float lacunarity; // 2.; 0.; 100.; 0.01 | Frequency multiplier per octave uniform float persistence; // 0.5; 0.; 100.; 0.01 | Amplitude multiplier per octave (same as 'gain' in some functions) uniform float offset; // 0.; 0.; 100.; 0.01 | For ridge noise void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord / iResolution.xy; NoiseParams nparam = defaultNoiseParams(); nparam.frequency = frequency; nparam.amplitude = amplitude; nparam.octaves = octaves; nparam.lacunarity = lacunarity; nparam.persistence = persistence; nparam.offset = offset; nparam.seed = iSeed; float perlin = noise_perlin(uv, nparam); fragColor = vec4(perlin, perlin, perlin, 1.); } | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| RGBA | IMAGE | Full channel [RGBA] image. If there is an alpha, the image will be masked out with it when using this output. |
| RGB | IMAGE | Three channel [RGB] image. There will be no alpha. |
| MASK | MASK | Single channel mask output. |