// Copyright (c) 2023 Lachlan McDonald // This work is licensed under the MIT License (MIT) // https://github.com/lachlanmcdonald/magicavoxel-shaders // // This script utilises or modifies code from other projects or publications. // Please see the attributions below for more information: // // 1. Copyright (c) 2020 ValgoBoi // MIT License (MIT) // https://github.com/ValgoBoi/clover-noise/blob/master/LICENSE // // xs pyramid [Noise] [Seed] // // xs_begin // author : '@lmcdx.bsky.social' // arg : { name = 'Noise' var = 'm_noise' range = '0 100' value = '0' step = '1' precision = '0' } // arg : { name = 'Seed' var = 'global_seed' range = '1 100' value = '1' step = '1' precision = '0' } // xs_end float noise = m_noise / 100.0; bool no_axis_mode = all(equal(ivec3(i_axis), ivec3(0))); bvec3 axis_mode = no_axis_mode ? bvec3(true) : equal(ivec3(i_axis), ivec3(1)); float hash(vec2 p, float seed) { p += seed + global_seed; return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 + p.x)))); } float hash(vec3 co, float seed) { return hash(vec2(hash(co.xy, seed), co.z), seed); } bool isSelectedPal(float p) { for (int i = 0; i < i_num_color_sels; i += 1) { if (p == color_sel(float(i))) { return true; } } return false; } bool isSelectedPal(vec3 v) { return isSelectedPal(voxel(v)); } float pal(float p) { float f = floor(mix(0.0, float(i_num_color_sels), p)); return color_sel(f); } float map(vec3 v) { float index = voxel(v); if (index == 0.0) { float index_beneath = voxel(v - vec3(0.0, 0.0, 1.0)); if (isSelectedPal(index_beneath)) { float t = 0.0; float a = 0.0; if (axis_mode.x) { t += 2.0; a += (isSelectedPal(vec3(v.x - 1.0, v.y, v.z - 1.0)) ? 1.0 : 0.0) + (isSelectedPal(vec3(v.x + 1.0, v.y, v.z - 1.0)) ? 1.0 : 0.0); } if (axis_mode.y) { t += 2.0; a += (isSelectedPal(vec3(v.x, v.y - 1.0, v.z - 1.0)) ? 1.0 : 0.0) + (isSelectedPal(vec3(v.x, v.y + 1.0, v.z - 1.0)) ? 1.0 : 0.0); } if (a == t) { float z = hash(v, a); if (noise == 0.0 || z > noise) { return index_beneath; } else { return pal(z); } } } } return index; }