Advertisement
Guest User

ToonLitDissolve.shader

a guest
May 22nd, 2017
3,296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. // lit toon dissolve by @minionsart
  2. Shader "Toon/Lit Dissolve" {
  3. Properties {
  4. _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
  5. _MainTex ("Base (RGB)", 2D) = "white" {}
  6. _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
  7. _NoiseTex("Dissolve Noise", 2D) = "white"{} // Texture the dissolve is based on
  8. _DisAmount("Dissolve Amount", Range(0, 1)) = 0 // amount of dissolving going on
  9. _DisLineWidth("Dissolve Width", Range(0, 2)) = 0 // width of the line around the dissolve
  10. _DisLineColor("Dissolve Color", Color) = (1,1,1,1) // Color of the dissolve Line
  11. }
  12.  
  13. SubShader {
  14. Tags { "RenderType"="Opaque" }
  15. LOD 200
  16. Blend SrcAlpha OneMinusSrcAlpha // transparency
  17. CGPROGRAM
  18. #pragma surface surf ToonRamp keepalpha // transparency
  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 exclude_path:prepass
  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; we don't want the alpha
  37. c.a = s.Alpha; // use the alpha of the surface output
  38. return c;
  39. }
  40.  
  41.  
  42. sampler2D _MainTex;
  43. float4 _Color;
  44. sampler2D _NoiseTex;//
  45. float _DisAmount;//
  46. float _DisLineWidth;//
  47. float4 _DisLineColor;//
  48.  
  49. struct Input {
  50. float2 uv_MainTex : TEXCOORD0;
  51. float3 worldPos;// built in value to use the world space position
  52.  
  53. };
  54.  
  55. void surf (Input IN, inout SurfaceOutput o) {
  56.  
  57. half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  58. half4 n = tex2D(_NoiseTex, IN.worldPos.xy); // turn the noise texture into a value we can compare to. worldPos.xy projects from one side, xz from other side, yz from top
  59.  
  60. if (n.r - _DisLineWidth < _DisAmount) { //if the noise value minus the width of the line is lower than the dissolve amount
  61. c = _DisLineColor ; // that part is the dissolve line color
  62. }
  63. if (n.r<_DisAmount) { // if the noise value is under the dissolve amount
  64. c.a = 0.0; // it's transparent, the alpha is set to 0
  65. }
  66. o.Albedo = c.rgb;
  67. o.Alpha = c.a;
  68. }
  69. ENDCG
  70.  
  71. }
  72.  
  73. Fallback "Diffuse"
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement