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

A few questions about URP/SRP

Discussion in 'Universal Render Pipeline' started by Chris-Trueman, Feb 24, 2020.

  1. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,260
    I have been searching for answers to some questions I have about URP and cannot find them.

    Using MaterialPropertyBlock breaks SRP batching. So what is the proper way to change material properties without creating new material instances for each object that wants to change its properties?

    Also how do you set vsync, cause setting it the usual way doesn't change anything.
     
    Gekigengar likes this.
  2. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,260
    I stumbled apon where to set vsync in the editor. In the game view drop down where you set the aspect ration/screen size, there is a check box for vsync in the game view only. I checked the box and it worked, got better performance too.

    As to the main question. What is the proper way to set material properties with SRP?

    I think, at the moment, it seems there is no other way. Each object that needs to change its values independent of other objects, would need to create its own. Each object needs its own MaterialPropertyBlock with the built in renderer, which should be more lightweight than a material instance taking less memory. I'm sure its not a big problem, and it may only affect mobile projects with less memory available.
     
  3. Fewes

    Fewes

    Joined:
    Jul 1, 2014
    Posts:
    259
    Using different MaterialPropertyBlocks has always disabled batching (as batching only works if the material/properties are the same). The only way AFAIK to draw multiple instances of the same object with different properties is to use instancing and shader uniform arrays.
    Renderers using the same MaterialPropertyBlocks should be batched together though.
     
  4. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,260
    With the SRP batcher it batches by shader variant. So with materials you can change properties or create new materials based off of the same shader and it will still be batched. It will need to upload the data to the GPU buffer, but it will batch. MaterialPropertyBlocks work great with the built in renderer's instancing. I keep trying to use them and end up using them wrong, as I misunderstand what they are used for.

    If I change the properties via renderer.material, draw calls remain the same only a new material instance is created and the GPU buffer gets modified. I am using instancing, but with shader graph shaders, I have no way to tell unity which data I want to be per renderer(the instanced data). This doesn't seem necessary with the SRP batcher, it uses instancing techniques to batch more effectively at the shader level with material data buffered on the GPU. So in doing what 99% of new people are doing(modifying the material directly) the new SRP batcher will still batch.
     
  5. Fewes

    Fewes

    Joined:
    Jul 1, 2014
    Posts:
    259
    My bad, I didn't realize the SRP batcher worked differently from the old ways!
    The docs state that material property blocks are incompatible with the SRP batcher. Unless you are creating thousands of material instances I don't think you need to worry about the memory impact of doing so. If your use case requires drawing that many variations of objects, you are probably better of using something like DrawMeshInstancedIndirect.