Hello. I recently ran across a bug in which custom shaders don’t work across multiple objects (i.e. it only works for one, not for other objects also running the shader, or sharing materials, or sharing meshes). The fix is to allow for sharing these effects between objects, of course. However, I wonder if that is the way to go? Perhaps it would be better to tie the shaders to the meshes instead of the materials?
That way one could use the same shader between different objects and provide different uniform values by taking advantage of LibNew (since they’re mesh specific, rather than material specific). This would also allow one to have one object do the work by making multiple objects intentionally share meshes, so that only one has to actually run the shader and provide the uniform values (if you choose to provide them, of course).
Here’s a bit of copy-paste from my addition to the long-running bug report for this.
The python binding would just move the entire shader system out from mesh.material.shader to mesh.shader and work generally the same. It even makes more sense since any applied shader automatically overrides the material; why tie them together?
The only downside is that you can’t apply shaders on a certain object’s materials in isolation (i.e. only apply a waving effect to the fire material on a mesh). Maybe the meshes and material’s lists could be refactored so that every material on a single mesh in Blender automatically creates a corresponding mesh in the BGE to access, and the material property is just a single accessible property that identifies that material? As far as I know, the meshes list usually only has a single mesh in it; perhaps taking advantage of that list would be effective.
Any ideas?