Guest User

ToonIridescent.shader

a guest
Nov 20th, 2017
2,498
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Toon/Iridescent" {
  2. Properties{
  3. _Color("Main Color", Color) = (0.5,0.5,0.5,1)
  4.  
  5. _MainTex("Base (RGB)", 2D) = "white" {}
  6.  
  7. _Noise("Noise (RGB)", 2D) = "white" {} // noise texture
  8. _Ramp("Toon Ramp (RGB)", 2D) = "gray" {}
  9. _IrTex("Iridescence Ramp (RGB)", 2D) = "white" {} // color ramp
  10. _IrColor("Ir Color", Color) = (0.5,0.5,0.5,1)// extra iridescence tinting
  11. _Offset ("Iridescence Ramp Offset", Range (0, 1)) = 1 // offset of the color ramp
  12. _Brightness ("Iridescence Opacity", Range (0, 1)) = 1 // opacity of iridescence
  13. _WorldScale ("Noise Worldscale", Range (.002, 5)) = 1 // noise scale
  14. [Toggle(LM)] _LM("Use Lightmap UVS?", Float) = 0 // use lightmap uvs instead of normal ones
  15.  
  16.  
  17. }
  18.  
  19. SubShader{
  20. Tags{ "RenderType" = "Opaque" }
  21. LOD 200
  22.  
  23. CGPROGRAM
  24. #pragma surface surf ToonRamp
  25. #pragma shader_feature LM
  26. sampler2D _Ramp;
  27.  
  28. // custom lighting function that uses a texture ramp based
  29. // on angle between light direction and normal
  30. #pragma lighting ToonRamp exclude_path:prepass
  31. inline half4 LightingToonRamp(SurfaceOutput s, half3 lightDir, half atten)
  32. {
  33. #ifndef USING_DIRECTIONAL_LIGHT
  34. lightDir = normalize(lightDir);
  35. #endif
  36.  
  37. half d = dot(s.Normal, lightDir)*0.5 + 0.5;
  38. half3 ramp = tex2D(_Ramp, float2(d,d)).rgb;
  39.  
  40. half4 c;
  41. c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  42. c.a = 0;
  43. return c;
  44. }
  45.  
  46.  
  47. sampler2D _MainTex;
  48. sampler2D _Noise; // noise
  49. sampler2D _IrTex; // color ramp
  50. float4 _Color;
  51. float4 _IrColor; // extra tinting
  52. float _Offset; // color ramp offset
  53. float _Brightness; // Iridescence opacity
  54. float _WorldScale; // noise scale
  55.  
  56. struct Input {
  57. float2 uv_MainTex : TEXCOORD0;
  58. float2 uv2_Noise : TEXCOORD1; // lightmap uvs
  59. float3 viewDir; // view direction
  60. };
  61.  
  62. void surf(Input IN, inout SurfaceOutput o) {
  63.  
  64. half f = 1 -dot(o.Normal, IN.viewDir) + _Offset; // fresnel
  65. half4 n = tex2D(_Noise, IN.uv_MainTex * _WorldScale); // noise based on the first uv set
  66. #if LM
  67. n = tex2D(_Noise, IN.uv2_Noise * _WorldScale); // noise based on the lightmap uv set
  68. #endif
  69.  
  70. half4 c = tex2D(_MainTex, IN.uv_MainTex ) * _Color;
  71.  
  72.  
  73. half3 i = tex2D(_IrTex, float2(f,f)+ n).rgb * _IrColor; // iridescence effect
  74.  
  75. o.Albedo = (c.rgb) + ((i * n) * _Brightness); // multiplied by original texture, with an opacity float
  76.  
  77. o.Alpha = c.a;
  78. }
  79. ENDCG
  80.  
  81. }
  82.  
  83. Fallback "Diffuse"
  84. }
RAW Paste Data