EDIT: Now also supported in the automatic shader generator. To enable it, you need these settings:
hardware-animated-vertices true
basic-shaders-only false
You also need to call setShaderAuto() on the actor in question.
The Cg and Shader Generator support will be 1.10.0 and above. I’ve backported the GLSL p3d_TransformTable support to 1.9.1 by user request.
Hi all,
I just checked in a change today that makes it more straightforward to implement skeleton animation in a shader using the existing Panda3D animation system.
It’s implemented via a new shader input p3d_TransformTable, and a flag you can set on ShaderAttrib that indicates that Panda should not attempt to animate the vertices on the CPU (though I may change my mind about the specifics of this interface later).
It should be trivial to extend this to cover Cg and the shader generator, which I plan to do soon.
I plan on making a similar interface for implementing morph targets as well.
If you don’t have a recent build, these were made today:
buildbot.panda3d.org/downloads/4 … 1cceb4df8/
This brief sample program shows a panda animated by a GLSL shader, next to another panda animated by Panda’s CPU animation system for reference.
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.actor.Actor import Actor
from panda3d.core import Shader, ShaderAttrib
shader = Shader.make(Shader.SL_GLSL, """#version 130
in vec4 p3d_Vertex;
in vec4 p3d_Color;
in vec2 p3d_MultiTexCoord0;
in vec4 transform_weight;
in uvec4 transform_index;
uniform mat4 p3d_ModelViewProjectionMatrix;
uniform mat4 p3d_TransformTable[100];
out vec4 color;
out vec2 texcoord;
void main() {
mat4 matrix = p3d_TransformTable[transform_index.x] * transform_weight.x
+ p3d_TransformTable[transform_index.y] * transform_weight.y
+ p3d_TransformTable[transform_index.z] * transform_weight.z
+ p3d_TransformTable[transform_index.w] * transform_weight.w;
gl_Position = p3d_ModelViewProjectionMatrix * matrix * p3d_Vertex;
color = p3d_Color;
texcoord = p3d_MultiTexCoord0;
}
""", """
#version 130
in vec4 color;
in vec2 texcoord;
uniform sampler2D p3d_Texture0;
void main() {
gl_FragColor = color * texture(p3d_Texture0, texcoord);
}
""")
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
model = "panda"
anim = "panda-walk"
scale = 1.0
distance = 6.0
# Load the panda model.
self.pandaActor = Actor(model, {"walk": anim})
self.pandaActor.setScale(scale)
self.pandaActor.reparentTo(self.render)
self.pandaActor.loop("walk")
# Load the shader to perform the skinning.
# Also tell Panda that the shader will do the skinning, so
# that it won't transform the vertices on the CPU.
attr = ShaderAttrib.make(shader)
attr = attr.setFlag(ShaderAttrib.F_hardware_skinning, True)
self.pandaActor.setAttrib(attr)
# Create a CPU-transformed panda, for reference.
self.pandaActor2 = Actor(model, {"walk": anim})
self.pandaActor2.setScale(scale)
self.pandaActor2.setPos(distance, 0, 0)
self.pandaActor2.reparentTo(self.render)
self.pandaActor2.loop("walk")
app = MyApp()
app.trackball.node().setPos(0, 50, -5)
app.run()