Advertisement
Deozaan

Soph_toonBumpOutline Shader

Oct 1st, 2013
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Soph_toonBumpOutline" {
  2.         Properties {
  3.                 _OutlineColor ("Outline Color", Color) = (0,0,0,1)
  4.                 _Outline ("Outline width", Range (.002, 0.03)) = .005
  5.                 _MainTex ("Base (RGB)", 2D) = "white" {}
  6.                 _BumpMap ("Bumpmap", 2D) = "bump" {}
  7.                 _Ramp ("ramp light", 2D) = "gray" {}
  8.         }
  9.        
  10. CGINCLUDE
  11. #include "UnityCG.cginc"
  12.  
  13. struct appdata {
  14.         float4 vertex : POSITION;
  15.         float3 normal : NORMAL;
  16. };
  17.  
  18. struct v2f {
  19.         float4 pos : POSITION;
  20.         float4 color : COLOR;
  21. };
  22.  
  23. uniform float _Outline;
  24. uniform float4 _OutlineColor;
  25.  
  26. v2f vert(appdata v) {
  27.         // just make a copy of incoming vertex data but scaled according to normal direction
  28.         v2f o;
  29.         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  30.  
  31.         float3 norm   = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal);
  32.         float2 offset = TransformViewToProjection(norm.xy);
  33.  
  34.         o.pos.xy += offset * o.pos.z * _Outline;
  35.         o.color = _OutlineColor;
  36.         return o;
  37. }
  38. ENDCG
  39.        
  40.         SubShader {
  41.                 Tags { "RenderType" = "Opaque" }
  42.                 CGPROGRAM
  43.                 #pragma surface surf ToonRamp
  44.                 //#pragma target 2.0
  45.  
  46.                 sampler2D _Ramp;
  47.                
  48.                
  49.                 half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
  50.                        
  51.                                
  52.                         half diff = max (0, dot ( lightDir, s.Normal ));
  53.                        
  54.                         half4 res;
  55.                         res.rgb = _LightColor0.rgb * diff;
  56.                         res *= atten * 2.0;
  57.                        
  58.                         float4 finalThing = tex2D(_Ramp,res.xy);
  59.                         finalThing.rgb *= s.Albedo.rgb;
  60.                        
  61.                         return finalThing;
  62.                 }
  63.                
  64.                
  65.                
  66.                 struct Input {
  67.                         float2 uv_MainTex;
  68.                         float2 uv_BumpMap;
  69.                 };
  70.                 sampler2D _MainTex;
  71.                 sampler2D _BumpMap;
  72.                 void surf (Input IN, inout SurfaceOutput o) {
  73.                        
  74.                         o.Alpha = 1.0;
  75.                         //o.Albedo = 0.0;
  76.                         o.Emission = 0.0;
  77.                         o.Gloss = 0.0;
  78.                         o.Specular = 0.0;
  79.                        
  80.                         o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
  81.                         o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
  82.                 }
  83.         ENDCG
  84.        
  85.         Pass {
  86.                         Name "OUTLINE"
  87.                         Tags { "LightMode" = "Always" }
  88.                         Cull Front
  89.                         ZWrite On
  90.                         ColorMask RGB
  91.                         Blend SrcAlpha OneMinusSrcAlpha
  92.                         //Offset 50,50
  93.  
  94.                         CGPROGRAM
  95.                         #pragma vertex vert
  96.                         #pragma fragment frag
  97.                         half4 frag(v2f i) :COLOR { return i.color; }
  98.                         ENDCG
  99.                 }
  100.        
  101.         }
  102. FallBack "Diffuse"
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement