// 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 cover [Headroom] [Noise] [Seed] // // xs_begin // author : '@lmcdx.bsky.social' // arg : { name = 'Headroom' var = 'm_headroom' range = '1 256' value = '1' step = '1' precision = '0' } // 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 headroom = m_headroom; float noise = m_noise / 100.0; 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); } 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 (voxel(vec3(v.x, v.y, v.z - 1.0)) > 0.0) { for (float z = 0.0; z < headroom; z += 1.0) { if (voxel(vec3(v.x, v.y, v.z + z)) > 0.0) { return index; } } float d = hash(v, 0.0); float z = hash(v, 128.0); if (noise == 0.0 || z > noise) { return pal(d); } else { return 0.0; } } return index; }