Skip to content

Commit 0a9d20b

Browse files
authored
Added Cellular 7 & 8 noise in FBM node
Add Cellular 7 & 8 noise (contributed by williamchange)
2 parents efb33ac + 6df4683 commit 0a9d20b

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

addons/material_maker/nodes/fbm4.mmg

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,84 @@
392392
"\treturn value / normalize_factor;",
393393
"}",
394394
"",
395+
"float cellular7_noise_2d(vec2 coord, vec2 size, float offset, float seed) {",
396+
"\tvec2 o = floor(coord)+rand2(vec2(seed, 1.0-seed))+size;",
397+
"\tvec2 f = fract(coord);",
398+
"\tfloat min_dist = 2.0;",
399+
"\tfor(float x = -1.0; x <= 1.0; x++) {",
400+
"\t\tfor(float y = -1.0; y <= 1.0; y++) {",
401+
"\t\t\tvec2 neighbor = vec2(float(x),float(y));",
402+
"\t\t\tvec2 node = rand2(mod(o + vec2(x, y), size)) + vec2(x, y);",
403+
"\t\t\tnode = 0.5 + 0.25 * sin(offset * TAU + TAU*node);",
404+
"\t\t\tvec2 diff = neighbor + node - f;",
405+
"\t\t\tconst float s3 = 0.866025;",
406+
"\t\t\tvec3 t = vec3(dot(diff, vec2(0,-1)), dot(diff, vec2(s3, 0.5)), dot(diff, vec2(-s3, 0.5)));",
407+
"\t\t\tfloat dist = max(t.x, max(t.y, t.z));",
408+
"\t\t\tmin_dist = min(min_dist, dist);",
409+
"\t\t}",
410+
"\t}",
411+
"\treturn min_dist;",
412+
"}",
413+
"",
414+
"float fbm_2d_cellular7(vec2 coord, vec2 size, int folds, int octaves, float persistence, float lacunarity, float offset, float seed) {",
415+
"\tfloat normalize_factor = 0.0;",
416+
"\tfloat value = 0.0;",
417+
"\tfloat scale = 1.0;",
418+
"\tfor (int i = 0; i < octaves; i++) {",
419+
"\t\tfloat noise = cellular7_noise_2d(coord*size, size, offset, seed+float(i));",
420+
"\t\tfor (int f = 0; f < folds; ++f) {",
421+
"\t\t\tnoise = abs(2.0*noise-1.0);",
422+
"\t\t}",
423+
"\t\tvalue += noise * scale;",
424+
"\t\tnormalize_factor += scale;",
425+
"\t\tsize *= lacunarity;",
426+
"\t\tscale *= persistence;",
427+
"\t}",
428+
"\treturn value / normalize_factor;",
429+
"}",
430+
"",
431+
"float cellular8_noise_2d(vec2 coord, vec2 size, float offset, float seed) {",
432+
"\tvec2 o = floor(coord)+rand2(vec2(seed, 1.0-seed))+size;",
433+
"\tvec2 f = fract(coord);",
434+
"\tfloat min_dist1 = 2.0;",
435+
"\tfloat min_dist2 = 2.0;",
436+
"\tfor(float x = -1.0; x <= 1.0; x++) {",
437+
"\t\tfor(float y = -1.0; y <= 1.0; y++) {",
438+
"\t\t\tvec2 neighbor = vec2(float(x),float(y));",
439+
"\t\t\tvec2 node = rand2(mod(o + vec2(x, y), size)) + vec2(x, y);",
440+
"\t\t\tnode = 0.5 + 0.25 * sin(offset * TAU + TAU*node);",
441+
"\t\t\tvec2 diff = neighbor + node - f;",
442+
"\t\t\tconst float s3 = 0.866025;",
443+
"\t\t\tvec3 t = vec3(dot(diff, vec2(0,-1)), dot(diff, vec2(s3, 0.5)), dot(diff, vec2(-s3, 0.5)));",
444+
"\t\t\tfloat dist = max(t.x, max(t.y, t.z));",
445+
"\t\t\tif (min_dist1 > dist) {",
446+
"\t\t\t\tmin_dist2 = min_dist1;",
447+
"\t\t\t\tmin_dist1 = dist;",
448+
"\t\t\t} else if (min_dist2 > dist) {",
449+
"\t\t\t\tmin_dist2 = dist;",
450+
"\t\t\t}",
451+
"\t\t}",
452+
"\t}",
453+
"\treturn min_dist2-min_dist1;",
454+
"}",
455+
"",
456+
"float fbm_2d_cellular8(vec2 coord, vec2 size, int folds, int octaves, float persistence, float lacunarity, float offset, float seed) {",
457+
"\tfloat normalize_factor = 0.0;",
458+
"\tfloat value = 0.0;",
459+
"\tfloat scale = 1.0;",
460+
"\tfor (int i = 0; i < octaves; i++) {",
461+
"\t\tfloat noise = cellular8_noise_2d(coord*size, size, offset, seed+float(i));",
462+
"\t\tfor (int f = 0; f < folds; ++f) {",
463+
"\t\t\tnoise = abs(2.0*noise-1.0);",
464+
"\t\t}",
465+
"\t\tvalue += noise * scale;",
466+
"\t\tnormalize_factor += scale;",
467+
"\t\tsize *= lacunarity;",
468+
"\t\tscale *= persistence;",
469+
"\t}",
470+
"\treturn value / normalize_factor;",
471+
"}",
472+
"",
395473
"// MIT License Inigo Quilez - https://www.shadertoy.com/view/Xd23Dh",
396474
"float voronoise_noise_2d( vec2 coord, vec2 size, float offset, float seed) {",
397475
"\tvec2 i = floor(coord) + rand2(vec2(seed, 1.0-seed)) + size;",
@@ -545,6 +623,14 @@
545623
"name": "Cellular 6",
546624
"value": "cellular6"
547625
},
626+
{
627+
"name": "Cellular 7",
628+
"value": "cellular7"
629+
},
630+
{
631+
"name": "Cellular 8",
632+
"value": "cellular8"
633+
},
548634
{
549635
"name": "Voronoise",
550636
"value": "voronoise"

0 commit comments

Comments
 (0)