I would like to avoid changing Babylon.js library. I created a PBRCustomMaterial that has properties of the original PBRMaterial used by the meshes of a rigged model, and I can pass the joint matrix of the key frames as texture to this PBRCustomMaterial.
What I want to achieve is to replace the existing implementation in src/Shaders/ShadersInclude/bonesVertex.fx. Instead of reading the transformation matrix from boneSampler, I want the bonesVertex shader to use dynamically calculated worldJointMatrix * invertedBindingMatrix in the shader. I want to know if this is a feasible approach or if there is any other way to do it?
Thanks for helping and happy new year. I am sorry that I didn’t express my question clearly. I am aware of Vertex_Before_PositionUpdated and AddUniform. I read code in pbr.vertex.fx when I tried to understand where Babylon applies weighted joint matrix to vertex. And it makes me hesitating continue my approach as explained below. The following code taken from lines 182-197 of pbr.vertex.fx.
Like you suggested, I was planing to apply my own transformation matrix to the vertex in CUSTOM_VERTEX_UPDATE_POSITION, which can be customized by Vertex_Before_PositionUpdated(). But after this vertex position update, the original weighted joint matrix are applied to vertex position change is still executed:
#include<bonesVertex>
I am not sure if the final positions are still correct if both my custom position update and bonesVertex.fx are applied. Also I am a bit worried that any other code between CUSTOM_VERTEX_UPDATE_POSITION and bonesVertex could also impact the position. So my actual question is trying to find out if my worries are actually valid. Or if there is better way to overwrite bonesVertex?
I am not sure I get what you mean. But I find the following approach is working for me. It allows me to replace the original bonesVertex shader with a custom implementation. But of course it will stop working if pbr vert shader changed this line #include<bonesVertex>, and this solution will need to update as well.