Skinned mesh related: bone/bind matrices update timing

Hi, I’m trying to make a particle system that emits particles at the deformed vertices of SkinnedMesh. How I implemented is that:

I wrote a custom shader that compute skinning and store the position to a WebGLRenderTarget. And a batched mesh of bunch of particles is built based on the texture, also the texture drives the position of the particles in update.

This is a screen rec of the implementation:
ezgif.com-gif-maker (5)
(Character is the original skinned mesh and those white points are the batched cubes driven by the texture)

The problem is that there seems a frame delay between the particles and the skinned mesh animation which I have been trying to figure.

The original skinned mesh is udpated before the texture is updated, something like this :

// Updates source skinned mesh animation
animationMixer.update(deltaTime)

// Upload skinning attributes from the source to custom skinning shader
shader.uniform = sourceSkinnedMesh.bindMatrix
shader.uniform = sourceSkinnedMesh.bindMatrixInverse
shader.uniform = sourceSkinnedMesh.boneTextureSize
shader.uniform = sourceSkinnedMesh.boneTexture

// Render RTT  to update texture
renderer.render(RTTScene);

// Render scene
renderer.render(Scene);

My guess is that the skinning attributes are actually not updated at the moment when animationMixer.update(deltaTime) is being called but it is updated when the scene is render which is after I upload skinning attributes to the shader but I’m kind of intimidated and not sure where I should look at as a start. Thought I should ask the forum first before I start to diving into the source and begin to hate myself…

Any help would be really appreciated!

Best,
av

1 Like

I was able to manage it by uploading the skinning attributes to shader in the source skinnedmesh’s onBeforeRender event instead of doing it in update.