Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Get PrimitiveID

Discussion in 'Shaders' started by Germanunkol, Oct 12, 2016.

  1. Germanunkol

    Germanunkol

    Joined:
    Oct 25, 2015
    Posts:
    11
    I read that OpenGL exposes the gl_PrimitiveID in fragment shaders, which (I believe) tells you the ID of the triangle currently being rendered.

    Is this accessible in Unity's Shader language?

    If not: My goal is to color each triangle individually without applying a texture. I want to tint each triangle of UI elements (i.e. UI Sprites) differently. Any ideas?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
    Germanunkol likes this.
  3. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    612
    bgolus likes this.
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
    What do you mean by "change SV_PrimitiveID in my shader"? You can "change" it with a geometry shader, by emitting more or less geometry, but I don't think you can restart it at 0. The OpenGL stuff you linked to happens in the CPU side rendering, not as part of the shader, and isn't something Unity exposes.
     
  5. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    612
    I don't use a geometry shader, only vert and frag with nointerpolation. I thought there might be a way to tell the GPU in my shader that it should use vertex 0 (or 1 or 2) as provoking vertex.

    "There is a way to change the provoking vertex convention:
    void glProvokingVertex(GLenum provokeMode);"

    --> https://www.khronos.org/opengl/wiki/Primitive#Provoking_vertex

    but i am completely misguided i guess :(