Search Unity

Surface shader appropriate for fur?

Discussion in 'Getting Started' started by Simon-O, Mar 11, 2015.

  1. Simon-O

    Simon-O

    Joined:
    Jan 22, 2014
    Posts:
    51
    So... I've decided to throw myself into shaders and try to implement a fur effect (actually, grass), I've seen some code which works by doing 5-60 passes, improving quality as it goes.

    I'm completely unfamiliar with Unity's approach to shaders, so am unsure if a surface shader is appropriate?

    The manual says (my emphasis):

    Which seems promising. I'd like to template/define a method for what each pass looks like and call it a variable number of times (I'd like the number of passes to be configurable if possible). Step one is to get multiple passes working, however, I seem to be failing quite hard. I've got two issues which may be related:

    > I can't work out how to execute a variable number of passes
    > I can't get multiple consecutive CGPROGRAMs to blend their output

    My current test case to figure this out is:

    Code (CSharp):
    1.  
    2. Shader "Custom/Grass" {
    3.     Properties {
    4.         _Color ("Tint", Color) = (1,1,1,1)
    5.         _MainTex ("Color (RGBA)", 2D) = "white" {}
    6.         _Fade ("Fade", Range(0,1)) = 0
    7.     }
    8.     SubShader {
    9.         Tags { "RenderType"="Opaque" "Queue" = "Geometry+1" }
    10.         LOD 200
    11.  
    12.  
    13.  
    14.         Blend SrcAlpha OneMinusSrcAlpha
    15.  
    16.         CGPROGRAM
    17.             #pragma surface surf Standard fullforwardshadows
    18.             #pragma target 3.0
    19.  
    20.             sampler2D _MainTex;
    21.  
    22.             struct Input {
    23.                 float2 uv_MainTex;
    24.             };
    25.  
    26.             fixed4 _Color;
    27.  
    28.             void surf (Input IN, inout SurfaceOutputStandard o) {
    29.                 fixed4 c = tex2D (_MainTex, IN.uv_MainTex);// * _Color;
    30.                 o.Albedo = c.rgb;
    31.                 o.Alpha = c.a;
    32.             }
    33.         ENDCG
    34.  
    35.  
    36.  
    37.         CGPROGRAM
    38.             #pragma surface surf Standard fullforwardshadows
    39.             #pragma target 3.0
    40.  
    41.             struct Input {
    42.                 float2 uv_MainTex;
    43.             };
    44.  
    45.             fixed4 _Color;
    46.             float _Fade;
    47.  
    48.             void surf (Input IN, inout SurfaceOutputStandard o) {
    49.                 fixed4 c = fixed4(0,0,1,_Fade);
    50.                 o.Albedo = c.rgb;
    51.                 o.Alpha = c.a;
    52.             }
    53.         ENDCG
    54.     }
    55.     FallBack "Diffuse"
    56. }
    I'd expect that as _Fade is varied, the shader would fade between the input texture and blue, however I just get solid blue.

    What am I missing? Are surface shaders just not appropriate for this scenario?

    Thanks for any help you can provide.
     
    Last edited: Mar 11, 2015