-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
p5.js Shader generation API #7622
base: dev-2.0
Are you sure you want to change the base?
Conversation
…next to fix structs
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 looking so good! I was poking around in preview/global
seeing how easily I could break things and it's feeling really stable!
src/webgl/ShaderGenerator.js
Outdated
return new VariableNode('gl_InstanceID', 'int'); | ||
} | ||
|
||
fn.uvCoords = function() { |
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.
Since not all hooks will be able to use this (e.g. in a vertex shader hook before it's assigned) are we able to just rely on texture coords in hook inputs?
Addresses #7188
Example sketch
Changes:
This PR extends the Shader Hooks
p5.Shader.modify()
API by adding a way to write shaders in JavaScript which will generate corresponding GLSL code. It simplifies the process of writing shaders, especially for people new to them.The API currently looks like this:
And the generated hook would be:
There are two modes for the API. In the JS code above, the second parameter is an optional options object. Currently, since
parser: true
is set (which is the default option), things like operator overloading and automatic naming of uniforms are allowed. With the (acorn) parsing stage enabled, it is transpiled to an intermediate stage which looks like:Optionally users can write in this style as well.
A lot of new functions are provided, including
create*()
anduniform*()
where * is a GLSLnative type. There are also the hook callbacks likegetFinalColor()
above.Blocking issues
Right now there are a couple of blocking issues before 2.0's release:
cos()
etc. I can set a flag for these which overrides them, but it depends on which order they're imported. One potential fix is to add these to the global scope and then remove them aftersetup()
.Longer term
And some remaining, medium to long term issues:
33.mult(time)
. This should be a small fix. It should also not transpile anything in uniform default value callbacks (as inuniformFloat('greenValue', () => myCol());
above) as these won't be able to assess at runtime..xyzw
, not.rgba
or.stpq
. RGBA would be especially important as conflating position/ colour data can be difficult for new shader programmers to wrap their head around. See the proxy issue later.() => millis()
:myVec4.yxyz
etc.texture()
is called, splice in thegetTexture
definition into shaders that don't already have it (e.g. they didnt branch off of a base material shader)PR Checklist
Not currently done.
npm run lint
passes