Advertisement
Guest User

Untitled

a guest
May 6th, 2017
1,023
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. Shader "Transparent/Cutout/Additive Cutout" {
  2. Properties{
  3. [HDR]_TintColor("Tint", Color) = (1,1,1,1)
  4. _MainTex("Base (RGB) Trans (A)", 2D) = "grey" {}
  5. _Cloud1Tex("Cloud 1 (RGB) Trans (A)", 2D) = "grey" {}
  6. _Cloud2Tex("Cloud 2 (RGB) Trans (A)", 2D) = "grey" {}
  7.  
  8. //_CutTex("Cutout (A)", 2D) = "white" {}
  9. _Cutoff("Alpha cutoff", Range(0,1)) = 0.5
  10. _AlphaThreshold("Alpha threshold", Range(0,1)) = 0.01
  11. _CutoffScroll("Cutoff Scroll Speed", Vector) = (0, 0, 0, 0)
  12. _InvFade("Soft Factor", Range(0.01,3.0)) = 1.0
  13. _Boost("Brightness Boost", Range(1, 20)) = 1.0
  14. _ExternalAlpha("External Alpha", Range(0, 1)) = 1.0
  15. //_AlphaPower("Alpha power", Range(1, 150)) = 1
  16. }
  17.  
  18. SubShader{
  19. Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" }
  20. Blend OneMinusDstColor One
  21. Alphatest Greater[_Cutoff]
  22. AlphaToMask True
  23. ColorMask RGB
  24. //ColorMask RGB
  25. Cull Off
  26. Lighting Off
  27. ZWrite Off
  28. //Fog{ Mode Off }
  29. //Fog Off
  30.  
  31.  
  32.  
  33. //Cull off
  34. CGPROGRAM
  35. #pragma surface surf NoLighting nofog //one one alpha// Blend One One
  36. #pragma target 3.0
  37. #pragma multi_compile _ SOFTPARTICLES_ON
  38.  
  39. sampler2D _MainTex;
  40. sampler2D _Cloud1Tex;
  41. sampler2D _Cloud2Tex;
  42.  
  43. fixed4 _TintColor;
  44. float _Cutoff;
  45. float _AlphaThreshold;
  46. uniform float _ExternalAlpha = 1;
  47. float4 _CutoffScroll;
  48. float _InvFade;
  49. float _Boost;
  50. sampler2D_float _CameraDepthTexture;
  51. fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten)
  52. {
  53. fixed4 c;
  54. c.rgb = s.Albedo;
  55. c.a = s.Alpha;
  56. return c;
  57. }
  58. float Remap(float value, float inMin, float inMax, float outMin, float outMax)
  59. {
  60. return outMin + (((value - inMin) / (inMax - inMin)) * (outMax - outMin));
  61. }
  62.  
  63. struct Input
  64. {
  65. float2 uv_MainTex;
  66. float2 uv_Cloud1Tex;
  67. float2 uv_Cloud2Tex;
  68. float4 color : COLOR;
  69. float3 worldPos;
  70. #ifdef SOFTPARTICLES_ON
  71. float4 screenPos;
  72. float eyeDepth;
  73. #endif
  74. };
  75. #ifdef SOFTPARTICLES_ON
  76. void vert(inout appdata_full v, out Input o)
  77. {
  78. UNITY_INITIALIZE_OUTPUT(Input, o);
  79. COMPUTE_EYEDEPTH(o.eyeDepth);
  80. }
  81. #endif
  82. void surf(Input IN, inout SurfaceOutput o)
  83. {
  84.  
  85. //Arrange scrolling into 2 separate vectors
  86. float2 scrollOffsetCloud1;
  87. float2 scrollOffsetCloud2;
  88. float time;
  89. time = _Time[0];// +IN.worldPos.y;
  90.  
  91. scrollOffsetCloud1.x = (time * _CutoffScroll.x);
  92. scrollOffsetCloud1.y = (time * _CutoffScroll.y);
  93. scrollOffsetCloud2.x = (time * _CutoffScroll.z);
  94. scrollOffsetCloud2.y = (time * _CutoffScroll.w);
  95.  
  96. //Pull main texture...
  97. fixed4 mainTexelColor = tex2D(_MainTex, IN.uv_MainTex);
  98. mainTexelColor = mainTexelColor * _TintColor * IN.color;// *fixed4(1, 0, 0, 0);
  99.  
  100. //..Then get cloud texture and multiply
  101. fixed4 cloud1TexelColor = tex2D(_Cloud1Tex, IN.uv_Cloud1Tex + scrollOffsetCloud1);
  102. fixed4 cloud2TexelColor = tex2D(_Cloud2Tex, IN.uv_Cloud2Tex + scrollOffsetCloud2);
  103.  
  104. //MAGIC
  105. fixed4 finalColor;
  106. finalColor = mainTexelColor;
  107. finalColor.a = (mainTexelColor.a * cloud1TexelColor.a * 2) * cloud2TexelColor.a * 2;
  108.  
  109.  
  110. //Cutoff math
  111. float ca = finalColor.a ;
  112. float a = ca;
  113. float progress = 1 - IN.color.a;
  114. float thresh = _AlphaThreshold;
  115. float fadeMin = clamp(_Cutoff - thresh, 0, 1);
  116. float fadeMax = clamp(_Cutoff + thresh, 0, 1);
  117.  
  118.  
  119. float currentAlpha = ca * (1 - progress) * _ExternalAlpha;;
  120. a = clamp(Remap(currentAlpha, fadeMin, fadeMax, 0, 1), 0, 1);
  121. float fade = 1;
  122. #ifdef SOFTPARTICLES_ON
  123. float rawZ = SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(IN.screenPos));
  124. float sceneZ = LinearEyeDepth(rawZ);
  125. fade = saturate(_InvFade * (sceneZ - IN.screenPos.w)); //float partZ = IN.eyeDepth;
  126. #endif
  127.  
  128. o.Alpha = a;
  129. o.Albedo = clamp(finalColor.rgb * a * _Boost, 0, 1) * fade;
  130. }
  131.  
  132.  
  133. ENDCG
  134. }
  135.  
  136. Fallback "Transparent/VertexLit"
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement