# Issue with a spotlight

**URL:** <https://forum.babylonjs.com/t/issue-with-a-spotlight/39797>\
**Category:** Questions\
**Created:** [April 11, 2023, 3:26pm UTC](https://forum.babylonjs.com/t/issue-with-a-spotlight/39797 "2023-04-11T15:26:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bvaisman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bvaisman/32/20835_2.png) [@bvaisman](https://forum.babylonjs.com/u/bvaisman)\
**Post date:** [April 11, 2023, 3:26pm UTC](https://forum.babylonjs.com/t/issue-with-a-spotlight/39797/1 "2023-04-11T15:26:43Z")

</div>

Hi everybody,

I have 2 issues with my spotlight

1 - Why is the light so shiny on the ground and so dull on the table ?

2 - Why can’t I see the shadows of the table on the ground ?

Here’s the PG :

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

If anybody could help…

Thanks in advance,

Boris

---

<div class="post-metadata">

**Author:** ![srzerbetto](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/srzerbetto/32/20941_2.png) [@srzerbetto](https://forum.babylonjs.com/u/srzerbetto)\
**Post date:** [April 11, 2023, 4:55pm UTC](https://forum.babylonjs.com/t/issue-with-a-spotlight/39797/2 "2023-04-11T16:55:42Z")

</div>

Hey @bvaisman , how are you doing?

For the shadows on the ground. The correct way to add you object to the ShadowGenerator would be to use the [addShadowCaster](https://doc.babylonjs.com/playground?type=code&q=addShadowCaster) helper function.

Your bias values also seemed to be wrong (I’m not sure why), but removing it seems to make the scene look right.

[Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#LHA8BA#3)

---

<div class="post-metadata">

**Author:** ![Dok11](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dok11/32/25754_2.png) [@Dok11](https://forum.babylonjs.com/u/Dok11)\
**Post date:** [April 11, 2023, 4:56pm UTC](https://forum.babylonjs.com/t/issue-with-a-spotlight/39797/3 "2023-04-11T16:56:13Z")

</div>

1. You have a point light under the table

2. Add all meshes to generator:

```auto
    data.meshes.forEach(x => {
       shadowGenerator.getShadowMap().renderList.push(x);
    });

```

And tune bias

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/4/540a12e0f174c448822eca75f9a9ad7a8d9fa2a8.jpeg)

---

<div class="post-metadata">

**Author:** ![bvaisman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bvaisman/32/20835_2.png) [@bvaisman](https://forum.babylonjs.com/u/bvaisman)\
**Post date:** [April 12, 2023, 7:41am UTC](https://forum.babylonjs.com/t/issue-with-a-spotlight/39797/4 "2023-04-12T07:41:58Z")

</div>

Ok @srzerbetto , you’ve found the solution, thanks very much .

But i don’t understand why _the shadowGenerator.addShadowCaster(mesh, true)_ function works and the _shadowGenerator.getShadowMap().renderList.push(mesh)_ does not.

When can we use the first and the second ?

---

<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:** [April 12, 2023, 9:12am UTC](https://forum.babylonjs.com/t/issue-with-a-spotlight/39797/5 "2023-04-12T09:12:55Z")

</div>

It’s the same thing, but make sure that `shadowGenerator.getShadowMap().renderList` is not `null` (initialize it with an empty array).

---

<div class="post-metadata">

**Author:** ![bvaisman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bvaisman/32/20835_2.png) [@bvaisman](https://forum.babylonjs.com/u/bvaisman)\
**Post date:** [April 12, 2023, 9:19am UTC](https://forum.babylonjs.com/t/issue-with-a-spotlight/39797/6 "2023-04-12T09:19:45Z")

</div>

No, i’m sorry @Evgeni_Popov but it does not work, even if I initialise my array.

My PG with _shadowGenerator.getShadowMap().renderList.push(mesh)_

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

My PG with _shadowGenerator.addShadowCaster(mesh, true)_

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

Anyway, the solution has been found but maybe it’s a bug with the spotlights. I always use the first syntax which works with directional lights and i thought it worked the same way with spotlights.

---

<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:** [April 12, 2023, 9:44am UTC](https://forum.babylonjs.com/t/issue-with-a-spotlight/39797/7 "2023-04-12T09:44:43Z")

</div>

The difference is that you pass `true` to `addShadowCaster`, which will also add all descendants of the mesh to the array, whereas `push(mesh)` only adds `mesh` to the array.

An equivalent of `addShadowCaster(mesg, true)` would be something like `shadowGenerator.getShadowMap().renderList.push(mesh, ...mesh.getChildMeshes(false))`.

---

<div class="post-metadata">

**Author:** ![bvaisman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bvaisman/32/20835_2.png) [@bvaisman](https://forum.babylonjs.com/u/bvaisman)\
**Post date:** [April 12, 2023, 11:54am UTC](https://forum.babylonjs.com/t/issue-with-a-spotlight/39797/8 "2023-04-12T11:54:21Z")

</div>

Ok, you’re right, that was not exactly the same code…
