Search Unity

Question GPU Instancing & Material buffers

Discussion in 'Shaders' started by Life_Is_Good_, Mar 6, 2023.

  1. Life_Is_Good_

    Life_Is_Good_

    Joined:
    Mar 4, 2013
    Posts:
    43
    Hi, I'm working on a foliage rendering system. Foliage is placed on my terrain. My terrain is divided up into tiles.
    Per tile I run a compute shader to produce instance data (position etc.) I then set a reference to that instance data buffer to the foliage material.
    So for example I have a material for a grass mesh. That grass material gets the instance data buffer. Finally, that material is passed to a Graphics.DrawMeshInstancedIndirect call.
    Now the issue:
    If 2 or more tiles have the same foliage type, I use the same material. Now both tiles produce instance data => the material ping pongs between those 2 instance data buffers.
    What's the best approach from here on?
    Simply copy the material such that each tile has a separate material instance?
    I've read a bit about MaterialPropertyBlocks, are those an alternative to copying the material?