Search Unity

Question Add shadow functionality to this shader code please

Discussion in 'Shaders' started by ketanichiwala, Jul 12, 2020.

  1. ketanichiwala

    ketanichiwala

    Joined:
    Aug 11, 2019
    Posts:
    4
    hello, thought I'd give this a go here. I'm not a programmer I'm more of an artist, I managed to find this shader which has what I need for a toon shader. unfortunately this shader does not support cast shadows. i have searched around for others that do but most toon shaders do not support both normal and ramp shading like this one does. I was hoping if somebody is willing to simply write in the code if possible. i dont know if adding in spec support aswell would be possible or even if it would look good but that would be nice. if anybody is willing to add shadow support for point lights etc to this shader i would really appreciate it thank you


    Code (CSharp):
    1. Shader "Custom/ToonRampWithNormals"
    2. {
    3.     Properties
    4.     {
    5.         _Color("Color", Color) = (1,1,1,1)
    6.         _MainTex("Albedo (RGB)", 2D) = "white" {}
    7.         _BumpMap("Bumpmap", 2D) = "bump" {}
    8.         _Ramp("Toon Ramp", 2D) = "white" {}
    9.     }
    10.         SubShader
    11.     {
    12.         Tags { "RenderType" = "Opaque" }
    13.         LOD 200
    14.  
    15.         CGPROGRAM
    16.         #pragma surface surf Ramp
    17.  
    18.         // Use shader model 3.0 target, to get nicer looking lighting
    19.         #pragma target 3.0
    20.  
    21.         sampler2D _Ramp;
    22.  
    23.         half4 LightingRamp(SurfaceOutput s, half3 lightDir, half atten) {
    24.             half NdotL = dot(s.Normal, lightDir);
    25.             half diff = NdotL * 0.5 + 0.5;
    26.             half3 ramp = tex2D(_Ramp, float2(diff,diff)).rgb;
    27.             half4 c;
    28.             c.rgb = s.Albedo * _LightColor0.rgb * ramp * atten;
    29.             c.a = s.Alpha;
    30.             return c;
    31.         }
    32.  
    33.         struct Input
    34.         {
    35.             float2 uv_MainTex;
    36.             float2 uv_BumpMap;
    37.         };
    38.  
    39.         sampler2D _MainTex;
    40.         sampler2D _BumpMap;
    41.         half _Glossiness;
    42.         fixed4 _Color;
    43.  
    44.         UNITY_INSTANCING_BUFFER_START(Props)
    45.             // put more per-instance properties here
    46.         UNITY_INSTANCING_BUFFER_END(Props)
    47.  
    48.         void surf(Input IN, inout SurfaceOutput o)
    49.         {
    50.             // Albedo comes from a texture tinted by color
    51.             fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    52.             o.Albedo = c.rgb;
    53.             o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    54.             o.Alpha = c.a;
    55.         }
    56.         ENDCG
    57.     }
    58.         FallBack "Diffuse"
    59. }
     
  2. ketanichiwala

    ketanichiwala

    Joined:
    Aug 11, 2019
    Posts:
    4
    never realized it has direct lighting shadows nevermind
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
  4. ketanichiwala

    ketanichiwala

    Joined:
    Aug 11, 2019
    Posts:
    4
  5. ketanichiwala

    ketanichiwala

    Joined:
    Aug 11, 2019
    Posts:
    4