# Casting Shadows for Virtual Objects using Occlusion Material

**URL:** <https://forum.magicleap.cloud/t/casting-shadows-for-virtual-objects-using-occlusion-material/3634>\
**Category:** Unity Development\
**Tags:** shaders\
**Created:** [June 12, 2024, 2:42pm UTC](https://forum.magicleap.cloud/t/casting-shadows-for-virtual-objects-using-occlusion-material/3634 "2024-06-12T14:42:22Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zul01](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@Zul01](https://forum.magicleap.cloud/u/Zul01)\
**Post date:** [June 12, 2024, 2:42pm UTC](https://forum.magicleap.cloud/t/casting-shadows-for-virtual-objects-using-occlusion-material/3634/1 "2024-06-12T14:42:22Z")

</div>

Hi,

I have a virtual character in my space for which I want to cast a shadow. I can see the shadow when I use the default green material for the mesh. Is it possible to cast shadow when i make the mesh invisible/transparent?

---

<div class="post-metadata">

**Author:** ![kbabilinski](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/kbabilinski/32/19_2.png) [@kbabilinski](https://forum.magicleap.cloud/u/kbabilinski)\
**Post date:** [June 12, 2024, 7:33pm UTC](https://forum.magicleap.cloud/t/casting-shadows-for-virtual-objects-using-occlusion-material/3634/2 "2024-06-12T19:33:26Z")

</div>

Are you using URP or the standard render pipeline? The only difference between Magic Leap 2 and other platforms is that it currently uses the Alpha channel for the Segmented Dimmer. So if your application uses the dimmer, you will need to make sure that the shader clears the alpha as well as occludes the object.

---

<div class="post-metadata">

**Author:** ![Zul01](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@Zul01](https://forum.magicleap.cloud/u/Zul01)\
**Post date:** [June 12, 2024, 8:04pm UTC](https://forum.magicleap.cloud/t/casting-shadows-for-virtual-objects-using-occlusion-material/3634/3 "2024-06-12T20:04:25Z")

</div>

I am using URP and I am not utilizing the dimmer feature, however I still can't see any shadows for the virtual objects in the scene. Even in the recording, there were no shadows displayed.

---

<div class="post-metadata">

**Author:** ![kbabilinski](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/kbabilinski/32/19_2.png) [@kbabilinski](https://forum.magicleap.cloud/u/kbabilinski)\
**Post date:** [June 13, 2024, 4:05am UTC](https://forum.magicleap.cloud/t/casting-shadows-for-virtual-objects-using-occlusion-material/3634/4 "2024-06-13T04:05:56Z")

</div>

Can you provide some more information on the shader(s) you tried using?

---

<div class="post-metadata">

**Author:** ![Zul01](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@Zul01](https://forum.magicleap.cloud/u/Zul01)\
**Post date:** [June 13, 2024, 5:48am UTC](https://forum.magicleap.cloud/t/casting-shadows-for-virtual-objects-using-occlusion-material/3634/5 "2024-06-13T05:48:50Z")

</div>

I am using the Occlusion material provided in the magic leap examples which uses the following shader :

![image](https://us1.discourse-cdn.com/flex019/uploads/magicleap1/original/2X/4/43e24d468fc9ae7d601ce725602c563fb2da0735.png)

Also, the occlusion material appears black in video recordings. I came across a similar post that suggested to enable segmented dimming as a solution: [Occlusion shader video recording issues - #10 by petrebasura](https://forum.magicleap.cloud/t/occlusion-shader-video-recording-issues/2575/10)

I did not face this issue when I used the Magic Leap Example project - I didn't have the dimmer enabled and the recording seemed to render the occlusion fine.

However, for my own project which is configured with MagicLeap-MRTK, I find issues regarding the black rendering in the recordings. I tried enabling basic segmented dimming and still faced this issue. Can you please advise on how can this be fixed as I need occlusion in my project. Thanks.

---

<div class="post-metadata">

**Author:** ![kbabilinski](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/kbabilinski/32/19_2.png) [@kbabilinski](https://forum.magicleap.cloud/u/kbabilinski)\
**Post date:** [June 13, 2024, 5:49pm UTC](https://forum.magicleap.cloud/t/casting-shadows-for-virtual-objects-using-occlusion-material/3634/6 "2024-06-13T17:49:15Z")

</div>

Are you using OpenXR ?

---

<div class="post-metadata">

**Author:** ![Zul01](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@Zul01](https://forum.magicleap.cloud/u/Zul01)\
**Post date:** [June 18, 2024, 2:02pm UTC](https://forum.magicleap.cloud/t/casting-shadows-for-virtual-objects-using-occlusion-material/3634/7 "2024-06-18T14:02:32Z")

</div>

Hi,

The project has the OpenXR package installed, but it is not configured for the Android platform. I am utilizing the MLSDK provider instead. These are the project settings :

 ![image](https://us1.discourse-cdn.com/flex019/uploads/magicleap1/original/2X/1/1b1f9146b15f872eb3e366102c7ae5760e347141.png)

 ![image](https://us1.discourse-cdn.com/flex019/uploads/magicleap1/original/2X/1/11a8b01df5cdbf2e43336478cc2d6355f2c4dfa0.png)

 ![image](https://us1.discourse-cdn.com/flex019/uploads/magicleap1/original/2X/6/664d11fa86fcdde5ac87f19224673337aedacb69.png)

 ![image](https://us1.discourse-cdn.com/flex019/uploads/magicleap1/original/2X/2/2513ed05fba97eedf33ad17d6645bbb5e5f20131.png)

---

<div class="post-metadata">

**Author:** ![kbabilinski](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/kbabilinski/32/19_2.png) [@kbabilinski](https://forum.magicleap.cloud/u/kbabilinski)\
**Post date:** [June 18, 2024, 7:21pm UTC](https://forum.magicleap.cloud/t/casting-shadows-for-virtual-objects-using-occlusion-material/3634/8 "2024-06-18T19:21:51Z")

</div>

Have you tried using the changes mentioned in this guide? [Passthrough for Capture and Dimming | MagicLeap Developer Documentation](https://developer-docs.magicleap.cloud/docs/guides/unity/display/unity-passthrough/#setup)

---

<div class="post-metadata">

**Author:** ![Zul01](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@Zul01](https://forum.magicleap.cloud/u/Zul01)\
**Post date:** [June 19, 2024, 10:39am UTC](https://forum.magicleap.cloud/t/casting-shadows-for-virtual-objects-using-occlusion-material/3634/9 "2024-06-19T10:39:51Z")

</div>

Hi, I will check out this guide, although I wanted to clarify segmented dimmer is not set for my application.

Also, I came across a similar post where you mentioned you have a URP shader that could possibly resolve the issue (for occlusion and shadows I believe) :

> [@Occlusion shader for built-in render pipeline - video recording issues](https://forum.magicleap.cloud/t/occlusion-shader-for-built-in-render-pipeline-video-recording-issues/2346/5):
>
> Hi @javier I have some bad news for you, Firstly, It appears that Unity's built in renderer does not support catching shadows on transparent objects. The shaders that catch shadows render opaque with a transparent blendmode, but they still use the opaque render pass. This results in Magic Leap 2 capture to render the occluder incorrectly. In summary, rendering shadows on occluder meshes is not possible when using Unity's built in render pipeline. I have reported your use case and this issue t…

Could you please provide me the mentioned shader?

---

<div class="post-metadata">

**Author:** ![kbabilinski](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/kbabilinski/32/19_2.png) [@kbabilinski](https://forum.magicleap.cloud/u/kbabilinski)\
**Post date:** [June 19, 2024, 5:36pm UTC](https://forum.magicleap.cloud/t/casting-shadows-for-virtual-objects-using-occlusion-material/3634/10 "2024-06-19T17:36:18Z")

</div>

Unfortunately, the shader that was mentioned in that post was provided by the developer so you would need to ask him if he can share it with you.

---

<div class="post-metadata">

**Author:** ![Zul01](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@Zul01](https://forum.magicleap.cloud/u/Zul01)\
**Post date:** [June 24, 2024, 10:12am UTC](https://forum.magicleap.cloud/t/casting-shadows-for-virtual-objects-using-occlusion-material/3634/11 "2024-06-24T10:12:20Z")

</div>

Hi,

I included the code snippet provided in the Passthrough for Capture guide and it resolved the issue. Now the mesh does not appear black in the video recording. Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/magicleap1/original/1X/bd9b737a4d45ea243aa7eb177d60a773b806899a.svg) [@system](https://forum.magicleap.cloud/u/system)\
**Post date:** [July 9, 2024, 10:12am UTC](https://forum.magicleap.cloud/t/casting-shadows-for-virtual-objects-using-occlusion-material/3634/12 "2024-07-09T10:12:58Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
