// Copyright (c) 2023 Lachlan McDonald // This work is licensed under the MIT License (MIT) // https://github.com/lachlanmcdonald/magicavoxel-shaders // // xs brush/diagonal [Direction] [Width A] [Width B] [Width C] [Width D] [Offset] [Shuffle] // // xs_begin // author : '@lmcdx.bsky.social' // arg : { name = 'Direction' var = 'm_direction' range = '0 5' value = '0' step = '1' precision = '0' } // arg : { name = 'Width A' var = 'm_width_a' range = '0 32' value = '2' step = '1' precision = '0' } // arg : { name = 'Width B' var = 'm_width_b' range = '0 32' value = '0' step = '1' precision = '0' } // arg : { name = 'Width C' var = 'm_width_c' range = '0 32' value = '0' step = '1' precision = '0' } // arg : { name = 'Width D' var = 'm_width_d' range = '0 32' value = '0' step = '1' precision = '0' } // arg : { name = 'Offset' var = 'm_offset' range = '0 256' value = '0' step = '1' precision = '0' } // arg : { name = 'Shuffle' var = 'm_shuffle' range = '0 256' value = '0' step = '1' precision = '0' } // xs_end int direction = int(m_direction); float width_1 = m_width_a; float width_2 = m_width_b; float width_3 = m_width_c; float width_4 = m_width_d; float offset = m_offset; float shuffle = m_shuffle; int imod(int a, int b) { return int(mod(float(a), float(b))); } float map(vec3 v) { // Line widths int width_count = 0; float widths[4]; if (width_1 >= 1.0) { widths[width_count] = width_1; width_count += 1; } if (width_2 >= 1.0) { widths[width_count] = width_2; width_count += 1; } if (width_3 >= 1.0) { widths[width_count] = width_3; width_count += 1; } if (width_4 >= 1.0) { widths[width_count] = width_4; width_count += 1; } // Adjustments for direction float x; float z; if (direction == 0) { v.z = 0.0; } else if (direction == 2) { v.z = -v.z; } else if (direction == 3) { v.x = -v.x; v.z = 0.0; } else if (direction == 4) { v.x = -v.x; } else if (direction == 5) { v.x = -v.x; v.z = -v.z; } int iter = 0; float p = abs(v.x + v.y + v.z + offset); float f = 0.0; while (f < p) { int idx = imod(iter, width_count); float w = widths[idx]; iter += 1; f += w; } if (i_num_color_sels == 1) { float i = mod(float(iter), 2.0); return i == 0.0 ? color_sel(i) : 0.0; } else { float i = mod(float(iter) + shuffle, float(i_num_color_sels)); return color_sel(i); } }