Using custom shaders with Models
Currently it isn't possible to use per-node or per-material shaders when rendering a Model. You can set a single shader and call Model:draw and that shader will be used for all of the nodes (Materials will update uniforms for that shader).
Some use cases require different glTF materials to use their own shaders.
In glTF, nodes can have a mesh, a mesh has one or more primitives, and a primitive can have a material.
In LÖVR, each glTF primitive is a Mesh with a Material applied to it.
I can see 2 possible approaches
- Add something like
Model:setShader(material, shader). This sets a shader to use for a material. Any primitives using this material will use the shader. If the shader is nil, the shader set usinglovr.graphics.setShaderwill be used. - Add a way to render a specific node of a Model. Imagine
Model:drawNode(node, [recurse], transform, instances)or a variant to :draw. Because a node can have multiple meshes/materials, this doesn't give the necessary amount of control. However, changing the Shader per-node would still be useful, and this probably enables lots of other interesting things too. If this was added, there probably also needs to be some way to get the parent/children of a node. The ultimate goal is to be able to writeModel:drawentirely in Lua, so that you can change how it works if you need to.
These aren't mutually exclusive. Both would probably be useful.
This is implemented on the gpu branch -- when drawing a Model, you can specify a single node to render (default: root) and whether you want to render its children as well (default: true).