# Shadow generator produces wrong shadow

**URL:** <https://forum.babylonjs.com/t/shadow-generator-produces-wrong-shadow/50996>\
**Category:** Questions\
**Tags:** shadows, shadowgenerator, rendering\
**Created:** [June 2, 2024, 12:19am UTC](https://forum.babylonjs.com/t/shadow-generator-produces-wrong-shadow/50996 "2024-06-02T00:19:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidP](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/davidp/32/45669_2.png) [@DavidP](https://forum.babylonjs.com/u/DavidP)\
**Post date:** [June 2, 2024, 12:19am UTC](https://forum.babylonjs.com/t/shadow-generator-produces-wrong-shadow/50996/1 "2024-06-02T00:19:55Z")

</div>

Hello,  
It appears that the shadow generator is not producing the expected results. In this example, sphere0’s shadow is a circular line instead of a solid circle, and sphere1 does not cast a shadow at all

> **[Babylon.js Playground](https://playground.babylonjs.com/#IIZ9UU%23464)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Can you please let me know what I am doing wrong  
Thank you  
David

---

<div class="post-metadata">

**Author:** ![qq2315137135](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qq2315137135/32/32219_2.png) [@qq2315137135](https://forum.babylonjs.com/u/qq2315137135)\
**Post date:** [June 2, 2024, 12:47am UTC](https://forum.babylonjs.com/t/shadow-generator-produces-wrong-shadow/50996/2 "2024-06-02T00:47:22Z")

</div>

You need to set shadowMinZ and shadowMaxZ.  
For example:

```auto
    light.shadowMinZ = 0
    light.shadowMaxZ = 5

```

> **[Babylon.js Playground](https://playground.babylonjs.com/#IIZ9UU%23466)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

see line 36

---

<div class="post-metadata">

**Author:** ![qq2315137135](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qq2315137135/32/32219_2.png) [@qq2315137135](https://forum.babylonjs.com/u/qq2315137135)\
**Post date:** [June 2, 2024, 12:53am UTC](https://forum.babylonjs.com/t/shadow-generator-produces-wrong-shadow/50996/3 "2024-06-02T00:53:42Z")

</div>

Or don’t set it, but put the light farther away.  
In debug view, it’s a good idea to make the frame include everything you want to cast a shadow on.

Example of placing the light farther away.

> **[Babylon.js Playground](https://playground.babylonjs.com/#IIZ9UU%23468)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Debugging views can be easily turned on in inspector

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/d/5/d5116a900d7a3b5c0c5ea376f5e3681ff110eefd.png)

---

<div class="post-metadata">

**Author:** ![DavidP](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/davidp/32/45669_2.png) [@DavidP](https://forum.babylonjs.com/u/DavidP)\
**Post date:** [June 2, 2024, 1:21am UTC](https://forum.babylonjs.com/t/shadow-generator-produces-wrong-shadow/50996/4 "2024-06-02T01:21:24Z")

</div>

@qq2315137135 Thank you for the solution and thank you for demo’ing BABYLON.DirectionalLightFrustumViewer - it is indeed very helpful and I did not know about it

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [June 2, 2024, 9:08am UTC](https://forum.babylonjs.com/t/shadow-generator-produces-wrong-shadow/50996/5 "2024-06-02T09:08:33Z")

</div>

If it can help, we have some docs explaining how to setup the parameters of the frustum for directional lights:

[https://doc.babylonjs.com/features/featuresDeepDive/lights/shadows#in-depth-analyzing-of-directional-light-position](https://doc.babylonjs.com/features/featuresDeepDive/lights/shadows#in-depth-analyzing-of-directional-light-position)
