Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

(LWRP) i can't change a material property without breaking batching ?

Discussion in 'Graphics Experimental Previews' started by Gruguir, Jan 11, 2019 at 2:22 PM.

  1. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    306
    (UT 2018.3 /LWRP 4.6.0) In standard RP i used material property blocks to modify properties at runtime.
    Now batching breaks as soon as i change a property value. Is there a specific way to do that ? I'm lost with SRP and wasn't able to find infos on this topic.
     
    Shorely likes this.
  2. Andre_Mcgrail

    Andre_Mcgrail

    Unity Technologies

    Joined:
    Dec 9, 2016
    Posts:
    111
    Some properties are wrapped behind shader features(shader keywords), this can lead to using an actual different shader all together if changed meaning even using a MaterialPropertyBlock will not work as they will be different shaders. This will only happen if you are changing any boolean or adding a texture and the other material has no texture applied.

    Do you have an example of what you are changing via the MPB and which LWRP shader?
     
  3. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    306
    @Andre_Mcgrail
    Thanks for your support. I've done some more tests. It looks like in 2018.3 i can't keep my meshes to batch as soon as i change a property value. I made a test with simple cubes sharing an LWRP unlit material (with a checker texture), changing only the "Color" property value at runtime. Each cube is then drawn separately.

    Here is the code :

    Code (CSharp):
    1.  
    2. MaterialPropertyBlock props = new MaterialPropertyBlock();
    3.  
    4.         foreach (GameObject cube in cubes)
    5.         {
    6.             float r = Random.Range(0.0f, 1.0f);
    7.             float g = Random.Range(0.0f, 1.0f);
    8.             float b = Random.Range(0.0f, 1.0f);
    9.  
    10.             rend = cube.GetComponent<Renderer>();
    11.             props.SetColor("_Color", new Color(r, g, b, 1f));
    12.             rend.SetPropertyBlock(props);
    13.         }
    14.  
    But if i do the same test in UT 2019.1.0.a13/LWRP 5.2.3 with the 'SRP Batcher' experimental feature then the cubes share the same draw pass, without using MPB, simply calling "rend.material.SetColor("_Color", new Color(r, g, b));".

    I didn't see the SRP Batcher option in UT 2018.3/LWRP 4.6.

    My results FWIW :
    • In any case (2018.3/2019a, and latest matching LWRP) using dynamic batching it breaks
    • In 2019 i can use 'material.SetColor' with SRP Batcher on, (with GPU instancing ticked or not) to get all cubes drawn all at once. 'Batches' keeps increasing in Game stats, but 'Saved by batching' gives me a negative number.
    Honestly i'm not sure where i may hit a bug or misunderstand/do some mistake.

    I work on a mobile VR project and i'm worried of seeing game state's batches increase even if lowering setpass calls.

    Maybe i should move back to standard RP as i'd like to stick to 2018 LTS for my project and obviously some LWRP features/fixes won't reach it.
     
  4. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    278
    If you can submit your project as bugreport we will gadly take a look at why batching is breaking when not using SRP Batcher.

    As for the SRP Batcher it will not be backported to 18.3. In fact since LWRP is experimental in 18.3 we will not give support to it in 18.3 LTS version. If you can't update to 2019 I'd recommend sticking with Builtin render pipelines.
     
  5. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    306
    phil_lira likes this.