How to share shader?

How do I share a shader between a number of shared nodes? The shaders need some uniforms to be set each frame with node specific information. Since the GLSLShaderDataLogic only has a reference to the geometry, I cannot use it to set my uniforms (the parent reference of shared meshes is pointing wrong). How do I solve this? What have I missed?



/Robert

I actually bumped into this same problem myself… I don't think there's an actual solution, except maybe not to use shared nodes at all.  :expressionless:

I did an ugly change in the SharedMesh:


### Eclipse Workspace Patch 1.0
#P jME2
Index: src/com/jme/scene/SharedMesh.java
===================================================================
--- src/com/jme/scene/SharedMesh.java   (revision 4105)
+++ src/com/jme/scene/SharedMesh.java   (working copy)

     @Override
public void draw(Renderer r) {
@@ -612,6 +623,10 @@
         target.getWorldRotation().set(getWorldRotation());
         target.getWorldScale().set(getWorldScale());
         target.setDefaultColor(getDefaultColor());
+       
+        // first parent of target is the shared node (if using one), second is the one to set
+        target.getParent().setParent(this.getParent());
+       
         System.arraycopy(this.states, 0, target.states, 0, states.length);
 
         r.draw(target);



So now, I can do this:

sharedShader.setShaderDataLogic(new GLSLShaderDataLogic() {
           public void applyData(GLSLShaderObjectsState shader, Geometry geom) {
              shader.setUniform("animationMatrix", ((MyNode)geom.getParent().getParent().getParent()).animationController.getAnimationMatrix(),true);
              shader.setUniform("skinShade", ((MyNode)geom.getParent().getParent().getParent()).skinShade);
           }
       });



Maybe something similar should be in jME?

OK, that's sad. I will try to solve it in some other way then… Thanks for answering.

Anyway sharing shader can be done without modifying SharedMesh, I think.

Because each geometry can have its own UserData,

you can get and use it in applyData()

Yes, you can share a shader without shared mesh and that works fine in jME. The problem is when you want to share a shader between shared meshes (so you have both shared vertices and shader).



I don't use that UserData actually, so I know nothing of it…