// Weedシェーダ // ver 1.2 2020/12/02 // by yarunashi@dooon // xs_begin // author : 'yarunashi@dooon' // arg : { id = '0' name = 'rate' value = '0.3' range = '0.1 1.0' step = '0.1' decimal = '1' } // arg : { id = '1' name = 'range' value = '2' range = '1 2' step = '1' decimal = '0' } // arg : { id = '2' name = 'seed' value = '1' range = '0 1000' step = '1' decimal = '0' } // xs_end float rate = i_args[0]; float range = i_args[1]; float seed = i_args[2]; float rand(vec2 co, float seed) { return fract(sin(dot(co.xy * seed, vec2(12.9898, 78.233))) * 43758.5453); } float rand3(vec3 v, float seed) { float r = rand(vec2(v.x, v.y), seed); r = rand(vec2(r, v.z), seed); return r; } float weight(vec3 v, float rng){ float K = rng; float cnt = 0.0; float sum = 0.0; for(float z = -K; z <= K; z++) for(float y = -K; y <= K; y++) for(float x = -K; x <= K; x++) { if (voxel(vec3(v.x + x, v.y + y, v.z + z)) > 0.0) sum++; cnt++; } return sum / cnt; } float map(vec3 v) { float i = voxel(v); if ( i > 0.0) return i; if ((rand3(v, seed) < (rate * 0.1)) && (weight(v, range) > 0.0)) { return i_color_index; } return 0.0; }