#pragma kernel CSMain // Thread group size #define thread_group_size_x 32 #define thread_group_size_y 1 #define thread_group_size_z 1 struct Particle { float3 position; float3 velocity; }; float time; float pi; float deltaTime; float damping; float3 base; // HANDLE. float3 orbit; // BOB float targetStrengh; // POWER MAG float orbit_weighting; // POWER RATIO BETWEEN HANDLE AND BOB float radius_of_action; // RADIUS OF TROUGH / MOTE :) around ATTRACTOR int attractor_Count; float3 att_0; float3 att_1; float3 att_2; float3 att_3; float3 att_4; float3 att_5; float3 att_6; float3 att_7; float3 att_8; float3 att_9; float3 att_10; float3 att_11; float3 att_12; float3 att_13; float3 att_14; float3 att_15; float3 att_16; float3 att_17; float3 att_18; float3 att_19; 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(attractor_Count != 0)//0 MEANS THE BOB and THE ANCHOR { if(attractor_Count == 4 || attractor_Count == 6 || attractor_Count == 8 || attractor_Count == 12 || attractor_Count == 13 || attractor_Count == 20) { // 0 - 4 float3 att_0_Dir = normalize((att_0 - particles[index].position)); float3 att_1_Dir = normalize((att_1 - particles[index].position)); float3 att_2_Dir = normalize((att_2 - particles[index].position)); float3 att_3_Dir = normalize((att_3 - particles[index].position)); float att_0_dist = distance(att_0, particles[index].position); float att_1_dist = distance(att_1, particles[index].position); float att_2_dist = distance(att_2, particles[index].position); float att_3_dist = distance(att_3, particles[index].position); if(att_0_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_0_Dir * deltaTime / att_0_dist; } else { particles[index].velocity -= targetStrengh * att_0_Dir * deltaTime / att_0_dist; } if(att_1_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_1_Dir * deltaTime / att_1_dist; } else { particles[index].velocity -= targetStrengh * att_1_Dir * deltaTime / att_1_dist; } if(att_2_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_2_Dir * deltaTime / att_2_dist; } else { particles[index].velocity -= targetStrengh * att_2_Dir * deltaTime / att_2_dist; } if(att_3_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_3_Dir * deltaTime / att_3_dist; } else { particles[index].velocity -= targetStrengh * att_3_Dir * deltaTime / att_3_dist; } //------------------------------ if(attractor_Count == 6 || attractor_Count == 8 || attractor_Count == 12 || attractor_Count == 13 || attractor_Count == 20) { // 4 - 7 float3 att_4_Dir = normalize((att_4 - particles[index].position)); float3 att_5_Dir = normalize((att_5 - particles[index].position)); float att_4_dist = distance(att_4, particles[index].position); float att_5_dist = distance(att_5, particles[index].position); if(att_4_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_4_Dir * deltaTime / att_4_dist; } else { particles[index].velocity -= targetStrengh * att_4_Dir * deltaTime / att_4_dist; } if(att_5_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_5_Dir * deltaTime / att_5_dist; } else { particles[index].velocity -= targetStrengh * att_5_Dir * deltaTime / att_5_dist; } //------------------------------ if(attractor_Count == 8 || attractor_Count == 12 || attractor_Count == 13 || attractor_Count == 20) { float3 att_6_Dir = normalize((att_6 - particles[index].position)); float3 att_7_Dir = normalize((att_7 - particles[index].position)); float att_6_dist = distance(att_6, particles[index].position); float att_7_dist = distance(att_7, particles[index].position); if(att_6_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_6_Dir * deltaTime / att_6_dist; } else { particles[index].velocity -= targetStrengh * att_6_Dir * deltaTime / att_6_dist; } if(att_7_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_7_Dir * deltaTime / att_7_dist; } else { particles[index].velocity -= targetStrengh * att_7_Dir * deltaTime / att_7_dist; } //------------------------------ if(attractor_Count == 12 || attractor_Count == 13 || attractor_Count == 20) { // 8 - 11 float3 att_8_Dir = normalize((att_8 - particles[index].position)); float3 att_9_Dir = normalize((att_9 - particles[index].position)); float3 att_10_Dir = normalize((att_10 - particles[index].position)); float3 att_11_Dir = normalize((att_11 - particles[index].position)); float att_8_dist = distance(att_8, particles[index].position); float att_9_dist = distance(att_9, particles[index].position); float att_10_dist = distance(att_10, particles[index].position); float att_11_dist = distance(att_11, particles[index].position); if(att_8_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_8_Dir * deltaTime / att_8_dist; } else { particles[index].velocity -= targetStrengh * att_8_Dir * deltaTime / att_8_dist; } if(att_9_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_9_Dir * deltaTime / att_9_dist; } else { particles[index].velocity -= targetStrengh * att_9_Dir * deltaTime / att_9_dist; } if(att_10_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_10_Dir * deltaTime / att_10_dist; } else { particles[index].velocity -= targetStrengh * att_10_Dir * deltaTime / att_10_dist; } if(att_11_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_11_Dir * deltaTime / att_11_dist; } else { particles[index].velocity -= targetStrengh * att_11_Dir * deltaTime / att_11_dist; } //------------------------------ if(attractor_Count == 12 || attractor_Count == 13 || attractor_Count == 20) { // 12 float3 att_12_Dir = normalize((att_12 - particles[index].position)); float att_12_dist = distance(att_12, particles[index].position); if(att_12_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_12_Dir * deltaTime / att_12_dist; } else { particles[index].velocity -= targetStrengh * att_12_Dir * deltaTime / att_12_dist; } //------------------------------ if(attractor_Count == 13 || attractor_Count == 20) { //13 float3 att_13_Dir = normalize((att_13 - particles[index].position)); float att_13_dist = distance(att_13, particles[index].position); if(att_13_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_13_Dir * deltaTime / att_5_dist; } else { particles[index].velocity -= targetStrengh * att_13_Dir * deltaTime / att_13_dist; } //------------------------------ if(attractor_Count == 20) { float3 att_14_Dir = normalize((att_14 - particles[index].position)); float3 att_15_Dir = normalize((att_15 - particles[index].position)); float att_14_dist = distance(att_14, particles[index].position); float att_15_dist = distance(att_15, particles[index].position); if(att_14_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_14_Dir * deltaTime / att_14_dist; } else { particles[index].velocity -= targetStrengh * att_14_Dir * deltaTime / att_14_dist; } if(att_15_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_15_Dir * deltaTime / att_15_dist; } else { particles[index].velocity -= targetStrengh * att_15_Dir * deltaTime / att_15_dist; } // 16 - 19 float3 att_16_Dir = normalize((att_16 - particles[index].position)); float3 att_17_Dir = normalize((att_17 - particles[index].position)); float3 att_18_Dir = normalize((att_18 - particles[index].position)); float3 att_19_Dir = normalize((att_19 - particles[index].position)); float att_16_dist = distance(att_16, particles[index].position); float att_17_dist = distance(att_17, particles[index].position); float att_18_dist = distance(att_18, particles[index].position); float att_19_dist = distance(att_19, particles[index].position); if(att_16_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_16_Dir * deltaTime / att_16_dist; } else { particles[index].velocity -= targetStrengh * att_16_Dir * deltaTime / att_16_dist; } if(att_17_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_17_Dir * deltaTime / att_17_dist; } else { particles[index].velocity -= targetStrengh * att_17_Dir * deltaTime / att_17_dist; } if(att_18_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_18_Dir * deltaTime / att_18_dist; } else { particles[index].velocity -= targetStrengh * att_18_Dir * deltaTime / att_18_dist; } if(att_19_dist > radius_of_action) { particles[index].velocity += targetStrengh * att_19_Dir * deltaTime / att_19_dist; } else { particles[index].velocity -= targetStrengh * att_19_Dir * deltaTime / att_19_dist; } } } } } } } float3 vConstVel; vConstVel.x = 0; vConstVel.y = 0; vConstVel.z = constVel; particles[index].velocity = particles[index].velocity * damping; particles[index].position += particles[index].velocity * deltaTime; } } if(attractor_Count == 0) { // Direction and distance to target. float3 basedir1 = normalize((base - particles[index].position)); float3 orbitdir2 = normalize((orbit - particles[index].position)); float basedist1 = distance(base, particles[index].position); float orbitdist2 = distance(orbit, particles[index].position); float mult1 = orbit_weighting; float mult2 = (1 - orbit_weighting); float3 vConstVel; vConstVel.x = 0; vConstVel.y = 0; vConstVel.z = constVel; float len = length(particles[index].position); //particles[index].position if(particles[index].position.z > 300) { particles[index].position.z = -300; } if(basedist1 > radius_of_action) { particles[index].velocity += mult1 * targetStrengh * basedir1 * deltaTime / basedist1; } else { particles[index].velocity -= mult1 * targetStrengh * basedir1 * deltaTime / basedist1; } if(orbitdist2 > radius_of_action) { particles[index].velocity += mult2 * targetStrengh * orbitdir2 * deltaTime / orbitdist2; } else { particles[index].velocity -= mult2 * targetStrengh * orbitdir2 * deltaTime / orbitdist2; } particles[index].velocity = particles[index].velocity * damping; particles[index].position += particles[index].velocity * deltaTime + vConstVel* deltaTime; } }
https://youtu.be/8ptfyhBjXj8?t=2h22m26s
https://youtu.be/HEpJdLkDlOY