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 accessing the SV_InstanceID from Frag Function

Discussion in 'Shaders' started by Opeth001, Jan 5, 2021.

  1. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,112
    Hello Everyone,

    I'm new to shader dev and i'm trying to create a terrain shader that can be instantiated regardless of used layers. (1 Draw / SetPass call for all visible Terrain pieces)

    the shader works fine when i use MaterialPropertyBlock to access the required data but has a weird bug when I use a StructuredBuffer and access it with SV_InstanceID or when I pass it from the vert function.

    1) so how to access any ComputeBuffer from the frag function using the per instance Id knowing that im using the Graphics.DrawMeshInstancedIndirect function?

    2) what's the difference between MaterialPropertyBlock and ComputeBuffer and which one is better for performance ?
    -from what I understood:
    * MaterialPropertyBlock has a limit of 1023 property per MaterialPropertyBlock instance.
    * it cant be filled from a Compute Shader which prevent devs from using GPU Frustum Culling..

    Thanks!