Advertisement
tonynogo

Demo 07 - Rim effect

Jul 6th, 2017
8,735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Rim effect" {
  2.     Properties {
  3.         _MainTex ("Base (RGB)", 2D) = "white" {}
  4.         _RimValue ("Rim value", Range(0, 1)) = 0.5
  5.     }
  6.     SubShader {
  7.         Tags { "RenderType"="Transparent" "Queue"="Transparent" }
  8.  
  9.         CGPROGRAM
  10.         #pragma surface surf Lambert alpha
  11.  
  12.         sampler2D _MainTex;
  13.         fixed _RimValue;
  14.  
  15.         struct Input {
  16.             float2 uv_MainTex;
  17.             float3 viewDir;
  18.             float3 worldNormal;
  19.         };
  20.  
  21.         void surf (Input IN, inout SurfaceOutput o) {
  22.             half4 c = tex2D (_MainTex, IN.uv_MainTex);
  23.             o.Albedo = c.rgb;
  24.             float3 normal = normalize(IN.worldNormal);
  25.             float3 dir = normalize(IN.viewDir);
  26.             float val = 1 - (abs(dot(dir, normal)));
  27.             float rim = val * val * _RimValue;
  28.             o.Alpha = c.a * rim;
  29.         }
  30.         ENDCG
  31.     }
  32.     FallBack "Diffuse"
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement