// Copyright (c) 2023 Lachlan McDonald // This work is licensed under the MIT License (MIT) // https://github.com/lachlanmcdonald/magicavoxel-shaders // // xs primitive/cylinder [Rotation] [Thickness] // // xs_begin // author : '@lmcdx.bsky.social' // arg : { name = 'Rotation' var = 'm_rotation' range = '0 2' value = '0' step = '1' precision = '0' } // arg : { name = 'Thickness' var = 'm_thickness' range = '0 100' value = '50' step = '1' precision = '0' } // xs_end int rotation = int(m_rotation); float thickness = 1.0 - (m_thickness / 100.0); vec3 pow3(vec3 v, float d) { v.x = pow(v.x, d); v.y = pow(v.y, d); v.z = pow(v.z, d); return v; } float dist(vec3 volume_size, vec3 v) { vec3 a = volume_size / 2.0; vec3 c = pow3(a, 2.0); vec3 j = pow3(v - a, 2.0); return sqrt((j.x / c.x) + (j.y / c.y)); } float map(vec3 v) { float f; if (rotation == 0) { f = dist(i_volume_size, v); } else if (rotation == 1) { f = dist(i_volume_size.zxy, v.zxy); } else if (rotation == 2) { f = dist(i_volume_size.zyx, v.zyx); } return (f <= 1.0 && f > thickness) ? i_color_index : 0.0; return 1.0; }