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

Question Material Instancing for URP

Discussion in 'General Graphics' started by xjjon, Aug 9, 2022.

  1. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    610
    With how SRP batcher works (and because MaterialPropertyBlock is not compatible with it), would the best way to handle per-instance material changes (such as color, emission) to be just create an instance of the material for each character that needs it at runtime?

    I'm using it for on-hit effects that flashes the meshes color to red/white/etc when taking damage or getting a status effect.

    I have tested using mpb to set per-instance color and emission and as expected it will add 1 additional URP draw call for each mpb set. However, if all the mpb are set to the same values then it doesn't result in more draw calls. However that's not very useful as it won't work when fading colors at different times.

    I also tested "cloning" the mesh's material at runtime so that each character has it's own instance of the material. This results in no additional draw calls since they can all be batched by SRP batcher (shared shader).

    I tested in a scene with 250 characters, so using mpb method resulted in 250~ calls vs 1 with cloned material instances. Which is what I expected.. but when profiling on low end android both approach had same performance (cpu/render thread ms) and no frame drops (averaged 60 fps)

    Is there something I am missing? Maybe a better way to implement this?

    Thanks