// Copyright (c) 2023 Lachlan McDonald // This work is licensed under the MIT License (MIT) // https://github.com/lachlanmcdonald/magicavoxel-shaders // // xs soil [Color] [Headroom] // // xs_begin // author : '@lmcdx.bsky.social' // arg : { name = 'Color' var = 'm_color' range = '0 255' value = '1' step = '1' precision = '0' } // arg : { name = 'Headroom' var = 'm_headroom' range = '1 256' value = '1' step = '1' precision = '0' } // xs_end int headroom = int(m_headroom); 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; } float map(vec3 v) { float index = voxel(v); float index_beneath = voxel(v - vec3(0.0, 0.0, 1.0)); if (isSelectedPal(index_beneath) && index == 0.0) { for (int z = 1; z <= headroom; z += 1) { float d = v.z + float(z); if (voxel(vec3(v.x, v.y, d)) > 0.0) { return index; } } return m_color; } return index; }