Skip to content

Commit 84cf412

Browse files
committed
Milestone: Particle Rendering Fix & Database Integration
- 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
1 parent e4f2090 commit 84cf412

File tree

15 files changed

+3589
-350
lines changed

15 files changed

+3589
-350
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ dist-ssr
2525

2626
# User-generated data
2727
leaderboard-data.json
28+
leaderboard.db

PROJECT_NEBULA_GUIDE.md

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,90 @@ To prevent repeating history, we document our critical failures and the lessons
183183
- **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.
184184
- **Code Refinements:** Continue to refactor and optimize the codebase, particularly in the post-processing chain and particle rendering systems.
185185
- **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`.
187+
188+
## Critical Bug Fix: Particle Rendering Issue (July 2025)
189+
190+
### Problem Description
191+
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
201+
const visibleColors = new Float32Array(colors.buffer, 0, visibleParticles * 3);
202+
const visibleVelocities = new Float32Array(velocities.buffer, 0, visibleParticles * 3);
203+
204+
instanceColorAttribute.setArray(visibleColors);
205+
instanceVelocityAttribute.setArray(visibleVelocities);
206+
instanceColorAttribute.needsUpdate = true;
207+
instanceVelocityAttribute.needsUpdate = true;
208+
}
209+
```
210+
211+
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+
const colorOffset = 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+
const velocityOffset = 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
255+
3. **Efficient Memory Usage**: Avoiding unnecessary buffer reallocation
256+
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.

index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ <h2>Benchmark Complete!</h2>
2727
<p>Here is your final score and a summary of your system's performance.</p>
2828
<div id="modal-score-summary"></div>
2929
<div id="modal-system-summary"></div>
30+
<div id="modal-name-input">
31+
<label for="submitter-name">Your Name:</label>
32+
<input type="text" id="submitter-name" placeholder="Enter your name" maxlength="50">
33+
</div>
34+
<div id="modal-message" class="modal-message hidden"></div>
3035
<div id="submission-buttons">
3136
<button id="modal-cancel-btn">Cancel</button>
3237
<button id="modal-submit-btn">Submit to Leaderboard</button>

0 commit comments

Comments
 (0)