Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

an analogue of the material property block in URP?

Discussion in 'Universal Render Pipeline' started by Stelette, Nov 4, 2021.

  1. Stelette

    Stelette

    Joined:
    Nov 3, 2017
    Posts:
    17
    Hello, tell me in what way it is better to implement a lot of health bars when switching from embedded rendering to URP. I can have up to 300 characters in my game at the same time. In order to reduce the number of Draw Calls, I used the material property block (and in some places, as there are materials that differ only in color, but there are quite a lot of them). But there is no support for material property block in URP , how to implement such a thing (a lot of health bars) in URP? Or stay on embedded rendering?
    Thank you in advance.
     
    bugbeeb and AlexandruGD like this.
  2. peterbay

    peterbay

    Unity Technologies

    Joined:
    Nov 2, 2017
    Posts:
    100
    Material Property Block will work in URP, but it will not take the fast SRP batcher path. It should work the same as in built-in renderer.

    While not quite the same, you can create a material per character instead, which will allow them to go via the SRP batcher fast path. But I do understand that this can be a hassle to manage if it's only e.g. a color that is different.
     
  3. Stelette

    Stelette

    Joined:
    Nov 3, 2017
    Posts:
    17
    Well, for example, I have 200 characters, they have a material that is identical, except for the color. Is it preferable to use the URP feature, which should optimize shaders since only the color is different and there will be a large number of Draw Calls (I'm doing a project including for mobile platforms), or is it better to break the SRP batcher and use the Material Property Block?
     
  4. justin_sunblink

    justin_sunblink

    Joined:
    Dec 3, 2019
    Posts:
    16
    In URP it's okay to have a lot of materials since they batch by shader. The old standard pipeline worked the exact opposite, thus the outdated need for material property blocks.
     
  5. peterbay

    peterbay

    Unity Technologies

    Joined:
    Nov 2, 2017
    Posts:
    100
    What justin_sunblink said :) You should get better performance with the SRP batcher + many materials approach. This also allows the constant buffer memory to be allocated persistently per material, so it should only get re-uploaded to the GPU when you change values in the material.
     
  6. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    706
    So what is the best way to approach this in URP 2022 using Shader Graph?
    I have about 300 car in the city, and each have 4 unique color properties.
    I wouldn't want to create 300^4 amount of materials on editor.

    If batching is per-shader, does that mean I can just modify the material value through script on runtime (Creating a new unique instanced material), and then have it automatically be batched at best performance?
     
  7. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    289
    You can instantiate copies of a base material in Start and use those.. the lack of a lightweight property override system per object has really been a problem for me in URP for years.
    If your cars all have the same shader + geometry + textures (or a reasonably small set) you can look into gpu instancing if you just need multiple color properties (in a best case scenario this might be even faster than srp batching).
     
    Radivarig likes this.
  8. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    706
    Hi, just for clarificaiton, if I understand this right, its alright to create unique instanced material at runtime because it will still be batched with the SRP batcher as long as they're the same shader?
     
  9. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    289
    I want to say yes, but obviously there is a bit of memory cost associated with the additional materials but I guess it is really not that much. The SRP batcher certainly makes this approach relatively light on the cpu though.
     
    Gekigengar likes this.