# Make objects cast/receive shadows

**URL:** <https://forum.babylonjs.com/t/make-objects-cast-receive-shadows/57505>\
**Category:** Questions\
**Tags:** shadowgenerator\
**Created:** [March 30, 2025, 6:58pm UTC](https://forum.babylonjs.com/t/make-objects-cast-receive-shadows/57505 "2025-03-30T18:58:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![TadKing42](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tadking42/32/44248_2.png) [@TadKing42](https://forum.babylonjs.com/u/TadKing42)\
**Post date:** [March 30, 2025, 6:58pm UTC](https://forum.babylonjs.com/t/make-objects-cast-receive-shadows/57505/1 "2025-03-30T18:58:13Z")

</div>

In my project I have functions to create objects and light, I don’t have direct access to objects. How can I make those objects cast shadows?

```auto
    createbox(args) {
      const box = BABYLON.MeshBuilder.CreateBox(args.name, { size: 1 }, scene);
      box.position.x = args.x;
      box.position.y = args.y;
      box.position.z = args.z;
      box.rotation.x = args.rx;
      box.rotation.y = args.ry;
      box.rotation.z = args.rz;
      box.scaling.x = args.sx;
      box.scaling.y = args.sy;
      box.scaling.z = args.sz;
      box.receiveShadows = true;
      box.castShadows = true;
      material.diffuseTexture = new BABYLON.Texture(textureDataURI, scene);
      if (args.staticdynamic == 1) {
        let boxAggregate = new BABYLON.PhysicsAggregate(box, BABYLON.PhysicsShapeType.BOX, { mass: 1, restitution:0}, scene);
      }
      else{
        var boxAggregate = new BABYLON.PhysicsAggregate(box, BABYLON.PhysicsShapeType.BOX, { mass: 0 }, scene);
      }
    }

```

```auto
    addpointlight(args){
      const pointLight = new BABYLON.PointLight(args.name, new BABYLON.Vector3(args.x,args.y, args.z), scene);}

```

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [March 30, 2025, 7:10pm UTC](https://forum.babylonjs.com/t/make-objects-cast-receive-shadows/57505/2 "2025-03-30T19:10:41Z")

</div>

I believe you have the list of `args`

```auto
const shadowGenerator = new BABYLON.ShadowGenerator(1024, scene.getLightByName(args.name));

```

```auto
shadowGenerator.getShadowMap().renderList.push(scene.getMeshByName(args.name));

```

(iterate the last part through the args list)

---

<div class="post-metadata">

**Author:** ![TadKing42](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tadking42/32/44248_2.png) [@TadKing42](https://forum.babylonjs.com/u/TadKing42)\
**Post date:** [March 30, 2025, 7:12pm UTC](https://forum.babylonjs.com/t/make-objects-cast-receive-shadows/57505/3 "2025-03-30T19:12:27Z")

</div>

Args are not a list, they are just arguments. I don’t have any arrays here. Is there any way to just make it so that every object automatically casts shadows?

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [March 30, 2025, 7:44pm UTC](https://forum.babylonjs.com/t/make-objects-cast-receive-shadows/57505/4 "2025-03-30T19:44:17Z")

</div>

You need to create in shadowGenerator in your addpointlight function, then push meshes to renderList in your createbox function.

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [March 30, 2025, 7:46pm UTC](https://forum.babylonjs.com/t/make-objects-cast-receive-shadows/57505/5 "2025-03-30T19:46:25Z")

</div>

> [@TadKing42](#):
>
> I don’t have any arrays here.

Arrays will not do any harm, you may add each created mesh to some array for easy reference.

---

<div class="post-metadata">

**Author:** ![TadKing42](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tadking42/32/44248_2.png) [@TadKing42](https://forum.babylonjs.com/u/TadKing42)\
**Post date:** [March 31, 2025, 2:58pm UTC](https://forum.babylonjs.com/t/make-objects-cast-receive-shadows/57505/6 "2025-03-31T14:58:53Z")

</div>

> [@labris](#):
>
> ``
> 
> ```auto
> shadowGenerator.getShadowMap().renderList.push(scene.getMeshByName(args.name));
> 
> ```

Great, I’m doing them now. Thanks!

---

<div class="post-metadata">

**Author:** ![TadKing42](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tadking42/32/44248_2.png) [@TadKing42](https://forum.babylonjs.com/u/TadKing42)\
**Post date:** [March 31, 2025, 3:11pm UTC](https://forum.babylonjs.com/t/make-objects-cast-receive-shadows/57505/7 "2025-03-31T15:11:40Z")

</div>

Actually, if I have an array for objects and a separate array for lights (shadowgenerators), how am I supposed to run in runtime. Do shadowgenerators check if they already made some object cast shadows?

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [March 31, 2025, 3:35pm UTC](https://forum.babylonjs.com/t/make-objects-cast-receive-shadows/57505/8 "2025-03-31T15:35:23Z")

</div>

> [@TadKing42](#):
>
> Do shadowgenerators check if they already made some object cast shadows?

Yes, there is the simple check

> <https://github.com/BabylonJS/Babylon.js/blob/3f9749c80de9f775c10dc143fd30920b06168303/packages/dev/core/src/Lights/Shadows/shadowGenerator.ts#L757>
