https://twitter.com/GPUComputing/status/793539395441664000/photo/1?ref_src=twsrc%5Etfw
float constVel; RWStructuredBuffer <Particle> particles; [numthreads(thread_group_size_x, thread_group_size_y, thread_group_size_z )] void CSMain ( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex ) { int index = DTid.x; //int index = DTid.x + DTid.y * thread_group_size_x * 32; if(app_mode == 0) //Platonics Mode { float3 velTemp = particles[index].velocity; float3 vel_T_Temp = particles[index].velocity; float3 vZero; vZero.x = 0; vZero.y = 0; vZero.z = 0; if(attractor_Count == 1 || attractor_Count == 2 || attractor_Count == 3 ) { float3 p0 = particles[index].position; float3 att_0_Dir = normalize((att_0 - particles[index].position)); float att_0_dist = distance(att_0, particles[index].position); vel_T_Temp += targetStrength * att_0_Dir * deltaTime / att_0_dist; float3 p1 = p0 + vel_T_Temp * deltaTime; float dist_P0_P1 = distance(p0, p1); float ratio = dist_P0_P1/att_0_dist; if(ratio < zero_mirror_radius) { velTemp = vel_T_Temp; } if(attractor_Count == 2 || attractor_Count == 3 ) { vel_T_Temp = particles[index].velocity; float3 att_1_Dir = normalize((att_1 - particles[index].position)); float att_1_dist = distance(att_1, particles[index].position); vel_T_Temp += targetStrength * att_1_Dir * deltaTime / att_1_dist; float3 p1 = p0 + vel_T_Temp * deltaTime; float dist_P0_P1 = distance(p0, p1); float ratio = dist_P0_P1/att_1_dist; if(ratio < zero_mirror_radius) { velTemp = vel_T_Temp; } if(attractor_Count == 3 ) { vel_T_Temp = particles[index].velocity; float3 att_2_Dir = normalize((att_2 - particles[index].position)); float att_2_dist = distance(att_2, particles[index].position); vel_T_Temp += targetStrength * att_2_Dir * deltaTime / att_2_dist; float3 p1 = p0 + vel_T_Temp * deltaTime; float dist_P0_P1 = distance(p0, p1); float ratio = dist_P0_P1/att_2_dist; if(ratio < zero_mirror_radius) { velTemp = vel_T_Temp; } } } //float dotVels = dot(normalize(velTemp), normalize(particles[index].velocity)); particles[index].velocity = velTemp; particles[index].position += particles[index].velocity * deltaTime; }