strmnati Posted November 3, 2015 Share Posted November 3, 2015 Hello everyone. I've found some issue. I have a mesh with skeleton animation. Also, I have a specific shader used in ShaderMaterial. When I assign the ShaderMaterial to the mesh. The animation disappear, but the effect of shader is working. How do I have the animation with my shader? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 3, 2015 Share Posted November 3, 2015 Unfortunately, you will have to code the skeletal animation support in your shaders but I have a good fallback, you can ask Babylon.js to compute skeletal animations for you not using GPU but using CPU: mesh.computeBonesUsingShaders = false strmnati 1 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted November 3, 2015 Share Posted November 3, 2015 More info will need to be provided. What version are you using? If 2.3, date & time of JS file, in addition to any console messages. I am not familiar with which vertex shader is called, but it changed yesteday. Never mind Quote Link to comment Share on other sites More sharing options...
strmnati Posted November 4, 2015 Author Share Posted November 4, 2015 Thanks, Deltakosh.Your reply is helpful. Quote Link to comment Share on other sites More sharing options...
jCarrasco Posted January 1, 2016 Share Posted January 1, 2016 Hi!I'm working on this right now, and managed to make it work, somehow. First of all, having a look at the basic shader source we can see we need to inject 3 values to the shader:attribute vec4 matricesIndices;attribute vec4 matricesWeights;uniform mat4 mBones[BonesPerMesh];Fortunately, Babylon will do this work for us. All we have to do is specify this values in the attributes and uniforms list when defining the shader, and Babylon will fill in this values automaticly. Like this:var myMaterial = new BABYLON.ShaderMaterial("myMaterial", scene, "/path/to/myShader", { attributes: ["position", "uv", "normal", "matricesIndices", "matricesWeights"], uniforms: ["worldViewProjection", "world", "cameraPosition", "lightPosition", "ambient", "mBones"]});You can check Babylon source code to see how this values are filled, if curious. It's relatively easy to understand. Going back to the basic shader source, let's see how this values are used:void main(void) { mat4 finalWorld = world; #ifdef BONES mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x; mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y; mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z; #ifdef BONES4 mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w; finalWorld = finalWorld * (m0 + m1 + m2 + m3); #else finalWorld = finalWorld * (m0 + m1 + m2); #endif #endif gl_Position = worldViewProjection * finalWorld * vec4(position, 1.0);}BONES and BONES4 defines will be also be generated automaticly if bones deformations by shader is set. So, basicly, the mat4 finalWorld will hold the bone deformation and you multiply it by the original vertex position. You can check if you remove it from the operation, the mesh will remain static. And that's all. You will have your shader ready for other operations you want to apply. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.