Shadows and opacity texture

In a project of mine, I have to use opacity texture on my meshes. However while executing it, we fins that shadows rendering is not proper as it neglects opacity texture and shows the shadow of whole object.

Here’s a demo on playground:
Shadows and Opacity texture | Babylon.js Playground (

can you please help me out to achieve the same. Thank you

Hello and welcome to the Babylon community! Take a look at Shadows | Babylon.js Documentation (

Thank you for responding. I have been through this documentation. As you can see in the playground, I have used

 shadowGenerator.enableSoftTransparentShadow = true;
 shadowGenerator.transparencyShadow = true;

However results are same i.e. I get the shadow of complete mesh.

My bad, I hadn’t noticed the set flags. Let me check it again.

Oooh, got it, you have to use the texture as a diffuseTexture, not an opacity one. Shadows and Opacity texture | Babylon.js Playground ( @sebavan is this intentional?


Lol, was just on it same time and about to say the same.
From your PG, I’m also not sure what you want to achieve? Which object should have the opacity texture (the box or the sphere)?
Anyways, take a look at this

and note that:

  1. If the sphere is the final shape you want to keep on say a box object, - turning a square into a circle or a box into a sphere - , then, when working with an opacity texture, the black part is the one that shows (in case you would need to invert your opacity texture.
  2. When working with objects you want to use for shadowing, you need to set a diffuse texture and set this texture as being transparent.

@carolhmj I agree it shoud be consistent with the rest of the code if possible do you want to give it a try ?

1 Like

Wow this works. Thank you so much

I wanted to achieve the shadows that responds with the opacity texture, but as suggested by @carolhmj , by using diffuse texture we can achieve the result.

Sorry I forgot to update with the PR but you can now use the opacity texture instead of the diffuse :slight_smile: [Engine] Add a flag to use opacity instead of diffuse texture for transparent shadows. by carolhmj · Pull Request #12390 · BabylonJS/Babylon.js (

1 Like