Implement your own shadow mapping

Thanks a lot for you answer, that is really helpful. I did not notice this overrideMaterial attribute in the documentation. That is exactly what I need.

Now, ideally I would only override the fragment shader (because some of my meshes might make use of a height map, modifying the vertex position in the vertex shader, and this might change the depth value). Do you think I could achieve this override of the fragment shader only? I suppose ThreeJS does it internally, or do shadows do not render that great when using a custom ShaderMaterial that modifies the vertex position?

It might be difficult to achieve though… You might end up having a Shader program that do not compile because the varyings do not match, right?