# customDepthMaterial vertex shader

**URL:** <https://discourse.threejs.org/t/customdepthmaterial-vertex-shader/45838>\
**Category:** Questions\
**Tags:** materials\
**Created:** [December 15, 2022, 3:56pm UTC](https://discourse.threejs.org/t/customdepthmaterial-vertex-shader/45838 "2022-12-15T15:56:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wsko-12](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/wsko-12/32/26456_2.png) [@Wsko-12](https://discourse.threejs.org/u/Wsko-12)\
**Post date:** [December 15, 2022, 3:56pm UTC](https://discourse.threejs.org/t/customdepthmaterial-vertex-shader/45838/1 "2022-12-15T15:56:10Z")

</div>

Hello. I have a problem with vertex shader on depth material.  
I changed vertex shader on MeshPhongMaterial and also apply this changes on MeshDepthMaterial for correct shadows.  
on R142 all works fine. But now I updated to R147 and .onBeforeCompile on MeshDepthMaterial isn’t calls. How it works now?  
Thanks

---

<div class="post-metadata">

**Author:** ![Fyrestar](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/fyrestar/32/52793_2.png) [@Fyrestar](https://discourse.threejs.org/u/Fyrestar)\
**Post date:** [December 15, 2022, 4:02pm UTC](https://discourse.threejs.org/t/customdepthmaterial-vertex-shader/45838/2 "2022-12-15T16:02:36Z")

</div>

I just tested `onBeforeCompile` with R147 on MeshDepthMaterial and it fires. Does it throw any errors?

With this you don’t need to manually replicate the modifications to the shadow material btw. Tested with R147 too.  
https://codepen.io/Fyrestar/embed/preview/YzvmLaO?default-tabs=js%2Cresult&height=300&host=https%3A%2F%2Fcodepen.io&slug-hash=YzvmLaO

> [@Function to extend Materials](https://discourse.threejs.org/t/function-to-extend-materials/7882):
>
> This is a little helper function to create a THREE.ShaderMaterial extending a standard material. The second parameter is optional. Instead the constructor of a standard material, you can also pass a instance of a shader material and extend it the same way. Usage To extend materials: THREE.extendMaterial( constructor|material|shaderMaterial [, options]) For patching in onBeforeCompile: THREE.patchShader( object [, options]) const myMaterial = THREE.extendMaterial(THR…

---

<div class="post-metadata">

**Author:** ![Wsko-12](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/wsko-12/32/26456_2.png) [@Wsko-12](https://discourse.threejs.org/u/Wsko-12)\
**Post date:** [December 15, 2022, 4:39pm UTC](https://discourse.threejs.org/t/customdepthmaterial-vertex-shader/45838/3 "2022-12-15T16:39:32Z")

</div>

No any error.  
I tried to find in witch version this happens:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/9/7/97ceb39088da09168149158963ed1233182d64d3.png)

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/6/6/666b91e3ebf736275e3332c134f698c03c9adfda.png)

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/4/0/4067a863662b19b8efb67de9a1470a75d757351a.png)

---

<div class="post-metadata">

**Author:** ![Fyrestar](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/fyrestar/32/52793_2.png) [@Fyrestar](https://discourse.threejs.org/u/Fyrestar)\
**Post date:** [December 15, 2022, 4:52pm UTC](https://discourse.threejs.org/t/customdepthmaterial-vertex-shader/45838/4 "2022-12-15T16:52:44Z")

</div>

I forgot my plugin actually makes that `customDepthMaterial` can be used on materials instead on the mesh, it might be possible this is now default.

---

<div class="post-metadata">

**Author:** ![titansoftime](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/titansoftime/32/1044_2.png) [@titansoftime](https://discourse.threejs.org/u/titansoftime)\
**Post date:** [December 15, 2022, 5:10pm UTC](https://discourse.threejs.org/t/customdepthmaterial-vertex-shader/45838/5 "2022-12-15T17:10:41Z")

</div>

customDepthMaterial acts a little strange in r147. Possibly related. Could try this patch and see if it works for you.

> <https://github.com/mrdoob/three.js/pull/25137#event-8035205412>
>
> Replacement PR for #25082
