Advertisement
Guest User

ToonLitDissolveWorldSpace.shader

a guest
Jun 9th, 2018
6,545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. Shader "Toon/Lit Dissolve DoubleTex" {
  2. Properties {
  3. _Color ("Primary Color", Color) = (1,1,1,1)
  4. _MainTex ("Primary (RGB)", 2D) = "white" {}
  5. _Color2 ("Secondary Color", Color) = (1,1,1,1)
  6. _SecondTex ("Secondary (RGB)", 2D) = "white" {}
  7. _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
  8. _NoiseTex("Dissolve Noise", 2D) = "white"{}
  9. _NScale ("Noise Scale", Range(0, 10)) = 1
  10. _DisAmount("Noise Texture Opacity", Range(0.01, 1)) =0.01
  11. _Radius("Radius", Range(0, 10)) = 0
  12. _DisLineWidth("Line Width", Range(0, 2)) = 0
  13. _DisLineColor("Line Tint", Color) = (1,1,1,1)
  14. }
  15.  
  16. SubShader{
  17. Tags { "RenderType" = "Transparent" }
  18. LOD 200
  19.  
  20. CGPROGRAM
  21.  
  22. #pragma surface surf ToonRamp
  23. sampler2D _Ramp;
  24.  
  25. // custom lighting function that uses a texture ramp based
  26. // on angle between light direction and normal
  27. #pragma lighting ToonRamp exclude_path:prepass
  28. inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
  29. {
  30. #ifndef USING_DIRECTIONAL_LIGHT
  31. lightDir = normalize(lightDir);
  32. #endif
  33.  
  34. half d = dot (s.Normal, lightDir)*0.5 + 0.5;
  35. half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
  36. half4 c;
  37. c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  38. c.a = 0;
  39. return c;
  40. }
  41.  
  42.  
  43. float3 _Position; // from script
  44.  
  45. sampler2D _MainTex, _SecondTex;
  46. float4 _Color, _Color2;
  47. sampler2D _NoiseTex;
  48. float _DisAmount, _NScale;
  49. float _DisLineWidth;
  50. float4 _DisLineColor;
  51. float _Radius;
  52.  
  53.  
  54. struct Input {
  55. float2 uv_MainTex : TEXCOORD0;
  56. float3 worldPos;// built in value to use the world space position
  57. float3 worldNormal; // built in value for world normal
  58.  
  59. };
  60.  
  61. void surf (Input IN, inout SurfaceOutput o) {
  62. half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  63. half4 c2 = tex2D(_SecondTex, IN.uv_MainTex) * _Color2;
  64.  
  65. // triplanar noise
  66. float3 blendNormal = saturate(pow(IN.worldNormal * 1.4,4));
  67. half4 nSide1 = tex2D(_NoiseTex, (IN.worldPos.xy + _Time.x) * _NScale);
  68. half4 nSide2 = tex2D(_NoiseTex, (IN.worldPos.xz + _Time.x) * _NScale);
  69. half4 nTop = tex2D(_NoiseTex, (IN.worldPos.yz + _Time.x) * _NScale);
  70.  
  71. float3 noisetexture = nSide1;
  72. noisetexture = lerp(noisetexture, nTop, blendNormal.x);
  73. noisetexture = lerp(noisetexture, nSide2, blendNormal.y);
  74.  
  75. // distance influencer position to world position
  76. float3 dis = distance(_Position, IN.worldPos);
  77. float3 sphere = 1 - saturate(dis / _Radius);
  78.  
  79. float3 sphereNoise = noisetexture.r * sphere;
  80.  
  81. float3 DissolveLine = step(sphereNoise - _DisLineWidth, _DisAmount) * step(_DisAmount,sphereNoise) ; // line between two textures
  82. DissolveLine *= _DisLineColor; // color the line
  83.  
  84. float3 primaryTex = (step(sphereNoise - _DisLineWidth,_DisAmount) * c.rgb);
  85. float3 secondaryTex = (step(_DisAmount, sphereNoise) * c2.rgb);
  86. float3 resultTex = primaryTex + secondaryTex + DissolveLine;
  87. o.Albedo = resultTex;
  88.  
  89. o.Emission = DissolveLine;
  90. o.Alpha = c.a;
  91.  
  92. }
  93. ENDCG
  94.  
  95. }
  96.  
  97. Fallback "Diffuse"
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement