Guest User

ToonlitIridescentMasked.Shader

a guest
May 19th, 2018
2,576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. Shader "Toon/Iridescent Mask" {
  2. Properties{
  3. _Color("Main Color", Color) = (0.5,0.5,0.5,1)
  4. _MainTex("Base (RGB)", 2D) = "white" {}
  5. _Noise("Noise (RGB)", 2D) = "white" {} // noise texture
  6. _Mask("Iri Mask (RGB)", 2D) = "white" {} // mask texture
  7. _Ramp("Toon Ramp (RGB)", 2D) = "gray" {}
  8. _IrTex("Iridescence Ramp (RGB)", 2D) = "white" {} // color ramp
  9. _IrColor("Iri Tint", Color) = (0.5,0.5,0.5,1)// extra iridescence tinting
  10. _Offset ("Mask Cutoff", Range (0, 1)) = 1 // offset of the color ramp
  11. _Brightness ("Iridescence Opacity", Range (0, 2)) = 1 // opacity of iridescence
  12. _WorldScale ("Noise Worldscale", Range (.002, 5)) = 1 // noise scale
  13. _Value ("Intensity Start", Range (-5, 5)) = 1 // noise scale
  14. _Value2 ("Intensity End", Range (-5, 5)) = 2 // noise scale
  15. [Toggle(LM)] _LM("Use Lightmap UVS?", Float) = 0 // use lightmap uvs instead of normal ones
  16. [Toggle(LM2)] _LM2("Use Lightmap UVS Mask?", Float) = 0 // use lightmap uvs instead of normal ones
  17.  
  18. }
  19.  
  20. SubShader{
  21. Tags{ "RenderType" = "Opaque" }
  22. LOD 200
  23. Cull Off
  24. CGPROGRAM
  25. #pragma surface surf ToonRamp
  26. #pragma shader_feature LM
  27. #pragma shader_feature LM2
  28. sampler2D _Ramp;
  29.  
  30. // custom lighting function that uses a texture ramp based
  31. // on angle between light direction and normal
  32. #pragma lighting ToonRamp exclude_path:prepass
  33. inline half4 LightingToonRamp(SurfaceOutput s, half3 lightDir, half atten)
  34. {
  35. #ifndef USING_DIRECTIONAL_LIGHT
  36. lightDir = normalize(lightDir);
  37. #endif
  38. half d = dot(s.Normal, lightDir)*0.5 + 0.5;
  39. half3 ramp = tex2D(_Ramp, float2(d,d)).rgb;
  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, _Mask;
  48. sampler2D _Noise; // noise
  49. sampler2D _IrTex; // color ramp
  50. float4 _Color;
  51. float4 _IrColor; // extra tinting
  52. float _Offset; // Mask cutoff
  53. float _Brightness; // Iridescence opacity
  54. float _WorldScale; // noise scale
  55. float _Value; // intensity start
  56. float _Value2;// intensity end
  57.  
  58. struct Input {
  59. float2 uv_MainTex : TEXCOORD0;
  60. float2 uv2_Noise : TEXCOORD1; // lightmap uvs
  61. float3 viewDir; // view direction
  62. };
  63.  
  64. void surf(Input IN, inout SurfaceOutput o) {
  65.  
  66. half f = 1 -dot(o.Normal, IN.viewDir * _Value2) + 0.5; // fresnel
  67. half4 m = tex2D(_Mask, IN.uv_MainTex); // mask
  68. #if LM2
  69. m = tex2D(_Mask, IN.uv2_Noise); // mask on lightmap UV set
  70. #endif
  71. half4 n = tex2D(_Noise, IN.uv_MainTex * _WorldScale); // noise based on the first uv set
  72. #if LM
  73. n = tex2D(_Noise, IN.uv2_Noise * _WorldScale); // noise based on the lightmap uv set
  74. #endif
  75. half4 c = tex2D(_MainTex, IN.uv_MainTex ) * _Color;
  76. half3 i = tex2D(_IrTex, float2(f,f)+ n * _Value ).rgb * _IrColor; // iridescence effect
  77. o.Albedo = (c.rgb) + (((i * n) * _Brightness) * smoothstep(m, m-0.1, _Offset)); // multiplied by original texture, masked
  78. o.Alpha = c.a;
  79. }
  80. ENDCG
  81.  
  82. }
  83.  
  84. Fallback "Diffuse"
  85. }
Advertisement
Add Comment
Please, Sign In to add comment