Skip to content

feat(particle): add NoiseModule for simplex noise turbulence#2953

Open
hhhhkrx wants to merge 1 commit intogalacean:dev/2.0from
hhhhkrx:feat/noise
Open

feat(particle): add NoiseModule for simplex noise turbulence#2953
hhhhkrx wants to merge 1 commit intogalacean:dev/2.0from
hhhhkrx:feat/noise

Conversation

@hhhhkrx
Copy link
Copy Markdown
Contributor

@hhhhkrx hhhhkrx commented Apr 3, 2026

Summary

  • Add NoiseModule to the particle system, referencing Unity's Noise Module
  • GPU-computed simplex noise displacement using existing noise_common + noise_simplex_3D shader libraries
  • Supports per-axis strength, frequency, scroll speed, damping, and up to 3 octaves
  • No instance buffer changes needed — purely uniform-driven
  • Noise bounds expansion applied in world space (after rotation transform) to ensure correct culling with rotated emitters

Usage

const generator = particleRenderer.generator;
generator.noise.enabled = true;
generator.noise.strengthX = 2.0;
generator.noise.frequency = 1.0;
generator.noise.scrollSpeed = 0.5;
generator.noise.octaves = 2;

Test plan

  • npm run build passes
  • Enable noise on a particle system, verify turbulence displacement
  • Adjust frequency, strength, scrollSpeed parameters and confirm visual changes
  • Enable octaves = 3, verify increased detail
  • Toggle damping off, confirm equal-amplitude noise across full lifetime
  • Test with rotated emitter to verify bounds correctness
  • Test with StretchedBillboard mode (known limitation: stretch direction does not account for noise velocity, consistent with Unity)

Summary by CodeRabbit

  • New Features
    • Added configurable noise effects to particle systems (strength, frequency, scroll speed, damping, octaves) for richer animations.
    • Particle shaders updated to support noise-driven behavior for lifetime effects.
  • Bug Fixes
    • Improved world-space bounds calculation so noisy particle motion is correctly accounted for in rendering and culling.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e6ef00bf-dddf-49d5-8b0f-18eb011cc673

📥 Commits

Reviewing files that changed from the base of the PR and between dcdfec0 and 64f726c.

⛔ Files ignored due to path filters (2)
  • packages/core/src/shaderlib/extra/particle.vs.glsl is excluded by !**/*.glsl
  • packages/core/src/shaderlib/particle/noise_over_lifetime_module.glsl is excluded by !**/*.glsl
📒 Files selected for processing (4)
  • packages/core/src/particle/ParticleGenerator.ts
  • packages/core/src/particle/index.ts
  • packages/core/src/particle/modules/NoiseModule.ts
  • packages/core/src/shaderlib/particle/index.ts
✅ Files skipped from review due to trivial changes (2)
  • packages/core/src/particle/index.ts
  • packages/core/src/shaderlib/particle/index.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/core/src/particle/ParticleGenerator.ts
  • packages/core/src/particle/modules/NoiseModule.ts

Walkthrough

Added a new NoiseModule for particle noise control, integrated it into ParticleGenerator (property, shader updates, bounds expansion), exported the module from the particle package, and registered a new GLSL noise module in the particle shader library.

Changes

Cohort / File(s) Summary
Noise Module Implementation
packages/core/src/particle/modules/NoiseModule.ts
New exported NoiseModule class extending ParticleGeneratorModule with public getters/setters for strengthX/Y/Z, frequency, scrollSpeed, damping, octaves (clamped 1–3), octaveMultiplier, octaveScale; updates renderer on changes and writes noise uniforms/macros in _updateShaderData.
ParticleGenerator Integration
packages/core/src/particle/ParticleGenerator.ts
Added @deepClone readonly noise: NoiseModule property; call to this.noise._updateShaderData(shaderData) in _updateShaderData; expanded _calculateTransformedBounds to include axis-aligned margin based on noise.enabled, strengthX/Y/Z and octave-derived maxAmplitude.
Exports and Shader Index
packages/core/src/particle/index.ts, packages/core/src/shaderlib/particle/index.ts
Exported NoiseModule from package particle index; added noise_over_lifetime_module GLSL import/property to particle shader library index.

Sequence Diagram

sequenceDiagram
    participant PG as ParticleGenerator
    participant NM as NoiseModule
    participant Renderer as Renderer
    participant ShaderData as ShaderData
    participant Shader as Shader

    PG->>NM: construct NoiseModule(this)
    PG->>NM: set properties (strength, freq, scroll, octaves, damping)
    NM->>Renderer: _onGeneratorParamsChanged()
    PG->>ShaderData: _updateShaderData(shaderData)
    PG->>NM: NM._updateShaderData(shaderData)
    alt Noise enabled
        NM->>ShaderData: write strengthVec, freq, scroll, octaveVec
        NM->>Shader: _enableMacro("NOISE_ENABLED", true)
        alt damping enabled
            NM->>Shader: _enableMacro("NOISE_DAMPING", true)
        else damping disabled
            NM->>Shader: _enableMacro("NOISE_DAMPING", false)
        end
    else Noise disabled
        NM->>Shader: _enableMacro("NOISE_ENABLED", false)
    end
    PG->>PG: _calculateTransformedBounds()
    PG->>PG: expand bounds by noise axis-aligned margin (maxAmplitude * strength)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I jitter and hum in a powdered noise bloom,
Pushing particles gently out from the gloom,
Octaves and strength weave a soft, sparking trance,
Damping and scroll send the chaos to dance,
Hooray — more motion, more magical prance! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(particle): add NoiseModule for simplex noise turbulence' accurately describes the main change: adding a NoiseModule to the particle system for simplex noise effects.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@hhhhkrx hhhhkrx requested a review from GuoLei1990 April 3, 2026 06:19
@hhhhkrx hhhhkrx self-assigned this Apr 3, 2026
Add GPU-computed simplex noise displacement to particles, referencing
Unity's Noise Module. Supports per-axis strength, frequency, scroll
speed, damping, and up to 3 octaves. Reuses existing noise_common and
noise_simplex_3D shader libraries. No instance buffer changes needed.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

❌ Patch coverage is 63.40426% with 86 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.70%. Comparing base (6c82a45) to head (64f726c).

Files with missing lines Patch % Lines
packages/core/src/particle/modules/NoiseModule.ts 59.24% 86 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           dev/2.0    #2953      +/-   ##
===========================================
- Coverage    77.73%   77.70%   -0.04%     
===========================================
  Files          898      899       +1     
  Lines        98310    98552     +242     
  Branches      9806     9806              
===========================================
+ Hits         76417    76575     +158     
- Misses       21728    21812      +84     
  Partials       165      165              
Flag Coverage Δ
unittests 77.70% <63.40%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/core/src/particle/modules/NoiseModule.ts`:
- Around line 146-150: The octaveMultiplier setter currently allows negative
values which can invert bounds; update set octaveMultiplier(value: number) to
validate and reject or clamp values to a safe non-negative range (e.g., clamp to
>= 0.0 or a chosen min like 0.0/1.0), only assign to this._octaveMultiplier and
call this._generator._renderer._onGeneratorParamsChanged() when the
validated/clamped value differs from the current value; ensure any invalid
inputs are normalized (or throw a clear error) so downstream bounds calculations
in ParticleGenerator no longer receive negative multipliers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bd9486dd-e2cd-4d0b-91a3-d78d7fd9eb2b

📥 Commits

Reviewing files that changed from the base of the PR and between 6c82a45 and dcdfec0.

⛔ Files ignored due to path filters (2)
  • packages/core/src/shaderlib/extra/particle.vs.glsl is excluded by !**/*.glsl
  • packages/core/src/shaderlib/particle/noise_over_lifetime_module.glsl is excluded by !**/*.glsl
📒 Files selected for processing (4)
  • packages/core/src/particle/ParticleGenerator.ts
  • packages/core/src/particle/index.ts
  • packages/core/src/particle/modules/NoiseModule.ts
  • packages/core/src/shaderlib/particle/index.ts

Comment on lines +146 to +150
set octaveMultiplier(value: number) {
if (value !== this._octaveMultiplier) {
this._octaveMultiplier = value;
this._generator._renderer._onGeneratorParamsChanged();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Validate octaveMultiplier to avoid invalid bounds shrinkage.

Line 146 currently accepts negative values. That propagates into transformed-bounds expansion (packages/core/src/particle/ParticleGenerator.ts, Line 1397 onward) where signed amplitude accumulation can under-estimate or invert expected expansion, causing culling artifacts.

Proposed fix
   set octaveMultiplier(value: number) {
-    if (value !== this._octaveMultiplier) {
-      this._octaveMultiplier = value;
+    const nextValue = Number.isFinite(value) ? Math.max(0, value) : 0;
+    if (nextValue !== this._octaveMultiplier) {
+      this._octaveMultiplier = nextValue;
       this._generator._renderer._onGeneratorParamsChanged();
     }
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
set octaveMultiplier(value: number) {
if (value !== this._octaveMultiplier) {
this._octaveMultiplier = value;
this._generator._renderer._onGeneratorParamsChanged();
}
set octaveMultiplier(value: number) {
const nextValue = Number.isFinite(value) ? Math.max(0, value) : 0;
if (nextValue !== this._octaveMultiplier) {
this._octaveMultiplier = nextValue;
this._generator._renderer._onGeneratorParamsChanged();
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/particle/modules/NoiseModule.ts` around lines 146 - 150,
The octaveMultiplier setter currently allows negative values which can invert
bounds; update set octaveMultiplier(value: number) to validate and reject or
clamp values to a safe non-negative range (e.g., clamp to >= 0.0 or a chosen min
like 0.0/1.0), only assign to this._octaveMultiplier and call
this._generator._renderer._onGeneratorParamsChanged() when the validated/clamped
value differs from the current value; ensure any invalid inputs are normalized
(or throw a clear error) so downstream bounds calculations in ParticleGenerator
no longer receive negative multipliers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant