Skip to content

Conversation

@rakesh2OO5
Copy link

This PR normalizes the output range of the strands noise implementation to match the JavaScript noise() function.

Changes:

  • Normalize GLSL backend output from [-1,1] to [0,1]
  • Normalize WGSL backend output from [-1,1] to [0,1]

Tested:

  • Verified GPU (WEBGL and WebGPU) noise output remains within [0,1]
  • Matches CPU noise() output range

Fixes #8386

@rakesh2OO5
Copy link
Author

CI is awaiting maintainer approval since this is from a fork — happy to update the branch if needed.

@davepagurek
Copy link
Contributor

I think this works, although is there a reason for doing the normalization differently in the two files? It could be easier for people in the future comparing the implementations if we use the same math in both places.

@rakesh2OO5
Copy link
Author

Good point — there’s no strong reason for them to differ. I used the equivalent forms out of habit, but I agree it’s better for readability and future comparisons if both backends use the same expression.

I have updated both GLSL and WGSL to use the same normalization math (e.g. (result + 1.0) * 0.5) and pushed a small follow-up commit.

Now , both backends use the same normalization expression for consistency — thanks for the suggestion!

@davepagurek
Copy link
Contributor

Thanks, code looks good! I think the last step before merging is just to test out a build of this doing something similar to the sketch in the original issue. I can get to that eventually, but if you have time, that would also be great. If you run npm run build, then you can upload lib/p5.js to a p5 web editor sketch, and edit the html to have <script src="p5.js"></script> rather than the usual longer CDN link to p5.

@rakesh2OO5
Copy link
Author

rakesh2OO5 commented Jan 23, 2026

Tested using the original issue sketch in the p5 Web Editor with a custom built p5.js (loaded via local p5.js file).
Tested on Windows 11 / Chrome (WebGL2 enabled).
Both paths stay normalized and match numerically:

CPU noise range: 0.0119 → 0.4960

GPU (strands/shader) noise range: 0.0119 → 0.4960

Screenshot attached showing red (GPU), blue (CPU), and console output.
image

@davepagurek
Copy link
Contributor

That looks great, thanks @rakesh2OO5!

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.

2 participants