Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Ver. 2021.3.9 - Newly introduced error for DrawMeshInstanced calls in codes

Discussion in 'General Graphics' started by TerraUnity, Sep 3, 2022.

  1. URPian

    URPian

    Joined:
    Aug 13, 2012
    Posts:
    33
    @TerraUnity As per your post, I have filed a bug with Unity Default built-in renderer with New Incident IN-24918 in support of bug IN-24374. The environment rendered correctly and only continuous error is of
    DrawMeshInstanced does not support the shader 'TerraUnity/Standard' because it does not read any instanced properties. Try switching to DrawMeshInstancedProcedural if the shader is doing procedural instancing.

    @aleksandrk Kindly add this to the bugs related to DrawMeshInstancedProcedural
     
    TerraUnity and aleksandrk like this.
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    There can be situations where it won't show up in the editor but will happen in the player.
    It also skips the draw call, so there is a graphical issue.
     
  3. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    If it's doing this then I should be missing trees wholesale - and I'm not as per URPian in his post above, the scene renders correctly, just the log is spammed with messages.
     
    URPian likes this.
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    It would be great if you could also submit a bug report in this case - I'd like to see what's happening in your project.
     
  5. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    We are in the middle of beta testing / bug fixing our latest release, so at the moment I don't have time to create a recreation project. Our project is over 150gb in size, so it's going to take quite a bit of work to sort this out. I did try using the provided unity tools to create a stripped down recreation project but the resulting project just didn't work and was missing a lot of required files, so it will have to be done manually when I have some time.
     
  6. WillCrate

    WillCrate

    Joined:
    May 16, 2016
    Posts:
    15
    Upon updating our project from 2021.1.15f1 to 2021.3.15f1 we encountered this issue as well. It is complaining about one of our custom shaders and even a built in one for speedtree not reading any instanced properties which is incorrect as they do.

    I have debugged this issue down to calling DrawMeshInstanced where the specified camera has DepthNormals enabled. I have repro'd this successfully in a fresh Unity project with Unity's own example instanced shader and have sent those files in as a bug report under CASE IN-25241.

    In any case, here are the files that I sent in if anyone cares to test it themselves. I used the simple built in Cube mesh assigned to meshToRender, with a basic material set to the specified shader and enabled for GPU Instancing for materialToRender and the MainCamera in the default new Unity scene to cameraToUse.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class InstancedRenderer : MonoBehaviour
    6. {
    7.     public Mesh meshToRender;
    8.     public Material materialToRender;
    9.     public Camera cameraToUse;
    10.  
    11.     public int instanceCount = 10;
    12.     public int instanceRange = 10;
    13.  
    14.     protected List<Matrix4x4> instanceTransforms = new List<Matrix4x4>();
    15.     protected List<Vector4> instanceColors = new List<Vector4>();
    16.  
    17.     protected MaterialPropertyBlock materialPropertyBlock = null;
    18.  
    19.     void Start()
    20.     {
    21.         //cameraToUse.depthTextureMode = DepthTextureMode.Depth | DepthTextureMode.DepthNormals;
    22.  
    23.         // NOTE: Setting the camera's depthTextureMode to DepthNormals triggers a spamming error log:
    24.         // DrawMeshInstanced does not support the shader 'Custom/InstancedColorSurfaceShader' because it does not read any instanced properties. Try switching to DrawMeshInstancedProcedural if the shader is doing procedural instancing.
    25.         // The shader used is the example Unity gives out for instanced shaders at https://docs.unity3d.com/Manual/gpu-instancing-shader.html
    26.         cameraToUse.depthTextureMode = DepthTextureMode.DepthNormals;
    27.  
    28.         for (int i = 0; i < instanceCount; i++)
    29.         {
    30.             int rangeToUse = instanceRange;
    31.             Vector3 position = new Vector3(Random.Range(-rangeToUse, rangeToUse), Random.Range(-rangeToUse, rangeToUse), Random.Range(-rangeToUse, rangeToUse));
    32.             Quaternion rotation = Quaternion.Euler(0, Random.Range(-180, 180), 0);
    33.             Vector3 scale = Vector3.one;
    34.  
    35.             Matrix4x4 matrix = Matrix4x4.TRS(position, rotation, scale);
    36.             Vector4 color = UnityEngine.Random.value > 0.5f ? Color.red : Color.blue;
    37.  
    38.             instanceTransforms.Add(matrix);
    39.             instanceColors.Add(color);
    40.         }
    41.  
    42.         materialPropertyBlock = new MaterialPropertyBlock();
    43.  
    44.         if (instanceColors.Count > 0)
    45.         {
    46.             materialPropertyBlock.SetVectorArray("_Color", instanceColors);
    47.         }
    48.     }
    49.  
    50.     void Update()
    51.     {
    52.         if (meshToRender != null && materialToRender != null && cameraToUse != null)
    53.         {
    54.             Graphics.DrawMeshInstanced(meshToRender, 0, materialToRender, instanceTransforms, materialPropertyBlock, UnityEngine.Rendering.ShadowCastingMode.On, true, 0, cameraToUse);
    55.         }
    56.     }
    57. }
    And the shader code as found here: https://docs.unity3d.com/Manual/gpu-instancing-shader.html

    Code (CSharp):
    1. Shader "Custom/InstancedColorSurfaceShader"
    2. {
    3.     Properties
    4.     {
    5.         _Color("Color", Color) = (1,1,1,1)
    6.         _MainTex("Albedo (RGB)", 2D) = "white" {}
    7.         _Glossiness("Smoothness", Range(0,1)) = 0.5
    8.         _Metallic("Metallic", Range(0,1)) = 0.0
    9.     }
    10.  
    11.         SubShader
    12.         {
    13.             Tags { "RenderType" = "Opaque" }
    14.             LOD 200
    15.             CGPROGRAM
    16.             // Uses the physically based standard lighting model with shadows enabled for all light types.
    17.             #pragma surface surf Standard fullforwardshadows
    18.             // Use Shader model 3.0 target
    19.             #pragma target 3.0
    20.             sampler2D _MainTex;
    21.             struct Input
    22.             {
    23.                 float2 uv_MainTex;
    24.             };
    25.             half _Glossiness;
    26.             half _Metallic;
    27.             UNITY_INSTANCING_BUFFER_START(Props)
    28.                UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
    29.             UNITY_INSTANCING_BUFFER_END(Props)
    30.             void surf(Input IN, inout SurfaceOutputStandard o) {
    31.                 fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * UNITY_ACCESS_INSTANCED_PROP(Props, _Color);
    32.                 o.Albedo = c.rgb;
    33.                 o.Metallic = _Metallic;
    34.                 o.Smoothness = _Glossiness;
    35.                 o.Alpha = c.a;
    36.             }
    37.             ENDCG
    38.         }
    39.             FallBack "Diffuse"
    40. }
    Photo for proof and ease of setup:

    InstancedRendererTest.png
     
  7. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    Hi!
    I successfully reproduced the issue (finally - thanks to everyone here!).
    We'll disable it.
     
    chriscode, catfink, URPian and 2 others like this.
  8. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    That's great, but unlike others here, I saw this issue on 2020.3.40f1. Will it be addressed there also?
     
  9. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    Yes
     
    magique likes this.
  10. URPian

    URPian

    Joined:
    Aug 13, 2012
    Posts:
    33
    A welcome news! I had just upgraded from 2019 LTS to 2021 LTS and encountered this issue. Thank you @aleksandrk, @TerraUnity and contributors for their efforts and time. Hoping to avail this in the upcoming LTS release:)
     
    TerraUnity likes this.
  11. dyox

    dyox

    Joined:
    Aug 19, 2011
    Posts:
    619
    Reproductible in Unity 2022.2.0f when using Projector
     
    Last edited: Dec 13, 2022
  12. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    The fix will be in 2021.3.17f1 (to be released approximately on 19 Jan 2023).
    EDIT (16.12.2022): 2020.3.44f1 will get it as well. 2022.2 and 2023.1 to follow.
     
    Last edited: Dec 16, 2022
  13. DavidBVal

    DavidBVal

    Joined:
    Mar 13, 2017
    Posts:
    206
    2020.3.43f1 released today lists it as fixed, has anyone tried it?
     
  14. nikk98

    nikk98

    Joined:
    Mar 8, 2021
    Posts:
    43
    I'm getting this error in 2020.3.43f1, it doesn't trigger on 2020.3.38f1 and it does not trigger inthe player, with either editor version. The function I'm calling is Graphics.DrawMeshInstanced.

    The exact error is:
    ""
    DrawMeshInstanced does not support the shader 'Mobile/Diffuse' because it does not read any instanced properties. Try switching to DrawMeshInstancedProcedural if the shader is doing procedural instancing.
    ""
    The shader that is causing it is Mobile/Diffuse, which I see that it has an "Enable GPU Instancing" label on the material which is why I assume that I can use it. The meshes are rendering.

    Is this part of the bug, that a fix hasn't propagated or something I should fix?
     
  15. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    @nikk98 as I wrote above, the error will disappear in 2020.3.44f1
     
  16. chriscode

    chriscode

    Joined:
    Mar 2, 2015
    Posts:
    48
    Will this fix be coming over to LTS versions?
    ( I'm on 2020.3.42f1)
     
  17. chriscode

    chriscode

    Joined:
    Mar 2, 2015
    Posts:
    48
    Oh it's not out yet, I thought your edit was to the date: i.e. the fix was coming 16th December 2022!!
    upload_2023-1-8_0-45-53.png
     
  18. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
    Hi there! I checked Unity Hub, and it seems 2021.3.16f1 is still the LTS version. How much closer are we to the 2021.3.17f1 release? :)
     
  19. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    It looks like it should be out soon (around Fri-Mon) if nothing happens that could prevent the release.
     
  20. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
    Hi there! Any update? :)
     
  21. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    Hi! It was delayed, ETA is today - tomorrow. Again, if nothing happens :)
     
  22. msilk

    msilk

    Joined:
    May 4, 2021
    Posts:
    2
    It's out! Anyone able to verify a fix?
     
  23. PyrateAkananto

    PyrateAkananto

    Joined:
    May 8, 2018
    Posts:
    10
    According to my colleagues the problem in their projects is gone (no more error message) when using Unity version 2021.3.17f1.
     
    msilk, FargleBargle and aleksandrk like this.
  24. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    773
    I've just updated everything I have to 2021.3.17, and the errors with Vegetation Studio Pro are gone. There were a few speed bumps as usual on some projects - import errors and editor crashes mostly - but after re-importing the problematic assets, the errors and crashes stopped, and everything seems to be working normally, so it looks like this version is a winner. Thanks to @aleksandrk for your support, and everyone else for keeping the pressure on until this got resolved. :)
     
    jf3000, aleksandrk and msilk like this.
  25. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    773
    I spoke too soon. Looks like every game I build now crashes within a few minutes. After this started happening consistently on my main project, I tried doing a build on one of my smaller test projects, and it crashed too. I've had zero issues with builds crashing previously, so this seems to be a new development since upgrading. I'll do more tests and see if I can narrow it down a bit more, but has anyone else had problems with this?
     
  26. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
  27. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    773
    Probably not related to the original bug reported here, or the fix, but I've now confirmed that 3 different projects - my main one, and 2 test projects of different sizes - crash when playing builds. I was able to play the most basic of them for about 10 minutes, and thought it was going to be OK, but it eventually crashed too. I reverted my main project to Unity 2021.3.7, which I'd been using before, and have done several builds in the last couple of days, which I can play for hours with no problems. Under Unity 2021.3.17, they always crashed within the first couple of minutes. It may not be this version specifically that's responsible, but something has been introduced since 2021.3.7 that doesn't seem to like any of my projects. I'm not expecting any solutions here, but thought I'd mention it to see if others were experiencing the same thing.
     
  28. jf3000

    jf3000

    Joined:
    Dec 31, 2013
    Posts:
    166
    Upgraded to Unity 2021.3.18f1 and don't get that error message any more, thank you.
     
  29. ul_antnasce

    ul_antnasce

    Joined:
    Dec 13, 2022
    Posts:
    3
    Any updates / workarounds for this? Is the workaround to update to 2021.3.18f as per @jf3000 's comment?
     
  30. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    Yes