-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
setAttribute() function for defining custom shader attributes #7276
Conversation
It looks like we've got some changes from the main branch in here, do we have any conflicts if we |
… 0's in case not enough attributes set
…crease the tesselation vertex size info
…ze so that custom attributes can increase size of vertex data
Thanks for spotting that, should be good now! |
…rray to single object
Custom geometries can now have multiple attributes across different shapes
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.
Great work on this, especially getting the tessellation stuff to work!
Yeah I'm also happy with those, especially as |
I think this is looking good to go! @perminder-17 how do you feel about |
Using the name |
Thanks @davepagurek and @perminder-17, I've updated the code so that everything uses 'vertexProperty()' instead! |
Thanks everyone! |
@all-contributors please add @lukeplowden for code |
I've put up a pull request to add @lukeplowden! 🎉 |
Resolves #5120
In response to the issue above I've added a global
setAttribute()
function and a method of the same name onp5.Geometry
.2024-09-20.12-35-05.mp4
Attributes are per vertex data declared at the top of the vertex shader like so:
Currently, p5.js has a number of predefined attributes including
aPosition
,aVertexColor
,aNormal
, etc. These changes allow the user to define custom attributes in two ways, using an API similar toShader.setUniform()
.setAttribute(attributeName, data)
which applies the custom attribute to subsequent calls tovertex()
,bezierVertex()
, orcurveVertex()
, within abeginShape()
->endShape()
block, i.e. on immediate mode geometry. This is the same behaviour asfill()
ornormal()
for per-vertex data.Geometry.setAttribute()
in case the user wants to directly interface withp5.Geometry
objects, i.e. on retained mode geometry. This essentially creates an array and pushes a new value on thep5.Geometry
object, which is unlike other methods onp5.Geometry
.The parameters for both functions are the same, a string
attributeName
and a number or array of numbersdata
.PR Checklist
npm run lint
passesThis is a draft pull request as I'm finishing off the tests and documentation right now. Would like to hear other WebGL contributor's thoughts on progress @perminder-17 @Garima3110
Edge cases
There are a few edge cases related to the need for attributes to be properly set for each vertex. If
attribute vec3 aCustom;
is declared and used in a shader, there should be as many values foraCustom
as there are foraPosition
.Global function (immediate mode)
setAttribute()
after the firstvertex()
call. In this casevertex()
zero-fills the previous values for each call which came before. It behaves like this:Retained mode
Because the
Geometry.setAttribute(attributeName, data)
method pushes to an arrayGeometry[attributeName]
:In this case we plan to just give a Friendly Error saying that one of the vertex attributes has not been properly filled.