Advertisement
Guest User

ToonDecal.shader

a guest
Oct 13th, 2018
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Toon/Lit Decal Effect" {
  2.     Properties {
  3.         _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
  4.         _MainTex ("Base (RGB)", 2D) = "white" {}   
  5.         _DecalTex("Decal (RGBA)", 2D) = "black" {}
  6.         _EmissionTex("Emission (RGBA)", 2D) = "black" {}
  7.         _Ramp ("Toon Ramp (RGB)", 2D) = "black" {}
  8.     }
  9.  
  10.     SubShader {
  11.         Tags { "RenderType"="Transparent" }
  12.        
  13.         Blend One OneMinusSrcAlpha
  14.         ColorMask RGBA
  15.         CGPROGRAM
  16.         #pragma surface surf ToonRamp keepalpha
  17.  
  18.         sampler2D _Ramp;
  19.  
  20.         // custom lighting function that uses a texture ramp based
  21.         // on angle between light direction and normal
  22.         #pragma lighting ToonRamp exclude_path:prepass
  23.         inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten) {
  24.             #ifndef USING_DIRECTIONAL_LIGHT
  25.             lightDir = normalize(lightDir);
  26.             #endif
  27.  
  28.             half d = dot (s.Normal, lightDir)*0.5 + 0.5;
  29.             half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
  30.  
  31.             half4 c;
  32.             c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  33.             c.a = s.Alpha;
  34.             return c;
  35.         }
  36.  
  37.         sampler2D _MainTex, _DecalTex, _EmissionTex;
  38.         float4 _Color;
  39.  
  40.         struct Input {
  41.             float2 uv_MainTex : TEXCOORD0;
  42.             float2 uv2_DecalTex : TEXCOORD1;
  43.         };
  44.  
  45.         void surf (Input IN, inout SurfaceOutput o) {
  46.             half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  47.             float4 d = tex2D(_DecalTex, IN.uv2_DecalTex);
  48.             float4 e = tex2D(_EmissionTex, IN.uv2_DecalTex);   
  49.             o.Albedo = (c.rgb * (1-d.a))+ (d * 2);
  50.             o.Emission = (e * 10);         
  51.             o.Alpha = c.a ;
  52.         }
  53.  
  54.         ENDCG
  55.     }
  56.  
  57.     Fallback "Diffuse"
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement