Mesh Instance Receiving Shadow

Yo @Deltakosh and @sebavan … I am having issues with Mesh Instances and OVERRIDING receive shadows.

I ask ChatGPT (before i started messing with mesh instances) if can have separate receiveShadows for each instance:

can babylonjs meshinstance receive shadows

ChatGPT said:
In Babylon.js, MeshInstance (specifically, InstancedMesh) can receive shadows, but you have to enable it properly.

Here's the key:

Each InstancedMesh inherits the receiveShadows and castShadows properties from its source mesh at creation time.

However, you can override instance.receiveShadows = true manually if needed.

But it not working right. Here are a couple of playgrounds:

Not showing shadows because Line 36 sets receiveShadows = false
even though the override for the instance at Line 42 is setting receiveShadows = true

Is Working If I Enable Shadows On Source Mesh At Line 36

Aren’t I supposed to be able to set receive shadows independent of the source mesh ?

The instanced mesh will take whatever value was set on the source mesh, and you cannot update the receiveShadows field on an instance- you can see in the console the below warning is logged.

In our docs we specify the properties which can be modified here

However this line which mentions ‘Instances are supported for collisions, picking, rendering and shadows’ may be what chat was reading / interpreting

3 Likes

One of possible workarounds to use another mesh which doesn’t receive shadows - https://playground.babylonjs.com/?BabylonToolkit#9FBCRL#3

2 Likes