# Occlusion shader for built-in render pipeline - video recording issues

**URL:** https://forum.magicleap.cloud/t/occlusion-shader-for-built-in-render-pipeline-video-recording-issues/2346
**Category:** Unity Development
**Tags:** shaders, mixed-reality-cam
**Created:** [August 9, 2023, 3:08pm UTC](https://forum.magicleap.cloud/t/occlusion-shader-for-built-in-render-pipeline-video-recording-issues/2346 "2023-08-09T15:08:07Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![javier](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@javier](https://forum.magicleap.cloud/u/javier)
#### Post date: [August 9, 2023, 3:08pm UTC](https://forum.magicleap.cloud/t/occlusion-shader-for-built-in-render-pipeline-video-recording-issues/2346/1 "2023-08-09T15:08:07Z")

</div>

Hi Magic Leap!

I was checking out your latest OS and the video recording is now great, except we still have this issue:

> [@Occlusion shaders rendering black in video recordings](https://forum.magicleap.cloud/t/occlusion-shaders-rendering-black-in-video-recordings/1686):
>
> Hi Magic Leap I have this occlusion shader that also can receive shadows from objects, it works alright in all platforms FIgmin XR supports but in Magic Leap 2 when I actually record footage it just shows everything black: [[video recording issue with occlusion + shadow shader - unlisted] ](https://www.youtube.com/watch?v=nMKeINFcJqk) What you see in the video is a black plane, that is the floor, it should just occlude but it renders black. The same issue occurs in our other occlusion shader that doesn't use shadows at all. Ju…

We still use the built-in render pipeline, and I suspect occlusion shaders are rendering black because of that, since I've seen videos of other ML2 apps that don't suffer from this problem.

The thing is that we use the same shader on all the platforms we support, and it works great everywhere except in ML2, so I was hoping to get some help from your team. If we can fix this we'll be able to make amazing video recordings on Figmin XR.

This is the shader we use:

```auto

Shader "Brush/Special/Occlusion"
{
    Properties{
    }
    SubShader{
      Tags{"RenderType" = "Transparent"}
      LOD 100
      Cull off
      ZWrite On
      ZTest Less

      //occlusion pass
      Pass {
        Blend Zero One, Zero One
        CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag
        #pragma multi_compile_fog
        #include "UnityCG.cginc"

        struct appdata {
          float4 vertex : POSITION;
          UNITY_VERTEX_INPUT_INSTANCE_ID
        };

        struct v2f {
          float4 vertex : SV_POSITION;
          UNITY_VERTEX_OUTPUT_STEREO
        };

        v2f vert(appdata v) {
          v2f o;
          UNITY_SETUP_INSTANCE_ID(v); //Insert
          UNITY_INITIALIZE_OUTPUT(v2f, o); //Insert
          UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); //Insert

          o.vertex = UnityObjectToClipPos(v.vertex);

          return o;
        }

        fixed4 frag(v2f i) : SV_Target {
          return float4(0, 0, 0, 0);
        }
        ENDCG
      }

    }
}

```

**Unity Editor version** : 2022.2.19  
**ML2 OS version** : 1.3.1  
**MLSDK version** : unity 1.9  
**Host OS** : windows

---

<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: [August 10, 2023, 4:35pm UTC](https://forum.magicleap.cloud/t/occlusion-shader-for-built-in-render-pipeline-video-recording-issues/2346/2 "2023-08-10T16:35:11Z")

</div>

Hi @javier we are looking into this and will get back to you shortly. Thank you for your patience.

---

<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: [August 10, 2023, 5:07pm UTC](https://forum.magicleap.cloud/t/occlusion-shader-for-built-in-render-pipeline-video-recording-issues/2346/3 "2023-08-10T17:07:49Z")

</div>

Is your application using the segmented dimmer? If you are, can you confirm that the opaque visual disappears when the segmented dimmer is disabled inside you application?

---

<div class="post-metadata">

### Author: ![javier](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@javier](https://forum.magicleap.cloud/u/javier)
#### Post date: [August 10, 2023, 5:16pm UTC](https://forum.magicleap.cloud/t/occlusion-shader-for-built-in-render-pipeline-video-recording-issues/2346/4 "2023-08-10T17:16:18Z")

</div>

We are actually not using the segmented dimmer, but I'm glad you asked!

The reason we aren't using it is related to this, the automatic segmented dimmer thinks that occlusion materials should activate dimming so it makes it looks terrible.

---

<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: [August 11, 2023, 9:34pm UTC](https://forum.magicleap.cloud/t/occlusion-shader-for-built-in-render-pipeline-video-recording-issues/2346/5 "2023-08-11T21:34:44Z")

</div>

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 to our voice of customer team.

Secondly, we are looking into the issue with the opaque object capture right now. It looks like our Mixed Reality Capture technique and Unity's Standard render pipeline don't play nice together. If you change to URP I have a shader that would work 😉 , I will let you know as soon as I have more information.

---

<div class="post-metadata">

### Author: ![javier](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@javier](https://forum.magicleap.cloud/u/javier)
#### Post date: [August 11, 2023, 9:55pm UTC](https://forum.magicleap.cloud/t/occlusion-shader-for-built-in-render-pipeline-video-recording-issues/2346/6 "2023-08-11T21:55:45Z")

</div>

Behold black magic!

> <https://twitter.com/javierdavalos/status/1681373624568250368>

It doesn't quite catch the shadows, you are right, they will cast again if they were to hit another surface lying underneath the table but that's pretty rare that it doesn't matter. This is captured on a Hololens 2 if you are curious. This is also enabled by default on the Magic Leap 2 build

But in any case, let's figure out what's the problem with mixed reality capture. We can't switch to URP, too many shaders, too many platforms, too much risk.

---

<div class="post-metadata">

### Author: ![paklnet](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@paklnet](https://forum.magicleap.cloud/u/paklnet)
#### Post date: [August 14, 2023, 4:44pm UTC](https://forum.magicleap.cloud/t/occlusion-shader-for-built-in-render-pipeline-video-recording-issues/2346/7 "2023-08-14T16:44:23Z")

</div>

@javier I noticed that an older version of Figmin XR (1.37.0.0; FigminXR\_ML2\_v8.apk) had a built in video recording without this issue. Were there any major disadvantages of having the built-in recording functionality?

@kbabilinski very curious to hear if there's a way to get this working without the switch to URP

Thank you

---

<div class="post-metadata">

### Author: ![javier](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@javier](https://forum.magicleap.cloud/u/javier)
#### Post date: [August 14, 2023, 4:57pm UTC](https://forum.magicleap.cloud/t/occlusion-shader-for-built-in-render-pipeline-video-recording-issues/2346/8 "2023-08-14T16:57:26Z")

</div>

I think the issue was always there, but the old video recordings were semi-transparent and it was harder to see. Now that the digital content is opaque it's an obvious issue.

I really hope they can fix the issue for us with the built-in render pipeline. We showcase ML2 a lot but it could be so much more if we could make use of the spatial map.

---

<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 20, 2024, 11:08am UTC](https://forum.magicleap.cloud/t/occlusion-shader-for-built-in-render-pipeline-video-recording-issues/2346/9 "2024-06-20T11:08:43Z")

</div>

Hi @javier ,

I am facing a similar issue regarding the shadows and the occlusion shader rendering black in video recordings, although I am using URP. @kbabilinski mentioned he has a URP shader that could possibly solve the issue. If your issue was resolved, would you mind sharing the shader or any insights on how you fixed it? Thanks.
