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 for Strand-Based Hair and Strand Color Variation

Discussion in 'Shaders' started by dav_ege, Jul 17, 2023.

  1. dav_ege

    dav_ege

    Joined:
    Apr 22, 2019
    Posts:
    17
    Hi,

    i am currently trying to write a urp shader for the strand based hair system, this is how it is looking so far:

    upload_2023-7-17_15-38-11.png

    I am still inexperienced with shaders but i have not found a lot of examples for the strand based hair system, apart from the enemies demo, which is in hdrp and way too complex for me to understand.
    I have two questions, first of all i tried to write a shader that randomly interpolates the color for each strand between two given colors, but my result is not interpolated but each strand is always either the first or second color, as can be seen here:
    upload_2023-7-17_15-41-33.png
    As i understand it, the random range node should give me a value between 0 and 1, but it seems to always return either 0 or 1. Why is that?

    My second question is more general, are there any examples of realistic hair shaders with the strand based system in urp that i might take a look at, or tutorials explaining the HairVertex and HairVolume Node? I have not found any documentation about them.
    Thanks for any help!
     

    Attached Files:

  2. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    625
    Hi, you can find a physical hair shader graph extension (for URP) in Unity's HairFX URP repository. (no need to import the HairFX Core package)

    Then you can import the HDRP shader graph (and subgraphs) from enemies demo or the hair sample demo and slightly adjust it in URP.

    That's weird. It should be a different integer for each hair strand.
    HairVertex.jpg
     
    dav_ege likes this.
  3. dav_ege

    dav_ege

    Joined:
    Apr 22, 2019
    Posts:
    17
    Thank you! This just what i needed. :)
    I implemented what i could from the enemies hair shader. On that note, do you happen to know why the alpha value of the fragment shader does not seem to do anything? Is it not compatible with the hair instance?