// 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 brush/weave [Mode] [Size] [Line Color] [Line Width] [Seed] // // xs_begin // author : '@lmcdx.bsky.social' // arg : { name = 'Mode' var = 'm_mode' range = '0 2' value = '0' step = '1' precision = '0' } // arg : { name = 'Size' var = 'm_size' range = '1 256' value = '4' step = '1' precision = '0' } // arg : { name = 'Line Color' var = 'm_line_color' range = '0 255' value = '10' step = '1' precision = '0' } // arg : { name = 'Line Width' var = 'm_line_width' range = '0 256' value = '1' step = '1' precision = '0' } // arg : { name = 'Seed' var = 'global_seed' range = '1 100' value = '1' step = '1' precision = '0' } // xs_end int mode = int(m_mode); float size = m_size; float line_color = m_line_color; float line_width = m_line_width; 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(vec2 co) { return hash(co, 0.0); } 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 j = size + line_width; if (mod(v.x, j) > size) { return line_color; } else if (mod(v.y, j) > size) { return line_color; } else { float row = floor(v.y / j); float col = floor(v.x / j); float d = hash(vec2(row, col)); vec2 k = v.xy - (vec2(col, row) * j); float color; float inner; vec2 xy; if (mod(row + col, 2.0) == 0.0) { inner = floor(k.x / (size / 2.0)); xy = vec2(inner, d); } else { inner = floor(k.y / (size / 2.0)); xy = vec2(d, inner); } if (mode == 0) { color = hash(xy); } else if (mode == 1) { float d = row + col + inner; color = (mod(d, float(i_num_color_sels)) / float(i_num_color_sels)); } else if (mode == 2) { color = mod(inner, 2.0); } return pal(color); } }