@@ -42,15 +42,11 @@ describe('gravity example', () => {
4242
4343 @group(0) @binding(0) var<uniform> celestialBodiesCount_3: i32;
4444
45- fn radiusOf_4(body: ptr<function, CelestialBody_2> ) -> f32 {
46- return (pow((((* body) .mass * 0.75f) / 3.141592653589793f), 0.333f) * (* body) .radiusMultiplier);
45+ fn radiusOf_4(body: CelestialBody_2) -> f32 {
46+ return (pow(((body.mass * 0.75f) / 3.141592653589793f), 0.333f) * body.radiusMultiplier);
4747 }
4848
49- fn radiusOf_5(body: ptr<storage, ptr<function, CelestialBody_2>, read>) -> f32 {
50- return (pow((((*(*body)).mass * 0.75f) / 3.141592653589793f), 0.333f) * (*(*body)).radiusMultiplier);
51- }
52-
53- fn isSmaller_6(currentId: u32, otherId: u32) -> bool {
49+ fn isSmaller_5(currentId: u32, otherId: u32) -> bool {
5450 let current = (&inState_1[currentId]);
5551 let other = (&inState_1[otherId]);
5652 if (((*current).mass < (*other).mass)) {
@@ -62,33 +58,33 @@ describe('gravity example', () => {
6258 return false;
6359 }
6460
65- @group(0) @binding(2) var<storage, read_write> outState_7 : array<CelestialBody_2>;
61+ @group(0) @binding(2) var<storage, read_write> outState_6 : array<CelestialBody_2>;
6662
67- struct computeCollisionsShader_Input_8 {
63+ struct computeCollisionsShader_Input_7 {
6864 @builtin(global_invocation_id) gid: vec3u,
6965 }
7066
71- @compute @workgroup_size(1) fn computeCollisionsShader_0(input: computeCollisionsShader_Input_8 ) {
67+ @compute @workgroup_size(1) fn computeCollisionsShader_0(input: computeCollisionsShader_Input_7 ) {
7268 let currentId = input.gid.x;
7369 var current = inState_1[currentId];
7470 if ((current.destroyed == 0u)) {
7571 for (var otherId = 0u; (otherId < u32(celestialBodiesCount_3)); otherId++) {
7672 let other = (&inState_1[otherId]);
77- if ((((((otherId == currentId) || ((*other).destroyed == 1u)) || (current.collisionBehavior == 0u)) || ((*other).collisionBehavior == 0u)) || (distance(current.position, (*other).position) >= (radiusOf_4((& current)) + radiusOf_5((& other)))))) {
73+ if ((((((otherId == currentId) || ((*other).destroyed == 1u)) || (current.collisionBehavior == 0u)) || ((*other).collisionBehavior == 0u)) || (distance(current.position, (*other).position) >= (radiusOf_4(current) + radiusOf_4((* other)))))) {
7874 continue;
7975 }
8076 if (((current.collisionBehavior == 1u) && ((*other).collisionBehavior == 1u))) {
81- if (isSmaller_6 (currentId, otherId)) {
77+ if (isSmaller_5 (currentId, otherId)) {
8278 var dir = normalize((current.position - (*other).position));
83- current.position = ((*other).position + (dir * (radiusOf_4((& current)) + radiusOf_5((& other)))));
79+ current.position = ((*other).position + (dir * (radiusOf_4(current) + radiusOf_4((* other)))));
8480 }
8581 var posDiff = (current.position - (*other).position);
8682 var velDiff = (current.velocity - (*other).velocity);
8783 let posDiffFactor = ((((2f * (*other).mass) / (current.mass + (*other).mass)) * dot(velDiff, posDiff)) / dot(posDiff, posDiff));
8884 current.velocity = ((current.velocity - (posDiff * posDiffFactor)) * 0.99);
8985 }
9086 else {
91- let isCurrentAbsorbed = ((current.collisionBehavior == 1u) || ((current.collisionBehavior == 2u) && isSmaller_6 (currentId, otherId)));
87+ let isCurrentAbsorbed = ((current.collisionBehavior == 1u) || ((current.collisionBehavior == 2u) && isSmaller_5 (currentId, otherId)));
9288 if (isCurrentAbsorbed) {
9389 current.destroyed = 1u;
9490 }
@@ -101,7 +97,7 @@ describe('gravity example', () => {
10197 }
10298 }
10399 }
104- outState_7 [currentId] = current;
100+ outState_6 [currentId] = current;
105101 }
106102
107103 struct Time_2 {
@@ -126,21 +122,17 @@ describe('gravity example', () => {
126122
127123 @group(1) @binding(0) var<uniform> celestialBodiesCount_5: i32;
128124
129- fn radiusOf_6(body: ptr<function, CelestialBody_4> ) -> f32 {
130- return (pow((((* body) .mass * 0.75f) / 3.141592653589793f), 0.333f) * (* body) .radiusMultiplier);
125+ fn radiusOf_6(body: CelestialBody_4) -> f32 {
126+ return (pow(((body.mass * 0.75f) / 3.141592653589793f), 0.333f) * body.radiusMultiplier);
131127 }
132128
133- fn radiusOf_7(body: ptr<storage, ptr<function, CelestialBody_4>, read>) -> f32 {
134- return (pow((((*(*body)).mass * 0.75f) / 3.141592653589793f), 0.333f) * (*(*body)).radiusMultiplier);
135- }
136-
137- @group(1) @binding(2) var<storage, read_write> outState_8: array<CelestialBody_4>;
129+ @group(1) @binding(2) var<storage, read_write> outState_7: array<CelestialBody_4>;
138130
139- struct computeGravityShader_Input_9 {
131+ struct computeGravityShader_Input_8 {
140132 @builtin(global_invocation_id) gid: vec3u,
141133 }
142134
143- @compute @workgroup_size(1) fn computeGravityShader_0(input: computeGravityShader_Input_9 ) {
135+ @compute @workgroup_size(1) fn computeGravityShader_0(input: computeGravityShader_Input_8 ) {
144136 let dt = (time_1.passed * time_1.multiplier);
145137 let currentId = input.gid.x;
146138 var current = inState_3[currentId];
@@ -150,14 +142,14 @@ describe('gravity example', () => {
150142 if (((otherId == currentId) || ((*other).destroyed == 1u))) {
151143 continue;
152144 }
153- let dist = max((radiusOf_6((& current)) + radiusOf_7((& other))), distance(current.position, (*other).position));
145+ let dist = max((radiusOf_6(current) + radiusOf_6((* other))), distance(current.position, (*other).position));
154146 let gravityForce = (((current.mass * (*other).mass) / dist) / dist);
155147 var direction = normalize(((*other).position - current.position));
156148 current.velocity = (current.velocity + (direction * ((gravityForce / current.mass) * dt)));
157149 }
158150 current.position = (current.position + (current.velocity * dt));
159151 }
160- outState_8 [currentId] = current;
152+ outState_7 [currentId] = current;
161153 }
162154
163155 struct Camera_2 {
@@ -209,8 +201,8 @@ describe('gravity example', () => {
209201
210202 @group(1) @binding(1) var<storage, read> celestialBodies_1: array<CelestialBody_2>;
211203
212- fn radiusOf_3(body: ptr<storage, ptr<function, CelestialBody_2>, read> ) -> f32 {
213- return (pow((((*(* body)) .mass * 0.75f) / 3.141592653589793f), 0.333f) * (*(* body)) .radiusMultiplier);
204+ fn radiusOf_3(body: CelestialBody_2) -> f32 {
205+ return (pow(((body.mass * 0.75f) / 3.141592653589793f), 0.333f) * body.radiusMultiplier);
214206 }
215207
216208 struct Camera_5 {
@@ -241,7 +233,7 @@ describe('gravity example', () => {
241233
242234 @vertex fn mainVertex_0(input: mainVertex_Input_7) -> mainVertex_Output_6 {
243235 let currentBody = (&celestialBodies_1[input.instanceIndex]);
244- var worldPosition = ((*currentBody).position + (input.position.xyz * radiusOf_3((& currentBody))));
236+ var worldPosition = ((*currentBody).position + (input.position.xyz * radiusOf_3((* currentBody))));
245237 let camera = (&camera_4);
246238 var positionOnCanvas = (((*camera).projection * (*camera).view) * vec4f(worldPosition, 1f));
247239 return mainVertex_Output_6(positionOnCanvas, input.uv, input.normal, worldPosition, (*currentBody).textureIndex, (*currentBody).destroyed, (*currentBody).ambientLightFactor);
0 commit comments