Advertisement
Guest User

ToonGlass.shader

a guest
Oct 15th, 2020
1,996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Toon/Lit Glass" {
  2.     Properties{
  3.         [Header(Main)]
  4.         _Color("Main Color", Color) = (1,1,1,0.2)
  5.         _SColor("Specular Color", Color) = (1,1,1,1)      
  6.         [Header(Light Direction Specular)]
  7.         _SpecSize("Light Direction Specular Size", Range(0.65,0.999)) = 0.9 // specular size
  8.         _SpecOffset("Light Direction Specular Offset", Range(0.5,1)) = 0.6 // specular offset of the spec Ramp
  9.         _Offset2("LightDir Spec Smoothness", Range(0,1)) = 0.05
  10.         [Header(View Direction Specular)]
  11.         _SpecSize2("View Specular", Range(0.65,0.999)) = 0.9 // specular size
  12.         _Offset("View Spec Smoothness", Range(0,1)) = 0.1
  13.         [Header(Outer Rim)]
  14.         _RimPower2("Rim Offset Out Rim", Range(0,4)) = 0.7
  15.         _RimColor2("Outer Rim Color", Color) = (0.49,0.94,0.64,1)
  16.         _OutRimCutoff("Out Rim Cutoff Inner", Range(0,1)) = 0
  17.         [Header(Inner Fresnel)]
  18.         _RimPower("Rim Offset Inner Fresnel", Range(0,4)) = 1.2
  19.         _RimColor("Inner Fresnel Rim Color", Color) = (0.49,0.94,0.64,1)      
  20.         _FresnelInner("Fresnell Rim Cutoff", Range(0,2)) = 0.7      
  21.     }
  22.  
  23.         SubShader{
  24.         Tags{ "Queue" = "Transparent"}
  25.         LOD 200
  26.         Blend SrcAlpha OneMinusSrcAlpha
  27.  
  28.         CGPROGRAM
  29. #pragma surface surf ToonRamp keepalpha
  30.        
  31.     // custom lighting function that uses a texture ramp based
  32.     // on angle between light direction and normal
  33. #pragma lighting ToonRamp exclude_path:prepass
  34.     inline half4 LightingToonRamp(SurfaceOutput s, half3 lightDir, half atten)
  35.     {
  36. #ifndef USING_DIRECTIONAL_LIGHT
  37.         lightDir = normalize(lightDir);
  38. #endif
  39.  
  40.         float d = dot(s.Normal, lightDir);
  41.         float dfwidth = fwidth(d);
  42.         float ramp = smoothstep(0, dfwidth, d);    
  43.         half4 c;
  44.         c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  45.         c.a = s.Alpha;
  46.         return c;
  47.     }
  48.  
  49.    
  50.     float4 _Color;
  51.     float4 _SColor; // specular color
  52.     float _SpecSize, _SpecSize2; // specular size
  53.     float _SpecOffset; // offset specular ramp
  54.     float _Offset, _Offset2; // specular fade offset
  55.     float4 _RimColor, _RimColor2; // fresnel rim color
  56.     float _RimPower, _RimPower2; // rim offsets
  57.     float _FresnelInner, _OutRimCutoff; // cutoffs
  58.    
  59.  
  60.     struct Input {    
  61.         float3 viewDir; // view direction from camera
  62.     };
  63.  
  64.     void surf(Input IN, inout SurfaceOutput o) {
  65.  
  66.         // lights
  67.         float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);            
  68.         half lightDot = dot(o.Normal, lightDirection -IN.viewDir)*0.5 + _SpecOffset; // basing on normal and light direction and view direction
  69.        
  70.         // inner glow and outer rim
  71.         float outerrim = _RimPower - saturate(dot(IN.viewDir, o.Normal)); // calculate fresnel rim
  72.         float innerglow = _RimPower2 - saturate(dot(IN.viewDir, o.Normal)); // calculate fresnel rim
  73.         innerglow =  smoothstep(0.5, 0.5 + _OutRimCutoff, innerglow) * _RimColor2.a;
  74.         outerrim = (1-smoothstep(0.5 - _FresnelInner, 0.5, outerrim)) * _RimColor.a;
  75.      
  76.         // make it glow
  77.         o.Emission = _RimColor.rgb * pow(outerrim, 1.5); // fresnel rim
  78.         o.Emission += _RimColor2.rgb * pow(innerglow, 1.5); // inner glow fresnel
  79.  
  80.         // view specular
  81.         half viewSpec =  saturate(dot(o.Normal, (IN.viewDir))); // basing on normal and light direction
  82.        
  83.         float viewSpecLine = (smoothstep(_SpecSize2, _SpecSize2 + _Offset, viewSpec)) * 10;
  84.        
  85.         // light dir specular
  86.         float specular= (smoothstep(_SpecSize, _SpecSize + _Offset2, lightDot)) * 10;
  87.        
  88.         o.Emission += saturate(viewSpecLine + specular) * _SColor * 2;
  89.        
  90.         o.Alpha = saturate(_Color.a + (viewSpecLine + specular + outerrim + innerglow));
  91.         o.Albedo = saturate(o.Albedo + _Color);
  92.      
  93.     }
  94.     ENDCG
  95.     }
  96.         Fallback "Diffuse"
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement