Search Unity

SetPropertyBlock with renderer index not working during meta pass (GI)

Discussion in 'Shaders' started by LazloBonin, Jul 10, 2021.

  1. LazloBonin

    LazloBonin

    Joined:
    Mar 6, 2015
    Posts:
    813
    I use instanced materials that need to contribute to global illumination by Englighten.

    Basically, I need to pass the albedo color as a property of MaterialPropertyBlock.

    This works fine when I use Renderer.SetPropertyBlock(MaterialPropertyBlock properties), but stops working when I use Renderer.SetPropertyBlock(MaterialPropertyBlock properties, int materialIndex).

    The color is properly applied per-renderer in other shader passes (like ForwardBase etc.), but does not seem transmitted during the meta pass (Tags { "LightMode" = "Meta" }).

    The issue does not seem related to that particular property. Any MPB property passed via the indexed overload does not seem to get picked up in the shader during the meta pass.

    My meta pass is as follows:

    Code (CSharp):
    1. Pass
    2. {
    3.     Name "META"
    4.     Tags { "LightMode" = "Meta" }
    5.  
    6.     Cull Off
    7.  
    8.     CGPROGRAM
    9.  
    10.     #include "UnityStandardMeta.cginc"
    11.  
    12.     #pragma vertex vert_meta
    13.     #pragma vertex frag_meta_custom
    14.  
    15.     UNITY_INSTANCING_BUFFER_START(IB_MyCustomMeta)
    16.         UNITY_DEFINE_INSTANCED_PROP(fixed4, _AlbedoColor)
    17.     UNITY_INSTANCING_BUFFER_END(IB_MyCustomMeta)
    18.  
    19.     float4 frag_meta_custom(v2f_meta i) : SV_Target
    20.     {
    21.         FragmentCommonData data = UNITY_SETUP_BRDF_INPUT(i.uv);
    22.  
    23.         UnityMetaInput o;
    24.         UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o);
    25.  
    26.         fixed3 albedo = UNITY_ACCESS_INSTANCED_PROP(IB_MyCustomMeta, _AlbedoColor).rgb;
    27.  
    28.         #ifdef EDITOR_VISUALIZATION
    29.             o.Albedo = albedo;
    30.             o.VizUV = i.vizUV;
    31.             o.LightCoord = i.lightCoord;
    32.         #else
    33.             o.Albedo = albedo;
    34.         #endif
    35.  
    36.         o.SpecularColor = data.specColor;
    37.         o.Emission = Emission(i.uv.xy);
    38.  
    39.         return UnityMetaFragment(o);
    40.     }
    41.     ENDCG
    42. }
    43.  
    Is this a known limitation? Am I doing something wrong? I've been googling this to no avail.
     
  2. ght1875

    ght1875

    Joined:
    Jul 29, 2016
    Posts:
    32
    I encoutered this problem too.
     
  3. LazloBonin

    LazloBonin

    Joined:
    Mar 6, 2015
    Posts:
    813
    Reported the bug, case IN-8639.
     
  4. LazloBonin

    LazloBonin

    Joined:
    Mar 6, 2015
    Posts:
    813
    Got a reply from support, Unity decided they will not fix this bug.