Skip to content

fix: NoiseEffectController producing zero progress on some platforms#3831

Merged
spydon merged 2 commits intomainfrom
devkage/noise-effect-controller-lattice-point
Mar 2, 2026
Merged

fix: NoiseEffectController producing zero progress on some platforms#3831
spydon merged 2 commits intomainfrom
devkage/noise-effect-controller-lattice-point

Conversation

@ufrshubham
Copy link
Member

Description

NoiseEffectController was sampling the noise function with a hardcoded y-coordinate of 1:

noise.getNoise2(timer / duration, 1)

PerlinNoise(frequency: F) scales inputs internally by F before sampling, so the effective y becomes 1 * F = F. With any integer frequency (e.g. frequency: 400), y lands on an integer row in the noise grid.

When this happens, yd0 = y - y0 = 0 (fractional distance from the lower lattice row) and consequently ys = 0 (the quintic interpolation weight). The ys.lerp(bottomRow, topRow) call then collapses to just bottomRow, discarding all top-row gradient contributions.

Within the surviving bottom row, gradCoord2D computes xd * g.x + yd * g.y. Since yd0 = 0, the y-gradient term vanishes entirely. Additionally, 2 of the 8 possible gradient vectors(0,-1) and (0,1) — have g.x = 0, so any corner the hash maps to those contributes nothing. The result is a severely reduced noise amplitude, sometimes collapsing to near-zero depending on the hash outcome for the seed and x-coordinate.

Fixes:

  • Changed y from 1 to sqrt2 (≈ 1.41421356…). Since sqrt2 is irrational, no integer frequency can scale it to an integer row, so yd0 ≠ 0, ys ≠ 0, and all 4 corner gradients (both x and y components) always contribute fully.
  • Changed x from timer / duration to timer so frequency correctly means oscillations per second regardless of effect duration. Previously, normalizing to 0..1 meant duration was silently controlling oscillation speed.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • [NA] I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • [NA] I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

Closes #3193

@ufrshubham ufrshubham self-assigned this Mar 2, 2026
Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

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

Lgtm!

@spydon spydon merged commit 5d88832 into main Mar 2, 2026
9 checks passed
@spydon spydon deleted the devkage/noise-effect-controller-lattice-point branch March 2, 2026 15:54
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.

MoveEffect with noise does nothing on some platforms

2 participants