devNotes 5-23-2017 Toroidal Compute Shader

 

    if(app_mode == 0) //Platonics Mode  MONAD
    {
        velDeref = particles[index].velocity;
		pVel = velDeref;
		pPos = particles[index].position;
		smallVec.x = 0.000001;
		smallVec.y = 0.000001;
		smallVec.z = 0.000001;

		vRadius = pPos - att_0;
		att_Dist = length(vRadius);
   
        att_Dir  = -normalize(vRadius);
        nPerp = normalize(cross(att_Dir,att_0_axis));

		o_PP = att_0 + att_0_axis*dot(vRadius, att_0_axis);	//Origin on Perpendicular Plane
		vRad_PP = pPos - o_PP;								//Radius from Particle Position in Perp Plane
		rad_PP = length(vRad_PP);
		nRad_PP = normalize(vRad_PP);

		Step_incline = 1;
		if (rad_PP < att_0_inner_Radius)
		{
			Step_incline = smoothstep(0.61803*att_0_inner_Radius, att_0_inner_Radius, rad_PP);
		}
		else if (rad_PP > att_0_outer_Radius + att_0_inner_Radius)
		{
			Step_incline = 1 - smoothstep(att_0_outer_Radius + att_0_inner_Radius, 1.16803*(att_0_outer_Radius + att_0_inner_Radius), rad_PP);
		}
	
		if (Step_incline > 0)
		{
			float BC_mod = 1;
			if (Rotation_on == 1)
			{		
				float magVel_PP = length(cross( pVel, att_0_axis)) + 0.00001;
				nVel_PP = normalize(pVel - dot(pVel, att_0_axis)*att_0_axis + smallVec);
				vel_PP  = magVel_PP*nVel_PP;

				u_vel_PP = Step_incline * targetStrength * att_0_tangential_amount * att_0_strength;
			
				float square_Switch = 1;
				if (Birkeland_on == 1)
				{
					float tot_rad = att_0_outer_Radius + att_0_inner_Radius;//6PI = 3 cycles over radius			
					float x = 18.8495*rad_PP / tot_rad;
					BC_mod = sin(x)/x;
					u_vel_PP *= BC_mod;
					if (BC_mod < 0) square_Switch = -1;
				}

				if (abs(magVel_PP - abs(u_vel_PP)) > 0.025 || abs(dot(nVel_PP, nPerp)) < 0.9781)//5 percent tolerance Mag - 12°;
				{
					float3 velDiff = nPerp*u_vel_PP - vel_PP;
					velDeref += velDiff * 0.05f;//Power function here
				}

				float theta_by_2 = u_vel_PP*deltaTime / (2 * rad_PP);
				float tanLen = theta_by_2 / (1 - theta_by_2);
				vRad_PP = nRad_PP + tanLen*nPerp;
				nRad_PP = normalize(vRad_PP);

				velDeref += -square_Switch*((u_vel_PP * u_vel_PP) / rad_PP) * nRad_PP * deltaTime;//v^2/r
			}
			//Linear																									  //Linear
			velDeref += BC_mod * Step_incline * targetStrength * att_0_linear_amount * att_0_strength * att_0_axis * deltaTime;
        }        
		//Radial
        att_A = att_0 + att_0_split_dist*nPerp;
        att_B = att_0 - att_0_split_dist*nPerp;

        att_A_Dir = normalize(att_A - pPos);
        att_B_Dir = normalize(att_B - pPos);

        coeff = targetStrength * att_0_radial_amount * att_0_strength * deltaTime / att_Dist;
        velDeref += coeff * att_A_Dir;  
        velDeref += coeff * att_B_Dir; 

        if(attractor_Count != 1) //DIAD
        {