Search Unity

Bug Meshes drawn using DrawMesh stops receive shadows on Android

Discussion in 'General Graphics' started by battou, Dec 8, 2020.

  1. battou

    battou

    Joined:
    Jan 25, 2011
    Posts:
    222
    I'm developing a game for Oculus Quest2 hat runs on Android. Using Unity 2020..2.0b14.

    I draw grass using DrawMesh. At max it draws around 600 meshes per frame.

    My problem is after some roaming around grass stops receiving shadows. It receives them at the start of game, but stops after some time.

    Is this a bug or its some performance saving feature of android builds?

    I specify it to do not cast shadows, but receive them. But I don't pass MaterialPropertyBlock into it, just Null. Can this cause this problem?

    Graphics.DrawMesh(grassMesh, grassMatrix, mat, 0, cam, 0, null, false, true, false);
     
  2. battou

    battou

    Joined:
    Jan 25, 2011
    Posts:
    222
    Found a possible fix for this behavior. You need to add basically empty ShadowCaster pass to your shader. Then receiving shadows dont brake so far.

    Code (CSharp):
    1.  
    2. Pass
    3.         {
    4.             Cull Off
    5.             Tags {"LightMode" = "ShadowCaster"}
    6.        
    7.             CGPROGRAM
    8.             #pragma vertex vert
    9.             #pragma fragment frag
    10.             #pragma multi_compile_shadowcaster
    11.             #include "UnityCG.cginc"
    12.        
    13.             struct v2f {
    14.             };
    15.        
    16.             v2f vert(appdata_base v)
    17.             {
    18.                 v2f o;
    19.                 return o;
    20.             }
    21.        
    22.             float4 frag(v2f i) : SV_Target
    23.             {
    24.                 return 0;
    25.             }
    26.             ENDCG
    27.         }
    28.  
     
  3. battou

    battou

    Joined:
    Jan 25, 2011
    Posts:
    222
    It will not enable shadow casting because all shadow caster code was deleted, but it some how prevents shadow receiving to break.