Custom Shader Attributes

For the vertex colors of a non-instanced mesh, you could use Mesh API. Here is an example of a procedural plane mesh with each vertex having own color:

https://playcanvas.com/project/1190134/overview/vertex-colors

Although not an attribute, but you could also pass it as a uniform to be used by shader. You probably have read Custom Shaders manual. We should probably add an example with an array there as well, but you could pass it like this:

// script
const myList = new Float32Array([0, 1, 2, 3, 4, 5, 6, 7]);
app.graphicsDevice.scope.resolve(`uSomeList[0]`).setValue(myList);
// shader
uniform float uSomeList[8];

If you wish to add some custom attributes to an instanced mesh, you can find an example here:

1 Like