Advertisement
Guest User

ToonIce.shader

a guest
Jun 26th, 2017
4,375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1.  
  2. Shader "Toon/Ice Effect" {
  3.  
  4. Properties{
  5. _TColor("Top Color", Color) = (0.64,0.94,0.64,1)// top gradient, light green
  6. _Ramp("Toon Ramp (RGB)", 2D) = "gray" {}
  7. _BottomColor("Bottom Color", Color) = (0.23,0,0.95,1)// bottom gradient, blue
  8. _RimBrightness("Rim Brightness", Range(3,4)) = 3.2 // ice rim brightness
  9.  
  10.  
  11. }
  12.  
  13. SubShader{
  14. Tags{ "RenderType" = "Opaque" }
  15.  
  16. LOD 200
  17. CGPROGRAM
  18. #pragma surface surf ToonRamp
  19.  
  20. sampler2D _Ramp;
  21.  
  22. // custom lighting function that uses a texture ramp based
  23. // on angle between light direction and normal
  24. #pragma lighting ToonRamp
  25. inline half4 LightingToonRamp(SurfaceOutput s, half3 lightDir, half atten)
  26. {
  27. #ifndef USING_DIRECTIONAL_LIGHT
  28. lightDir = normalize(lightDir);
  29. #endif
  30.  
  31. half d = dot(s.Normal, lightDir)*0.5 + 0.5;
  32. half3 ramp = tex2D(_Ramp, float2(d,d)).rgb;
  33.  
  34. half4 c;
  35. c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  36. c.a = 0;
  37. return c;
  38. }
  39.  
  40.  
  41. float4 _TColor;
  42. float4 _BottomColor;// bottom gradient color
  43. float _RimBrightness;// ice rim brightness
  44.  
  45.  
  46. struct Input {
  47. float3 viewDir; // view direction
  48. float3 worldPos; // world position
  49.  
  50. };
  51.  
  52. void surf(Input IN, inout SurfaceOutput o) {
  53. float3 localPos = saturate(IN.worldPos - mul(unity_ObjectToWorld, float4(0, 0, 0, 1)).xyz) + 0.4;// local position of the object, with an offset, clamped to make sure it doesn't go into negative
  54.  
  55. float softRim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));// calculate a soft fresnel based on the view direction and the normals of the object
  56. float hardRim = round(softRim); // round it up for a harder edge
  57. o.Emission = _TColor * lerp(hardRim, softRim, (localPos.x + localPos.y)) * (_RimBrightness*localPos.y); // lerp the emission from the hard rim to the softer one, based on the position
  58. float innerRim = 1.5 + saturate(dot(normalize(IN.viewDir), o.Normal)); // softer inner rim
  59.  
  60. o.Albedo = _TColor *pow(innerRim, 0.7)*lerp(_BottomColor, _TColor, localPos.y); // multiply the main color by the inner rim, multiply that by the gradient color lerp
  61.  
  62. }
  63. ENDCG
  64.  
  65. }
  66.  
  67. Fallback "Diffuse"
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement