// xs_begin
// author : '@mode_vis'
// arg : { id = '0' name = 'Teeth' value = '6'   range = '3 64'    step = '1'		decimal = '0' }
// arg : { id = '1' name = 'Inner' value = '0.5' range = '0.0 1.0' step = '0.05'	decimal = '2' }
// xs_end

//===== user args =====
// uniform float	i_args[8];

//===== built-in args =====
// uniform vec3		i_volume_size;	// volume size [1-256]
// uniform float	i_color_index;	// color index [0-255]
// uniform vec3		i_mirror;		// mirror mode [0,1]
// uniform vec3		i_axis;			// axis mode [0,1]
// uniform float	i_iter;			// iteration index

//===== built-in functions ===== 
// float voxel( vec3 v );			// get voxel color index at position v

float map( vec3 v ) {				// generate a new voxel color index [0, 255] at position v ( v is at the center of voxel, such as vec3( 1.5, 2.5, 4.5 ) )
	float num_teeth = i_args[0];
	float inner = i_args[1];
	float evo = 1.0;

	vec3 center = i_volume_size * 0.5;
	vec3 p = (v-center);
	p.z = 1.0;
	float r = 0.12*min(i_volume_size.x,i_volume_size.y);
	float R = length(p);
    float a = atan(p.y,p.x);
    float f = smoothstep(-.5, evo, cos(a * num_teeth)) * r + r * 3. ;
	float d = step(r*4.*inner,R);
    float col = d * ( 1.-step(f,R));
	return col* i_color_index;
}