# Why must specify a customDepthMaterial for proper shadows when modifying vertex positions

**URL:** https://discourse.threejs.org/t/why-must-specify-a-customdepthmaterial-for-proper-shadows-when-modifying-vertex-positions/70715
**Category:** Questions
**Tags:** shaders
**Created:** [September 14, 2024, 11:13am UTC](https://discourse.threejs.org/t/why-must-specify-a-customdepthmaterial-for-proper-shadows-when-modifying-vertex-positions/70715 "2024-09-14T11:13:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Alexandria](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/alexandria/32/24614_2.png) [@Alexandria](https://discourse.threejs.org/u/Alexandria)
#### Post date: [September 14, 2024, 11:13am UTC](https://discourse.threejs.org/t/why-must-specify-a-customdepthmaterial-for-proper-shadows-when-modifying-vertex-positions/70715/1 "2024-09-14T11:13:08Z")

</div>

from the [docs](https://threejs.org/docs/#api/en/core/Object3D.customDepthMaterial) it states that:  
" When shadow-casting with a [DirectionalLight](https://threejs.org/docs/index.html#api/en/lights/DirectionalLight) or [SpotLight](https://threejs.org/docs/index.html#api/en/lights/SpotLight), if you are modifying vertex positions in the vertex shader you must specify a customDepthMaterial for proper shadows"

what causes the shadows to break when changing the vertices? and how does customDepthMaterial mitigate this? what is customDepthMaterial instance of? can it be an instance of THREE.MeshBasicMaterial etc?  
how do i approach answering these kinds of questions from the source code itself? how do i navigate the codebase / repo history to get this answer?

thank you so much

---

<div class="post-metadata">

### Author: ![dubois](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dubois](https://discourse.threejs.org/u/dubois)
#### Post date: [September 15, 2024, 3:14am UTC](https://discourse.threejs.org/t/why-must-specify-a-customdepthmaterial-for-proper-shadows-when-modifying-vertex-positions/70715/2 "2024-09-15T03:14:27Z")

</div>

two shaders are needed to make the shadows. Some shader X and a “depth shader”. Since these are two different shaders/materials, if you change one you have to change the other.

Say you make your own shader that transforms the vertices just like everything else in three, but then you add your own logic that says that vertices should move 3 units in world z. If you don’t modify the other shader, shadows will be cast as if the model has not moved by 3 units in world z…

---

<div class="post-metadata">

### Author: ![Alexandria](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/alexandria/32/24614_2.png) [@Alexandria](https://discourse.threejs.org/u/Alexandria)
#### Post date: [September 15, 2024, 9:14am UTC](https://discourse.threejs.org/t/why-must-specify-a-customdepthmaterial-for-proper-shadows-when-modifying-vertex-positions/70715/3 "2024-09-15T09:14:53Z")

</div>

Thanks so much
