blob: 0ac0dbe47978fb674658faec869c3b32be4e005c [file] [log] [blame]
Ben Claytond1232672021-05-18 09:24:18 +00001struct tint_symbol_1 {
2 float2 a_particlePos : TEXCOORD0;
3 float2 a_particleVel : TEXCOORD1;
4 float2 a_pos : TEXCOORD2;
5};
6struct tint_symbol_2 {
7 float4 value : SV_Position;
8};
Ben Claytond1232672021-05-18 09:24:18 +00009
James Pricea5d73ce2021-08-04 22:15:28 +000010float4 vert_main_inner(float2 a_particlePos, float2 a_particleVel, float2 a_pos) {
Ben Claytonada560b2021-05-20 21:31:37 +000011 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 Pricea5d73ce2021-08-04 22:15:28 +000013 return float4((pos + a_particlePos), 0.0f, 1.0f);
14}
15
16tint_symbol_2 vert_main(tint_symbol_1 tint_symbol) {
Antonio Maiorano144ebed2024-01-30 16:30:15 +000017 float4 inner_result = vert_main_inner(tint_symbol.a_particlePos, tint_symbol.a_particleVel, tint_symbol.a_pos);
James Pricea5d73ce2021-08-04 22:15:28 +000018 tint_symbol_2 wrapper_result = (tint_symbol_2)0;
19 wrapper_result.value = inner_result;
20 return wrapper_result;
Ben Claytond1232672021-05-18 09:24:18 +000021}
22
Ben Clayton5d2f34e2021-06-16 09:19:36 +000023struct tint_symbol_3 {
24 float4 value : SV_Target0;
25};
26
James Pricea5d73ce2021-08-04 22:15:28 +000027float4 frag_main_inner() {
Ben Claytone9f8b092022-06-01 13:14:39 +000028 return (1.0f).xxxx;
James Pricea5d73ce2021-08-04 22:15:28 +000029}
30
Ben Claytond1232672021-05-18 09:24:18 +000031tint_symbol_3 frag_main() {
Antonio Maiorano144ebed2024-01-30 16:30:15 +000032 float4 inner_result_1 = frag_main_inner();
James Pricea5d73ce2021-08-04 22:15:28 +000033 tint_symbol_3 wrapper_result_1 = (tint_symbol_3)0;
34 wrapper_result_1.value = inner_result_1;
35 return wrapper_result_1;
Ben Claytond1232672021-05-18 09:24:18 +000036}
37
Peng Huangc00ff7f2023-03-31 17:55:19 +000038cbuffer cbuffer_params : register(b0) {
Ben Clayton165512c2021-06-18 21:15:25 +000039 uint4 params[2];
Ben Clayton5d2f34e2021-06-16 09:19:36 +000040};
Peng Huangc00ff7f2023-03-31 17:55:19 +000041RWByteAddressBuffer particlesA : register(u1);
42RWByteAddressBuffer particlesB : register(u2);
Ben Clayton5d2f34e2021-06-16 09:19:36 +000043
44struct tint_symbol_5 {
45 uint3 gl_GlobalInvocationID : SV_DispatchThreadID;
46};
47
James Pricea5d73ce2021-08-04 22:15:28 +000048void comp_main_inner(uint3 gl_GlobalInvocationID) {
Ben Claytond1232672021-05-18 09:24:18 +000049 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 Claytone9f8b092022-06-01 13:14:39 +000055 float2 cMass = (0.0f).xx;
56 float2 cVel = (0.0f).xx;
57 float2 colVel = (0.0f).xx;
Ben Claytond1232672021-05-18 09:24:18 +000058 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 Maiorano06844a52022-09-29 16:53:58 +000063 for(uint i = 0u; (i < 5u); i = (i + 1u)) {
Ben Claytonada560b2021-05-20 21:31:37 +000064 if ((i == index)) {
Ben Claytonada560b2021-05-20 21:31:37 +000065 continue;
66 }
67 pos = asfloat(particlesA.Load2((16u * i))).xy;
68 vel = asfloat(particlesA.Load2(((16u * i) + 8u))).xy;
Ben Clayton51cfe262021-07-13 12:18:13 +000069 if ((distance(pos, vPos) < asfloat(params[0].y))) {
Ben Claytonada560b2021-05-20 21:31:37 +000070 cMass = (cMass + pos);
71 cMassCount = (cMassCount + 1);
72 }
Ben Clayton51cfe262021-07-13 12:18:13 +000073 if ((distance(pos, vPos) < asfloat(params[0].z))) {
Ben Claytonada560b2021-05-20 21:31:37 +000074 colVel = (colVel - (pos - vPos));
75 }
Ben Clayton51cfe262021-07-13 12:18:13 +000076 if ((distance(pos, vPos) < asfloat(params[0].w))) {
Ben Claytonada560b2021-05-20 21:31:37 +000077 cVel = (cVel + vel);
78 cVelCount = (cVelCount + 1);
79 }
Ben Claytond1232672021-05-18 09:24:18 +000080 }
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 Clayton51cfe262021-07-13 12:18:13 +000088 vVel = (((vVel + (cMass * asfloat(params[1].x))) + (colVel * asfloat(params[1].y))) + (cVel * asfloat(params[1].z)));
dan sinclair6cc183c2023-03-02 21:28:45 +000089 vVel = (normalize(vVel) * clamp(length(vVel), 0.0f, 0.10000000149011611938f));
Ben Clayton51cfe262021-07-13 12:18:13 +000090 vPos = (vPos + (vVel * asfloat(params[0].x)));
Ben Claytond1232672021-05-18 09:24:18 +000091 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 Pricea5d73ce2021-08-04 22:15:28 +0000105}
106
107[numthreads(1, 1, 1)]
108void comp_main(tint_symbol_5 tint_symbol_4) {
109 comp_main_inner(tint_symbol_4.gl_GlobalInvocationID);
Ben Claytond1232672021-05-18 09:24:18 +0000110 return;
111}