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 | |
James Price | a5d73ce | 2021-08-04 22:15:28 +0000 | [diff] [blame] | 10 | float4 vert_main_inner(float2 a_particlePos, float2 a_particleVel, float2 a_pos) { |
Ben Clayton | ada560b | 2021-05-20 21:31:37 +0000 | [diff] [blame] | 11 | float angle = -(atan2(a_particleVel.x, a_particleVel.y)); |
| 12 | float2 pos = float2(((a_pos.x * cos(angle)) - (a_pos.y * sin(angle))), ((a_pos.x * sin(angle)) + (a_pos.y * cos(angle)))); |
James Price | a5d73ce | 2021-08-04 22:15:28 +0000 | [diff] [blame] | 13 | return float4((pos + a_particlePos), 0.0f, 1.0f); |
| 14 | } |
| 15 | |
| 16 | tint_symbol_2 vert_main(tint_symbol_1 tint_symbol) { |
Antonio Maiorano | 144ebed | 2024-01-30 16:30:15 +0000 | [diff] [blame] | 17 | float4 inner_result = vert_main_inner(tint_symbol.a_particlePos, tint_symbol.a_particleVel, tint_symbol.a_pos); |
James Price | a5d73ce | 2021-08-04 22:15:28 +0000 | [diff] [blame] | 18 | tint_symbol_2 wrapper_result = (tint_symbol_2)0; |
| 19 | wrapper_result.value = inner_result; |
| 20 | return wrapper_result; |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 21 | } |
| 22 | |
Ben Clayton | 5d2f34e | 2021-06-16 09:19:36 +0000 | [diff] [blame] | 23 | struct tint_symbol_3 { |
| 24 | float4 value : SV_Target0; |
| 25 | }; |
| 26 | |
James Price | a5d73ce | 2021-08-04 22:15:28 +0000 | [diff] [blame] | 27 | float4 frag_main_inner() { |
Ben Clayton | e9f8b09 | 2022-06-01 13:14:39 +0000 | [diff] [blame] | 28 | return (1.0f).xxxx; |
James Price | a5d73ce | 2021-08-04 22:15:28 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 31 | tint_symbol_3 frag_main() { |
Antonio Maiorano | 144ebed | 2024-01-30 16:30:15 +0000 | [diff] [blame] | 32 | float4 inner_result_1 = frag_main_inner(); |
James Price | a5d73ce | 2021-08-04 22:15:28 +0000 | [diff] [blame] | 33 | tint_symbol_3 wrapper_result_1 = (tint_symbol_3)0; |
| 34 | wrapper_result_1.value = inner_result_1; |
| 35 | return wrapper_result_1; |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Peng Huang | c00ff7f | 2023-03-31 17:55:19 +0000 | [diff] [blame] | 38 | cbuffer cbuffer_params : register(b0) { |
Ben Clayton | 165512c | 2021-06-18 21:15:25 +0000 | [diff] [blame] | 39 | uint4 params[2]; |
Ben Clayton | 5d2f34e | 2021-06-16 09:19:36 +0000 | [diff] [blame] | 40 | }; |
Peng Huang | c00ff7f | 2023-03-31 17:55:19 +0000 | [diff] [blame] | 41 | RWByteAddressBuffer particlesA : register(u1); |
| 42 | RWByteAddressBuffer particlesB : register(u2); |
Ben Clayton | 5d2f34e | 2021-06-16 09:19:36 +0000 | [diff] [blame] | 43 | |
| 44 | struct tint_symbol_5 { |
| 45 | uint3 gl_GlobalInvocationID : SV_DispatchThreadID; |
| 46 | }; |
| 47 | |
James Price | a5d73ce | 2021-08-04 22:15:28 +0000 | [diff] [blame] | 48 | void comp_main_inner(uint3 gl_GlobalInvocationID) { |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 49 | uint index = gl_GlobalInvocationID.x; |
| 50 | if ((index >= 5u)) { |
| 51 | return; |
| 52 | } |
| 53 | float2 vPos = asfloat(particlesA.Load2((16u * index))); |
| 54 | float2 vVel = asfloat(particlesA.Load2(((16u * index) + 8u))); |
Ben Clayton | e9f8b09 | 2022-06-01 13:14:39 +0000 | [diff] [blame] | 55 | float2 cMass = (0.0f).xx; |
| 56 | float2 cVel = (0.0f).xx; |
| 57 | float2 colVel = (0.0f).xx; |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 58 | int cMassCount = 0; |
| 59 | int cVelCount = 0; |
| 60 | float2 pos = float2(0.0f, 0.0f); |
| 61 | float2 vel = float2(0.0f, 0.0f); |
| 62 | { |
Antonio Maiorano | 06844a5 | 2022-09-29 16:53:58 +0000 | [diff] [blame] | 63 | for(uint i = 0u; (i < 5u); i = (i + 1u)) { |
Ben Clayton | ada560b | 2021-05-20 21:31:37 +0000 | [diff] [blame] | 64 | if ((i == index)) { |
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 | 51cfe26 | 2021-07-13 12:18:13 +0000 | [diff] [blame] | 69 | if ((distance(pos, vPos) < asfloat(params[0].y))) { |
Ben Clayton | ada560b | 2021-05-20 21:31:37 +0000 | [diff] [blame] | 70 | cMass = (cMass + pos); |
| 71 | cMassCount = (cMassCount + 1); |
| 72 | } |
Ben Clayton | 51cfe26 | 2021-07-13 12:18:13 +0000 | [diff] [blame] | 73 | if ((distance(pos, vPos) < asfloat(params[0].z))) { |
Ben Clayton | ada560b | 2021-05-20 21:31:37 +0000 | [diff] [blame] | 74 | colVel = (colVel - (pos - vPos)); |
| 75 | } |
Ben Clayton | 51cfe26 | 2021-07-13 12:18:13 +0000 | [diff] [blame] | 76 | if ((distance(pos, vPos) < asfloat(params[0].w))) { |
Ben Clayton | ada560b | 2021-05-20 21:31:37 +0000 | [diff] [blame] | 77 | cVel = (cVel + vel); |
| 78 | cVelCount = (cVelCount + 1); |
| 79 | } |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | if ((cMassCount > 0)) { |
| 83 | cMass = ((cMass / float2(float(cMassCount), float(cMassCount))) - vPos); |
| 84 | } |
| 85 | if ((cVelCount > 0)) { |
| 86 | cVel = (cVel / float2(float(cVelCount), float(cVelCount))); |
| 87 | } |
Ben Clayton | 51cfe26 | 2021-07-13 12:18:13 +0000 | [diff] [blame] | 88 | vVel = (((vVel + (cMass * asfloat(params[1].x))) + (colVel * asfloat(params[1].y))) + (cVel * asfloat(params[1].z))); |
dan sinclair | 6cc183c | 2023-03-02 21:28:45 +0000 | [diff] [blame] | 89 | vVel = (normalize(vVel) * clamp(length(vVel), 0.0f, 0.10000000149011611938f)); |
Ben Clayton | 51cfe26 | 2021-07-13 12:18:13 +0000 | [diff] [blame] | 90 | vPos = (vPos + (vVel * asfloat(params[0].x))); |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 91 | if ((vPos.x < -1.0f)) { |
| 92 | vPos.x = 1.0f; |
| 93 | } |
| 94 | if ((vPos.x > 1.0f)) { |
| 95 | vPos.x = -1.0f; |
| 96 | } |
| 97 | if ((vPos.y < -1.0f)) { |
| 98 | vPos.y = 1.0f; |
| 99 | } |
| 100 | if ((vPos.y > 1.0f)) { |
| 101 | vPos.y = -1.0f; |
| 102 | } |
| 103 | particlesB.Store2((16u * index), asuint(vPos)); |
| 104 | particlesB.Store2(((16u * index) + 8u), asuint(vVel)); |
James Price | a5d73ce | 2021-08-04 22:15:28 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | [numthreads(1, 1, 1)] |
| 108 | void comp_main(tint_symbol_5 tint_symbol_4) { |
| 109 | comp_main_inner(tint_symbol_4.gl_GlobalInvocationID); |
Ben Clayton | d123267 | 2021-05-18 09:24:18 +0000 | [diff] [blame] | 110 | return; |
| 111 | } |