feat(particle): add NoiseModule for simplex noise turbulence#2953
feat(particle): add NoiseModule for simplex noise turbulence#2953hhhhkrx wants to merge 1 commit intogalacean:dev/2.0from
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughAdded 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
Sequence DiagramsequenceDiagram
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)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (2)
packages/core/src/shaderlib/extra/particle.vs.glslis excluded by!**/*.glslpackages/core/src/shaderlib/particle/noise_over_lifetime_module.glslis excluded by!**/*.glsl
📒 Files selected for processing (4)
packages/core/src/particle/ParticleGenerator.tspackages/core/src/particle/index.tspackages/core/src/particle/modules/NoiseModule.tspackages/core/src/shaderlib/particle/index.ts
| set octaveMultiplier(value: number) { | ||
| if (value !== this._octaveMultiplier) { | ||
| this._octaveMultiplier = value; | ||
| this._generator._renderer._onGeneratorParamsChanged(); | ||
| } |
There was a problem hiding this comment.
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.
| 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.
Summary
NoiseModuleto the particle system, referencing Unity's Noise Modulenoise_common+noise_simplex_3Dshader librariesUsage
Test plan
npm run buildpassesSummary by CodeRabbit