Skip to content

Add GLSL-based noise(vec2) function to p5.strands (#7897) #7921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev-2.0
Choose a base branch
from

Conversation

LalitNarayanYadav
Copy link
Contributor

Summary

This PR implements a noise(vec2) function in p5.strands to enable shader-compatible noise effects. It addresses #7897, which is part of the broader effort to bridge core p5.js functions with p5.strands (#7849).


Changes Made

  • Created src/webgl/shaders/functions/noise.glsl.js with a basic fractal noise implementation (3 octaves).
  • Registered noise(vec2) in builtInGLSLFunctions in ShaderGenerator.js with isp5Function: false.
  • Injected the GLSL noise code into all fragment shaders via GLOBAL_SHADER.output.fragmentDeclarations.add(noiseGLSL).

PR Checklist

- Created src/webgl/shaders/functions/noise.glsl.js
- Provides a simple fractal noise function using 3 octaves
@LalitNarayanYadav LalitNarayanYadav changed the base branch from main to dev-2.0 June 18, 2025 21:21
@RandomGamingDev
Copy link
Contributor

Looks good to me :D

@davepagurek
Copy link
Contributor

Thanks for tackling this! Are you able to show a test sketch using the noise so we can take a look at what it looks like? Either by making a test sketch in src/preview/global/sketch.js + npm run dev:gloabl, or by running npm run build to generate lib/p5.js and lib/p5.min.js which you could then upload to the p5 web editor and use.

@@ -1632,6 +1634,7 @@ function shadergenerator(p5, fn) {
}


GLOBAL_SHADER.output.fragmentDeclarations.add(noiseGLSL);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this might not be defined yet, as we only set GLOBAL_SHADER = this in the ShaderGenerator constructor. Maybe rather than adding noise to the list of glsl functions, we could do a custom function for it like you did earlier for lerp, and in that custom function, you do GLOBAL_SHADER.output.fragmentDeclarations.add(noiseGLSL)? (And possibly add it to the vertex declarations too, it could be used in updating positions as well.)

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.

3 participants