[BUG DISCUSSION] Shader System and Materials

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?

Reading it, it looks like it’s been in Blender for a while, this could in part be due to the fact that the system for custom shaders is not quite as complete as it could be (the developer of the system has long left the BGE to work on the GameKit project).

Perhaps Kupoman has something up his sleeve since he’s still working on overhauling the shading system (though in smaller chunks now so as to be more applicable to code review and to possibly get his work committed much faster).

Perhaps so. I imagine the main bug of the shader not affecting shared meshes wouldn’t be too difficult to fix, but making it work really well may not be such an easy feat. I think in a perfect world, you could:

  1. Apply a shader to an object and its duplicates.
  2. Not apply a shader to certain other duplicates.
  3. Supply different uniform variables to the shader to affect objects applying it in different ways.

This indeed might take awhile to fix (perhaps it can be part of the Google Summer of Code project).

I want to help but I’m clueless when it comes to shaders. You should post a blend file so we can try a few things on it and see what happens. You might have to duplicate the shader for each object so that each objects gets a dedicated one. No blend file ?

I made a comment in the bug report in which I attached a blend file that demonstrates the issue.