Search Unity

Is there any way to get the SV_PrimitiveID from within a surface shader?

Discussion in 'Shaders' started by teawrecks, May 4, 2017.

  1. teawrecks

    teawrecks

    Joined:
    Nov 1, 2014
    Posts:
    1
    Hi, new to Unity. I'm doing some procedural rendering using the MeshFilter/MeshRenderer components, and wanted to take advantage of the built in lighting system. I'm ok with using a surface shader, but I would like to color the faces based on the PrimitiveID. It seemed like the best place to get this info into a surface shader would be with a magic UNITY directive in the Input struct. Something like UNITY_PRIMITIVE_ID similar to how it's done with InstanceID here: https://docs.unity3d.com/Manual/GPUInstancing.html, but I can't find any info on such a directive existing.

    I am able to use the "Show generated code" button in Unity to view the final Cg source, and trivially edit it to add the SV_PrimitiveID argument to do what I want, I just find it strange that surface shaders don't appear to support it. Am I overlooking something?

    Thanks
     
  2. tomix1024

    tomix1024

    Joined:
    May 5, 2017
    Posts:
    8
    Has anyone figured out, how this can be done yet?

    For a classical vertex/fragment shader setup, this works, but in the surface shader setup, one has no control over the actual fragment shader input...