// Copyright (c) 2023 Lachlan McDonald // This work is licensed under the MIT License (MIT) // https://github.com/lachlanmcdonald/magicavoxel-shaders // // xs brush/zigzag_range [Direction] [Width] // // xs_begin // author : '@lmcdx.bsky.social' // arg : { name = 'Direction' var = 'm_direction' range = '0 3' value = '0' step = '1' precision = '0' } // arg : { name = 'Width' var = 'm_width' range = '1 256' value = '2' step = '1' precision = '0' } // xs_end int direction = int(m_direction); float width = m_width; float roundf(float f) { return f >= 0.5 ? ceil(f) : floor(f); } float pal(float p) { float f = roundf(mix(0.0, float(i_num_color_sels), p)); return color_sel(f); } float map(vec3 v) { v = floor(v); if (direction == 1) { v.y = -v.y; } else if (direction == 2) { v.x = -v.x; v.y = -v.y; } else if (direction == 3) { v.x = -v.x; } float size = floor(float(i_num_color_sels) * width); float row = floor(v.y / size); float col = floor(v.x / size); vec2 k = v.xy - vec2(col, row) * size; float p = mod(row + col, 2.0) == 0.0 ? min(k.x, k.y) : max(k.x, k.y); return color_sel(floor(p / width)); }