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

Question URP Shader Graph - Get Face Index on a Fragment shader.

Discussion in 'Universal Render Pipeline' started by DanVioletSagmiller, Dec 10, 2022.

  1. DanVioletSagmiller

    DanVioletSagmiller

    Joined:
    Aug 26, 2010
    Posts:
    203
    I'm working on code that will work with low poly models to cut out faces and change colors of other faces. I'm somewhat new to shaders.

    I'm planning to pass in a texture that is 1x300 pixels (the model I'm working with has 300 triangles), where black means hide the face, and anything else means use the color for the entire face. I cannot figure out how to get the index of the face I'm currently texturing. Is that possible? Would it require custom shader graph functions, or can I gather this info from existing shader graph nodes?

    - Thank you :)
     
  2. DanVioletSagmiller

    DanVioletSagmiller

    Joined:
    Aug 26, 2010
    Posts:
    203
    It seems I can use vertex at least for cutting the triangles out. My equations is a little off, but it seems like I need to get 3 vertices (makes sense). I.e. If the [vertex id] >= (index * 3) && [vertex id] <= (index * 3 + 2) then multiply object position by 0. It seems like this works perfectly for some triangles, but not others. Still a little lost.
     
  3. DanVioletSagmiller

    DanVioletSagmiller

    Joined:
    Aug 26, 2010
    Posts:
    203
  4. DanVioletSagmiller

    DanVioletSagmiller

    Joined:
    Aug 26, 2010
    Posts:
    203
    I would still love to find a solution, but for now I'm moving forward with C# based mesh deformations and don't have this code base to test any more.