Skip to content

Commit bacae73

Browse files
committed
fix calibration
1 parent c9178c5 commit bacae73

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

src/pages/particle-life-gpu/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,20 @@ async function start(
7979
const width = ctx.canvas.width
8080
const height = ctx.canvas.height
8181

82-
const repulsionRange = 20
83-
const attractionRange = 20
84-
const repulsionStrength = 20
85-
const attractionStrength = 10
82+
const repulsionRange = 25
83+
const attractionRange = 26
84+
const repulsionStrength = 30
85+
const attractionStrength = 30
8686

8787
const cellSize = repulsionRange + attractionRange
8888
const widthDivisions = Math.ceil(width / cellSize)
8989
const heightDivisions = Math.ceil(height / cellSize)
9090
const toBinX = widthDivisions / width
9191
const toBinY = heightDivisions / height
9292
const binCount = widthDivisions * heightDivisions
93-
// const particleCount = 180_000
93+
// const particleCount = 130_000
9494
const particleCount = 100_000
95+
// const particleCount = 20_000
9596

9697
const particlePositionBuffer = device.createBuffer({
9798
label: 'particle position storage buffer',
@@ -148,6 +149,7 @@ async function start(
148149
for (let i = 0; i < 6; i++) {
149150
for (let j = 0; j < 6; j++) {
150151
staticStorageArray[i * 6 + j] = Math.random() * 2 - 1
152+
// staticStorageArray[i * 6 + j] = i === j ? 1 : 0
151153
}
152154
}
153155
particleInteractionsBuffer.unmap()

src/pages/particle-life-gpu/update.wgsl

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ fn update(
4646

4747
let range = config.repulsionRange + config.attractionRange;
4848

49-
let min_bin_x = u32(floor((position.x - range) * config.binWidth));
50-
let min_bin_y = u32(floor((position.y - range) * config.binHeight));
51-
let max_bin_x = u32(floor((position.x + range) * config.binWidth));
52-
let max_bin_y = u32(floor((position.y + range) * config.binHeight));
49+
let min_bin_x = u32((position.x - range) * config.binWidth);
50+
let min_bin_y = u32((position.y - range) * config.binHeight);
51+
let max_bin_x = u32((position.x + range) * config.binWidth);
52+
let max_bin_y = u32((position.y + range) * config.binHeight);
5353

5454
let wd = config.widthDivisions;
5555
let hd = config.heightDivisions;
@@ -89,25 +89,18 @@ fn update(
8989
}
9090

9191
let dist = length(offset);
92-
if (dist > range) {
93-
continue;
94-
}
9592

96-
if (dist < 0.5) {
97-
// Collision (elastic bounce) (also avoids division by zero)
98-
let other_velocity = particleVelocities[other_index];
99-
velocity -= dot(velocity - other_velocity, offset / dist) * (offset / dist);
100-
} else if (dist < config.repulsionRange) {
93+
if (dist < config.repulsionRange) {
10194
// Repulsion
10295
let strength = (config.repulsionRange - dist) / config.repulsionRange * config.repulsionStrength * dt;
10396
velocity -= normalize(offset) * strength;
104-
} else {
97+
} else if (dist < range) {
10598
// Attraction
10699
let other_color = particleColors[other_index];
107100
let interaction_index = color * COLOR_COUNT + other_color;
108101
let interaction_strength = interactions[interaction_index];
109102
let normalized_distance = (config.attractionRange - (dist - config.repulsionRange)) / config.attractionRange;
110-
let symmetric_distance = abs(normalized_distance * 2.0 - 1.0);
103+
let symmetric_distance = 1.0 - abs(normalized_distance * 2.0 - 1.0);
111104
let strength = symmetric_distance * interaction_strength * config.attractionStrength * dt;
112105
velocity += normalize(offset) * strength;
113106
}
@@ -116,7 +109,7 @@ fn update(
116109
}
117110

118111
// dampen velocity
119-
velocity -= normalize(velocity) * 12 * dt;
112+
velocity -= velocity * 8 * dt;
120113

121114
// update position
122115
position += velocity * dt;

src/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export const ROUTES = {
236236
image: particle_life_gpu_image
237237
},
238238
git: {
239-
lastModified: 1762611209000,
239+
lastModified: 1762613219000,
240240
firstAdded: 1762551884000
241241
},
242242
},

0 commit comments

Comments
 (0)