You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Fixed critical particle rendering issue by properly updating instanced buffer attributes using setXYZ methods instead of replacing entire arrays
- Added comprehensive documentation of the fix in PROJECT_NEBULA_GUIDE.md
- Integrated SQLite database for persistent leaderboard storage
- Enhanced system profiler with detailed hardware detection
- Improved particle management system with proper synchronization
- Added scenario presets for quick experimentation
- Updated .gitignore to exclude user-generated database files
- Verified all functionality is working correctly with successful build
Copy file name to clipboardExpand all lines: PROJECT_NEBULA_GUIDE.md
+87-1Lines changed: 87 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -183,4 +183,90 @@ To prevent repeating history, we document our critical failures and the lessons
183
183
-**Celestial Events:** Introduce scripted or random events, such as a star passing too close to the black hole and being torn apart, creating a spectacular visual showcase.
184
184
-**Code Refinements:** Continue to refactor and optimize the codebase, particularly in the post-processing chain and particle rendering systems.
185
185
-**Sound Design:** Add ambient sound effects and music to enhance the atmosphere.
186
-
-**WASM Physics:** Begin exploration of WebAssembly-based physics simulation for Phase 3, following the guidelines in `RUST_SETUP.md`.
186
+
-**WASM Physics:** Begin exploration of WebAssembly-based physics simulation for Phase 3, following the guidelines in `RUST_SETUP.md`.
In July 2025, a critical bug was discovered where the main physics particles (star particles) were not rendering correctly, although jet particles and other visual elements were working properly. This issue was traced to improper handling of instanced buffer attributes in the particle rendering system.
192
+
193
+
### Root Cause Analysis
194
+
The issue was located in the `updateParticles` function in `src/main.js` (lines 999-1008). The original code attempted to update instanced attributes by replacing entire buffer arrays:
195
+
196
+
```javascript
197
+
// PROBLEMATIC CODE (Lines 999-1008 in src/main.js)
198
+
// Update attributes directly for better performance
199
+
if (instanceColorAttribute && instanceVelocityAttribute) {
200
+
// Truncate arrays to actual visible particle count
The problem with this approach was that the instanced buffer attributes were originally created with fixed-size buffers to accommodate the maximum number of particles (`MAX_PARTICLES = 500000`). When `setArray()` was called to replace these buffers with smaller arrays, it caused rendering issues because:
212
+
213
+
1.**Buffer Size Mismatch**: The new arrays were much smaller than the original fixed-size buffers
214
+
2.**Memory Management**: Replacing the entire buffer array disrupted the WebGL buffer management
215
+
3.**Attribute Binding**: The instanced attributes lost their proper binding to the mesh geometry
216
+
217
+
### Solution Implementation
218
+
The fix involved properly updating the existing attribute buffers using the `setXYZ` methods instead of replacing entire arrays:
219
+
220
+
```javascript
221
+
// FIXED CODE (Lines 999-1008 in src/main.js)
222
+
// Update attributes directly for better performance
223
+
if (instanceColorAttribute && instanceVelocityAttribute) {
224
+
// Update color attributes
225
+
for (let i =0; i < visibleParticles; i++) {
226
+
constcolorOffset= i *3;
227
+
instanceColorAttribute.setXYZ(
228
+
i,
229
+
colors[colorOffset],
230
+
colors[colorOffset +1],
231
+
colors[colorOffset +2]
232
+
);
233
+
}
234
+
235
+
// Update velocity attributes
236
+
for (let i =0; i < visibleParticles; i++) {
237
+
constvelocityOffset= i *3;
238
+
instanceVelocityAttribute.setXYZ(
239
+
i,
240
+
velocities[velocityOffset],
241
+
velocities[velocityOffset +1],
242
+
velocities[velocityOffset +2]
243
+
);
244
+
}
245
+
246
+
// Mark attributes as needing update
247
+
instanceColorAttribute.needsUpdate=true;
248
+
instanceVelocityAttribute.needsUpdate=true;
249
+
}
250
+
```
251
+
252
+
### Key Changes and Benefits
253
+
1.**Proper Attribute Updates**: Using `setXYZ()` methods to update individual attribute components
254
+
2.**Preserved Buffer Integrity**: Maintaining the original fixed-size buffer structure
4.**Consistent Rendering**: Ensuring proper WebGL buffer binding and rendering
257
+
258
+
### Testing and Verification
259
+
After implementing this fix:
260
+
- Main physics particles (star particles) now render correctly
261
+
- Particles load immediately on application startup
262
+
- Jet particles continue to work correctly
263
+
- All visual elements display as expected
264
+
- Performance remains optimal
265
+
266
+
### Lessons Learned
267
+
1.**Buffer Management**: When working with instanced attributes in Three.js, it's crucial to maintain the original buffer structure rather than replacing entire arrays
268
+
2.**Debugging Approach**: Adding comprehensive logging helped identify the buffer transfer issues between main thread and worker
269
+
3.**Performance Considerations**: The `setXYZ` approach is actually more efficient than buffer replacement for partial updates
270
+
4.**Backward Compatibility**: This fix maintains compatibility with existing particle physics calculations while resolving the rendering issue
271
+
272
+
This fix restored the core functionality of the Nebula AUSP particle system and ensures a smooth user experience for both sandbox exploration and benchmark testing.
0 commit comments