Search Unity

Discussion Help with Hair Shader (2 sided and Transparent/Opaque)

Discussion in 'Shaders' started by sammiie, Mar 8, 2023.

  1. sammiie

    sammiie

    Joined:
    Sep 18, 2021
    Posts:
    2
    Hello!

    I need help with my hair shader, I need to make it 2 sided and smooth on the edge. With my current shader, when I apply transparent background, the hair is being clipped. I will attach the pictures. Thank you!



    Code (CSharp):
    1. Shader "Wit/Hair"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Diffuse (RGB) Alpha (A)", 2D) = "white" {}
    6.         _Color ("Main Color", Color) = (1,1,1,1)
    7.         _Cutoff ("Alpha Cut-Off", range(0, 1)) = 0.95
    8.         _NormalTex ("Normal Map", 2D) = "bump" {}
    9.         _NormalPower ("NormalPower", range(0, 5)) = 0.75
    10.         _SpecularTex ("Specular (R) Spec Shift (G) Spec Mask (B)", 2D) = "gray" {}
    11.         _SpecularMultiplier ("Specular Multiplier", float) = 10.0
    12.        
    13.         _SpecularColor ("Specular Color", Color) = (1,1,1,1)
    14.         _SpecularMultiplier2 ("Secondary Specular Multiplier", float) = 10.0
    15.         _SpecularColor2 ("Secondary Specular Color", Color) = (1,1,1,1)
    16.         _PrimaryShift ( "Specular Primary Shift", float) = -0.01
    17.         _SecondaryShift ( "Specular Secondary Shift", float) = -0.28
    18.  
    19.         _RimColor ("Rim Color", Color) = (0,0,0,0)
    20.         _RimPower ("Rim Power", Range(1,3)) = 1.292
    21.  
    22.  
    23.         _TintColor ("Tint Color", Color) = (0,0,0)
    24.         _TintPower ("Tint Power", Range(0,1)) = 0.292
    25.  
    26.         [HideInInspector]_LogLut ("_LogLut", 2D)  = "white" {}      
    27.    
    28.  
    29.  
    30.     }
    31.  
    32.      SubShader
    33.     {
    34.         Tags { "RenderType" = "Transparent"  "Queue" = "Transparent+1" "IgnoreProjector" = "True" "DisableBatching" = "True" }
    35.  
    36.         Blend One OneMinusSrcAlpha
    37.  
    38.         LOD 0
    39.  
    40.         CGPROGRAM
    41.         #pragma surface surf Hair vertex:vert finalcolor:tonemapping alpha:blend
    42.         #pragma target 3.0
    43.  
    44.         #include "./Hair.cginc"
    45.  
    46.         void surf (Input IN, inout SurfaceOutputHair o)
    47.         {
    48.             surf_base(IN, o);
    49.             if(o.Alpha  < _Cutoff) {
    50.                 o.Alpha = o.Alpha - _Cutoff;
    51.    
    52.              }
    53.         }
    54.  
    55.         ENDCG
    56.  
    57.     }
    58.     FallBack "Mobile/VertexLit"
    59.  
    60. }
    Hair with transparent bg:
    HAIR (8).png

    Hair with white bg:
    HAIR (9).png