Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 1 | struct tint_symbol_1 { |
| 2 | float2 a_particlePos : TEXCOORD0; |
| 3 | float2 a_particleVel : TEXCOORD1; |
| 4 | float2 a_pos : TEXCOORD2; |
| 5 | }; |
| 6 | struct tint_symbol_2 { |
| 7 | float4 value : SV_Position; |
| 8 | }; |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 9 | |
| 10 | tint_symbol_2 vert_main(tint_symbol_1 tint_symbol) { |
| 11 | const float2 a_particlePos = tint_symbol.a_particlePos; |
| 12 | const float2 a_particleVel = tint_symbol.a_particleVel; |
| 13 | const float2 a_pos = tint_symbol.a_pos; |
Ben Clayton | ada560b | 2021-05-20 21:31:37 +0000 | [diff] [blame] | 14 | float angle = -(atan2(a_particleVel.x, a_particleVel.y)); |
| 15 | float2 pos = float2(((a_pos.x * cos(angle)) - (a_pos.y * sin(angle))), ((a_pos.x * sin(angle)) + (a_pos.y * cos(angle)))); |
Ben Clayton | 165512c | 2021-06-18 21:15:25 +0000 | [diff] [blame^] | 16 | const tint_symbol_2 tint_symbol_9 = {float4((pos + a_particlePos), 0.0f, 1.0f)}; |
| 17 | return tint_symbol_9; |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 18 | } |
| 19 | |
Ben Clayton | 5d2f34e | 2021-06-16 09:19:36 +0000 | [diff] [blame] | 20 | struct tint_symbol_3 { |
| 21 | float4 value : SV_Target0; |
| 22 | }; |
| 23 | |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 24 | tint_symbol_3 frag_main() { |
Ben Clayton | 165512c | 2021-06-18 21:15:25 +0000 | [diff] [blame^] | 25 | const tint_symbol_3 tint_symbol_10 = {float4(1.0f, 1.0f, 1.0f, 1.0f)}; |
| 26 | return tint_symbol_10; |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 27 | } |
| 28 | |
Ben Clayton | 165512c | 2021-06-18 21:15:25 +0000 | [diff] [blame^] | 29 | cbuffer cbuffer_params : register(b0, space0) { |
| 30 | uint4 params[2]; |
Ben Clayton | 5d2f34e | 2021-06-16 09:19:36 +0000 | [diff] [blame] | 31 | }; |
Ben Clayton | 5d2f34e | 2021-06-16 09:19:36 +0000 | [diff] [blame] | 32 | RWByteAddressBuffer particlesA : register(u1, space0); |
| 33 | RWByteAddressBuffer particlesB : register(u2, space0); |
| 34 | |
| 35 | struct tint_symbol_5 { |
| 36 | uint3 gl_GlobalInvocationID : SV_DispatchThreadID; |
| 37 | }; |
| 38 | |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 39 | [numthreads(1, 1, 1)] |
| 40 | void comp_main(tint_symbol_5 tint_symbol_4) { |
| 41 | const uint3 gl_GlobalInvocationID = tint_symbol_4.gl_GlobalInvocationID; |
| 42 | uint index = gl_GlobalInvocationID.x; |
| 43 | if ((index >= 5u)) { |
| 44 | return; |
| 45 | } |
| 46 | float2 vPos = asfloat(particlesA.Load2((16u * index))); |
| 47 | float2 vVel = asfloat(particlesA.Load2(((16u * index) + 8u))); |
| 48 | float2 cMass = float2(0.0f, 0.0f); |
| 49 | float2 cVel = float2(0.0f, 0.0f); |
| 50 | float2 colVel = float2(0.0f, 0.0f); |
| 51 | int cMassCount = 0; |
| 52 | int cVelCount = 0; |
| 53 | float2 pos = float2(0.0f, 0.0f); |
| 54 | float2 vel = float2(0.0f, 0.0f); |
| 55 | { |
| 56 | uint i = 0u; |
Ben Clayton | ada560b | 2021-05-20 21:31:37 +0000 | [diff] [blame] | 57 | while (true) { |
| 58 | if (!((i < 5u))) { |
| 59 | break; |
| 60 | } |
| 61 | if ((i == index)) { |
| 62 | { |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 63 | i = (i + 1u); |
| 64 | } |
Ben Clayton | ada560b | 2021-05-20 21:31:37 +0000 | [diff] [blame] | 65 | continue; |
| 66 | } |
| 67 | pos = asfloat(particlesA.Load2((16u * i))).xy; |
| 68 | vel = asfloat(particlesA.Load2(((16u * i) + 8u))).xy; |
Ben Clayton | 165512c | 2021-06-18 21:15:25 +0000 | [diff] [blame^] | 69 | const int scalar_offset = (4u) / 4; |
| 70 | if ((distance(pos, vPos) < asfloat(params[scalar_offset / 4][scalar_offset % 4]))) { |
Ben Clayton | ada560b | 2021-05-20 21:31:37 +0000 | [diff] [blame] | 71 | cMass = (cMass + pos); |
| 72 | cMassCount = (cMassCount + 1); |
| 73 | } |
Ben Clayton | 165512c | 2021-06-18 21:15:25 +0000 | [diff] [blame^] | 74 | const int scalar_offset_1 = (8u) / 4; |
| 75 | if ((distance(pos, vPos) < asfloat(params[scalar_offset_1 / 4][scalar_offset_1 % 4]))) { |
Ben Clayton | ada560b | 2021-05-20 21:31:37 +0000 | [diff] [blame] | 76 | colVel = (colVel - (pos - vPos)); |
| 77 | } |
Ben Clayton | 165512c | 2021-06-18 21:15:25 +0000 | [diff] [blame^] | 78 | const int scalar_offset_2 = (12u) / 4; |
| 79 | if ((distance(pos, vPos) < asfloat(params[scalar_offset_2 / 4][scalar_offset_2 % 4]))) { |
Ben Clayton | ada560b | 2021-05-20 21:31:37 +0000 | [diff] [blame] | 80 | cVel = (cVel + vel); |
| 81 | cVelCount = (cVelCount + 1); |
| 82 | } |
| 83 | { |
| 84 | i = (i + 1u); |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | } |
| 88 | if ((cMassCount > 0)) { |
| 89 | cMass = ((cMass / float2(float(cMassCount), float(cMassCount))) - vPos); |
| 90 | } |
| 91 | if ((cVelCount > 0)) { |
| 92 | cVel = (cVel / float2(float(cVelCount), float(cVelCount))); |
| 93 | } |
Ben Clayton | 165512c | 2021-06-18 21:15:25 +0000 | [diff] [blame^] | 94 | const int scalar_offset_3 = (16u) / 4; |
| 95 | const int scalar_offset_4 = (20u) / 4; |
| 96 | const int scalar_offset_5 = (24u) / 4; |
| 97 | vVel = (((vVel + (cMass * asfloat(params[scalar_offset_3 / 4][scalar_offset_3 % 4]))) + (colVel * asfloat(params[scalar_offset_4 / 4][scalar_offset_4 % 4]))) + (cVel * asfloat(params[scalar_offset_5 / 4][scalar_offset_5 % 4]))); |
Ben Clayton | ada560b | 2021-05-20 21:31:37 +0000 | [diff] [blame] | 98 | vVel = (normalize(vVel) * clamp(length(vVel), 0.0f, 0.100000001f)); |
Ben Clayton | 165512c | 2021-06-18 21:15:25 +0000 | [diff] [blame^] | 99 | const int scalar_offset_6 = (0u) / 4; |
| 100 | vPos = (vPos + (vVel * asfloat(params[scalar_offset_6 / 4][scalar_offset_6 % 4]))); |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 101 | if ((vPos.x < -1.0f)) { |
| 102 | vPos.x = 1.0f; |
| 103 | } |
| 104 | if ((vPos.x > 1.0f)) { |
| 105 | vPos.x = -1.0f; |
| 106 | } |
| 107 | if ((vPos.y < -1.0f)) { |
| 108 | vPos.y = 1.0f; |
| 109 | } |
| 110 | if ((vPos.y > 1.0f)) { |
| 111 | vPos.y = -1.0f; |
| 112 | } |
| 113 | particlesB.Store2((16u * index), asuint(vPos)); |
| 114 | particlesB.Store2(((16u * index) + 8u), asuint(vVel)); |
| 115 | return; |
| 116 | } |