# Shadow Catcher Material

**URL:** <https://community.nianticspatial.com/t/shadow-catcher-material/3213>\
**Category:** I'm Stuck\
**Created:** [January 16, 2023, 7:23pm UTC](https://community.nianticspatial.com/t/shadow-catcher-material/3213 "2023-01-16T19:23:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tobias\_Reidl](https://sea2.discourse-cdn.com/niantic/user_avatar/community.nianticspatial.com/tobias_reidl/32/1688_2.png) [@Tobias\_Reidl](https://community.nianticspatial.com/u/Tobias_Reidl)\
**Post date:** [January 16, 2023, 7:23pm UTC](https://community.nianticspatial.com/t/shadow-catcher-material/3213/1 "2023-01-16T19:23:43Z")

</div>

_Include the following details (edit as applicable):_

- **Issue category** : Real-time Mapping-Depth / ARDK Documentation / Sample App aka ‘AR Developer Tools
- **Device type & OS version** : Android / iOS
- **Host machine & OS version** : Mac Ventura, M1
- **Issue Environment** : Unity Mock / On Device
- **Xcode version** :
- **ARDK version** : 2.3.1.
- **Unity version** : 2021.3.16

Description of the issue:

Hi y’all. I’m trying to create / find a material / shader, that serves as a shadow caster only, meaning I can attach it to detected planes / meshes or onto a normal Plane game object and it will only cast shadows from other objects.

I found a few tutorials on how to do that in URP:

> **[Realtime AR Shadows – Unity Shader Graph – BrownBot](https://brownbot.com/2021/03/09/realtime-ar-shadows-unity-shader-graph/)**

[![](https://us1.discourse-cdn.com/niantic/original/2X/0/0844760df06f9cf5a0fd05590c7a88628c820870.jpeg "Unity AR Foundation - How To Apply Shadows To Transparent AR Planes For More Realistic AR?") ](https://www.youtube.com/watch?v=QbAY963xp0c)

However none seems to work for me. Would be happy about some advice / material that works with ARDK

cheers and thanks in advance  
Tobi

---

<div class="post-metadata">

**Author:** ![Merijn\_Kersten](https://sea2.discourse-cdn.com/niantic/user_avatar/community.nianticspatial.com/merijn_kersten/32/1277_2.png) [@Merijn\_Kersten](https://community.nianticspatial.com/u/Merijn_Kersten)\
**Post date:** [January 17, 2023, 9:26am UTC](https://community.nianticspatial.com/t/shadow-catcher-material/3213/2 "2023-01-17T09:26:47Z")

</div>

Hey @Tobias_Reidl

Here is a shader that i use in some of my AR projects to cast shadows on planes:  
Shader “URP AR Shadow Receiver”  
{  
Properties  
{  
\_ShadowColor (“Shadow Color”, Color) = (0.35,0.4,0.45,1.0)  
}

```
SubShader
{
    Tags
    {
        "RenderPipeline"="UniversalPipeline"
        "RenderType"="Transparent"
        "Queue"="Transparent-1"
    }

    Pass
    {
        Name "ForwardLit"
        Tags { "LightMode" = "UniversalForward" }

        Blend DstColor Zero, Zero One
        Cull Back
        ZTest LEqual
        ZWrite Off

        HLSLPROGRAM
        #pragma vertex vert
        #pragma fragment frag

        #pragma prefer_hlslcc gles
        #pragma exclude_renderers d3d11_9x
        #pragma target 2.0

        #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
        #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
        #pragma multi_compile _ _SHADOWS_SOFT
        #pragma multi_compile_fog

        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"

        CBUFFER_START(UnityPerMaterial)
        float4 _ShadowColor;
        CBUFFER_END

        struct Attributes
        {
            float4 positionOS : POSITION;
            UNITY_VERTEX_INPUT_INSTANCE_ID
        };

        struct Varyings
        {
            float4 positionCS : SV_POSITION;
            float3 positionWS : TEXCOORD0;
            float fogCoord : TEXCOORD1;
            UNITY_VERTEX_INPUT_INSTANCE_ID
            UNITY_VERTEX_OUTPUT_STEREO
        };

        Varyings vert (Attributes input)
        {
            Varyings output = (Varyings)0;

            UNITY_SETUP_INSTANCE_ID(input);
            UNITY_TRANSFER_INSTANCE_ID(input, output);
            UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);

            VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
            output.positionCS = vertexInput.positionCS;
            output.positionWS = vertexInput.positionWS;
            output.fogCoord = ComputeFogFactor(vertexInput.positionCS.z);

            return output;
        }

        half4 frag (Varyings input) : SV_Target
        {
            UNITY_SETUP_INSTANCE_ID(input);
            UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);

            half4 color = half4(1,1,1,1);

        #ifdef _MAIN_LIGHT_SHADOWS
            VertexPositionInputs vertexInput = (VertexPositionInputs)0;
            vertexInput.positionWS = input.positionWS;

            float4 shadowCoord = GetShadowCoord(vertexInput);
            half shadowAttenutation = MainLightRealtimeShadow(shadowCoord);
            color = lerp(half4(1,1,1,1), _ShadowColor, (1.0 - shadowAttenutation) * _ShadowColor.a);
            color.rgb = MixFogColor(color.rgb, half3(1,1,1), input.fogCoord);
        #endif
            return color;
        }

        ENDHLSL
    }
}

```

}

But be aware that for this to work you have to toggle “transparent recieve shadows” on in your renderer asset here:  
 ![Screenshot 2023-01-17 at 10.25.11](https://us1.discourse-cdn.com/niantic/original/2X/7/736bfd1f563b5265b1472d40c753f34c175add88.png)

---

<div class="post-metadata">

**Author:** ![Dylan\_Smit](https://sea2.discourse-cdn.com/niantic/user_avatar/community.nianticspatial.com/dylan_smit/32/562_2.png) [@Dylan\_Smit](https://community.nianticspatial.com/u/Dylan_Smit)\
**Post date:** [January 17, 2023, 9:38am UTC](https://community.nianticspatial.com/t/shadow-catcher-material/3213/3 "2023-01-17T09:38:03Z")

</div>

If you want a premade solution, I got a free version on the asset store as well:

> **[Shadow Receiver URP (AR) | VFX Shaders | Unity Asset Store](https://assetstore.unity.com/packages/vfx/shaders/shadow-receiver-urp-ar-228069)**
>
> Add depth to your next project with Shadow Receiver URP (AR) from Dev Dunk Studio. Find this & more VFX Shaders on the Unity Asset Store.

> **[Shadow Receiver URP (FREE) | VFX Shaders | Unity Asset Store](https://assetstore.unity.com/packages/vfx/shaders/shadow-receiver-urp-free-228074)**
>
> Add depth to your next project with Shadow Receiver URP (FREE) from Dev Dunk Studio. Find this & more VFX Shaders on the Unity Asset Store.

---

<div class="post-metadata">

**Author:** ![Tobias\_Reidl](https://sea2.discourse-cdn.com/niantic/user_avatar/community.nianticspatial.com/tobias_reidl/32/1688_2.png) [@Tobias\_Reidl](https://community.nianticspatial.com/u/Tobias_Reidl)\
**Post date:** [January 17, 2023, 11:28am UTC](https://community.nianticspatial.com/t/shadow-catcher-material/3213/4 "2023-01-17T11:28:50Z")

</div>

@Merijn_Kersten@Dylan_Smit , thanks a lot you guys, sadly both solutions do not work for me. The weird thing is that it seems like I do not get shadows on transparent surfaces at all despite activating Transparent Receive shadows…

Take a look at the screenshots, here I tested a normal material, semi transparent and the Shadow Receiver URP Free :

 ![Screenshot 2023-01-17 at 12.25.50](https://us1.discourse-cdn.com/niantic/original/2X/2/24c4fe44a22ff787f931761f3d67df9fd5d75af4.jpeg)

 ![Screenshot 2023-01-17 at 12.26.45](https://us1.discourse-cdn.com/niantic/original/2X/1/16b003d427c10c6855a849f6f42856fc0e37aa1a.png)  
 ![Screenshot 2023-01-17 at 12.26.58](https://us1.discourse-cdn.com/niantic/original/2X/9/92beb6fff0c15ba84aab5ad7ea8eacfae34ee2fb.png)  
 ![Screenshot 2023-01-17 at 12.27.01](https://us1.discourse-cdn.com/niantic/original/2X/e/e2652a83f5a7c4a05f13385dc21163e8cc4d4cd4.png)  
 ![Screenshot 2023-01-17 at 12.27.04](https://us1.discourse-cdn.com/niantic/original/2X/2/23f1c014f5eb2d1446826ff08d3aca9f1fc0cca2.png)

---

<div class="post-metadata">

**Author:** ![Dylan\_Smit](https://sea2.discourse-cdn.com/niantic/user_avatar/community.nianticspatial.com/dylan_smit/32/562_2.png) [@Dylan\_Smit](https://community.nianticspatial.com/u/Dylan_Smit)\
**Post date:** [January 17, 2023, 12:09pm UTC](https://community.nianticspatial.com/t/shadow-catcher-material/3213/5 "2023-01-17T12:09:22Z")

</div>

Disable shadow cascades. No free version supports it currently. Might help?

---

<div class="post-metadata">

**Author:** ![Tobias\_Reidl](https://sea2.discourse-cdn.com/niantic/user_avatar/community.nianticspatial.com/tobias_reidl/32/1688_2.png) [@Tobias\_Reidl](https://community.nianticspatial.com/u/Tobias_Reidl)\
**Post date:** [January 17, 2023, 12:14pm UTC](https://community.nianticspatial.com/t/shadow-catcher-material/3213/6 "2023-01-17T12:14:31Z")

</div>

Oh yes! Works like a charm, thanks a bunch @Dylan_Smit !

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/niantic/user_avatar/community.nianticspatial.com/system/32/13_2.png) [@system](https://community.nianticspatial.com/u/system)\
**Post date:** [January 17, 2023, 2:43pm UTC](https://community.nianticspatial.com/t/shadow-catcher-material/3213/7 "2023-01-17T14:43:33Z")

</div>

Closed on January 17, 2023, 2:43pm UTC

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