You want to change the vertices in the vertex shader. However, this is tricky, since 1) we’re using OpenGLES 2.0 which doesn’t feature gl_VertexID, and 2) We currently only support 4 user defined constants per shader.
However, a simple test allowed me to modify the vertices of my box, using a custom material and custom shader. The yellow rectangle is the original location of my box, and the gradient polygon is my custom vertices (pretend there’s a light source in the bottom left corner):
Setting render constants is straight forward. Copy the material and shaders you wish to use into your project (from the builtins folder), and then add extra constants into the material file. See the manual for further reference.
In my test, I pass 3 constants: the center of the box, and the 4 vertices:
go.set("#sprite", "center", vmath.vector4(pos.x, pos.y, 0, 0))
go.set("#sprite", "p1p2", vmath.vector4(p1.x, p1.y, p2.x, p2.y))
go.set("#sprite", "p3p4", vmath.vector4(p3.x, p3.y, p4.x, p4.y))
Using a technique this, you could render them into a stencil buffer an use that for rendering the scene. See this flashlight example
I’ve uploaded this (very basic) example of the custom box here
Hopefully, we can soon render custom shapes a bit more easily