-
Notifications
You must be signed in to change notification settings - Fork 25
Add p5.js integration #96
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super cool! ❤️
I've got just a couple very minor comments.
Thanks for sending this, we really appreciate having some fresh eyes on it :)
targets/p5.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can change "Hyrda" -> to "p5"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops good catch! Also I forgot that this copy-and-pasted function already handles passing in a function as the source instead of a string, so I don't need to export two separate functions for this.
targets/p5.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this disable face culling when a p5 user wants it to stay on? (even if it did I wouldn't imagine it would affect many users.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call, I'll grab the current parameter values at the start and restore them here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thinking here. This is something we could probably add in the future for our other targets like threejs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another good idea that we could implement in our other targets to reduce duplication. thanks!
This adds a new build that can be included in p5 sketches to mix Shader Park sdfs with other p5 objects, including depth support, so that p5 objects don't clip the sdf in unexpected ways.
A small demo with two Shader Park spheres and a p5 cube:
shaderpark-in-p5.mov
Live here: https://editor.p5js.org/davepagurek/sketches/elqEKyApr
This exposes a few function people can use:
loadShaderPark(url, options)
: Call this inpreload()
to load source code from a filecreateShaderParkFromSrc(src, options)
: Creates a shader park object from string source codecreateShaderPark(fn, options)
: Like thecreateShaderParkFromSrc
option, but it lets you pass in a js function. Under the hood, this just calls.toString()
on the function. This is maybe the easiest option within the p5 editor that also gives you js syntax highlighting.For all of those methods:
p5
instance when using p5's instance modecreateGraphics
object to get an object you can use on that instead of the main canvasscale
: Defaults to 1, and scales up or down the sdfdrawGeometry
: A function that draws the host object the shader will run on. Defaults to a sphere, but could be anything.To use this, you'll need a build of p5 off of the main branch (there isn't a release yet with WebGL2 support, but it'll be in the next one!) and you'll need to add a script tag referencing
dist/shader-park-p5.js
.