Physical material with onBeforeCompile vertex edit dont cast shadows

Hi to everyone,
Working currently on a project where I need to edit vertex shaders ( positions animations) and need to keep the physical material properties ( metalness, roughness etc). Found a good way to do it by using the onBeforeCompile property and I am able to achieve the position animation, but with this way of doing shadows seems to be “static”.
Did some tests by passing the same vertex shader to the customDepthMaterial, also tested with the customDistanceMaterial, but nothing works.
if someone has already encountered this problem and found a solution or a lead, you save me if you can share !
Here a small preview: https://codesandbox.io/p/sandbox/6kcyp8 ( you can use the orbitControl to see the static shadow )

That custom depth material needs a minor change in its onBeforeCompile:

customDepthMat.onBeforeCompile = (shader) => {
  shader.uniforms.uTime = customDepthMat.uniforms.uTime;
  shader.vertexShader = `
      uniform float uTime;
      ${shader.vertexShader}
      `.replace(
    `#include <begin_vertex>`,
    `#include <begin_vertex>
      ${compute}
      transformed = pos;
      `
  );
};

shader.uniforms.uTime, you have time instead of uTime here.

3 Likes

Shame on me!! Thank you so much!!

1 Like