Guest User

Untitled

a guest
Mar 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. // threshold for mask can be controlled using vertex color alpha (useful for spriteRenderers or particle systems)
  2. // _MainTex: alpha of this texture is used as a mask
  3. // _EmissionTex: usually rgb noise texture, adjust it's scaling if needed
  4. // color remap and oscilation for each channel of emission can be modified in _EmStrobeBFALR, _EmStrobeBFALG, _EmStrobeBFALB
  5. // Base: base amplitude of brightness oscilation
  6. // Freq: frequency of oscilation
  7. // Ampl: amplitude of oscilation
  8. // L: how much _EmissionTex affects this color
  9.  
  10. Shader "StandardWMask" {
  11. Properties {
  12. _Color ("Color", Color) = (1,1,1,1)
  13. [Header(Mask)]
  14. _MaskSoft ("Smoothness", Range (0.001, 1)) = .1
  15. [Space]
  16.  
  17. _MaskBrightOffset ("Shadow Mask Offset", Range (-.5, .5)) = 0
  18. _MainTex ("Albedo (RGB)", 2D) = "white" {}
  19. _AlphaClip ("Alpha clip", Float) = 0.01
  20. _SpecGlossMap("Specular", 2D) = "white" {}
  21.  
  22. _Specular ("Specular Mult", Range (0, 1)) = .5
  23. _Smoothness ("Glossiness Mult", Range (0, 1)) = .5
  24.  
  25. [Normal][NoScaleOffset] _BumpMap ("Normal", 2D) = "bump" {}
  26. _BumpScale ("BumpScale", Range (0, 4)) = 1
  27. [Space(20)]
  28. _MaskEmissOffset ("Emis Mask Offset", Range (-.5, .5)) = 0
  29. [NoScaleOffset] _EmissionMap ("Emission Mask", 2D) = "white" {}
  30. [Space(20)]
  31. [Toggle] _QuantEmisPos ("Snap Emission?", Float) = 0
  32. [NoScaleOffset] _EmTxtrQuant ("Quantisize", Vector) = (1,1,0,0)
  33. [NoScaleOffset] _ColorPhase ("ColorPhase", Float) = 0
  34.  
  35. [Space(20)]
  36. [Toggle] _UseColor ("Use Material Color?", Float) = 0
  37. [Toggle] _UseVertexColor ("Use Vertex?", Float) = 0
  38. [Space(20)]
  39.  
  40. _EmSpeed ("UV Speed (XY) UV Scale (ZW)", Vector) = (0,5,1,1)
  41. _EmissionTex ("Emission FX", 2D) = "white" {}
  42. [HDR]_EmissionColor ("Emission Color", Color) = (1,1,1,1)
  43.  
  44. [Header(Red remap)]
  45. [HDR]_EmisRemapR ("Remap", Color) = (1,1,1,1)
  46. _EmStrobeBFALR ("Oscilate [Base,Freq,Ampl,L]", Vector) = (.2,2,2,1)
  47.  
  48. [Header(Green remap)]
  49. [HDR]_EmisRemapG ("Remap", Color) = (1,1,1,1)
  50. _EmStrobeBFALG ("Oscilate [Base,Freq,Ampl,L]", Vector) = (8,120,1.7,1)
  51.  
  52. [Header(Blue remap)]
  53. [HDR]_EmisRemapB ("Remap", Color) = (1,1,1,1)
  54. _EmStrobeBFALB ("Oscilate [Base,Freq,Ampl,L]", Vector) = (2,.5,10,1)
  55. }
  56.  
  57. SubShader {
  58. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  59. Blend SrcAlpha OneMinusSrcAlpha
  60. Cull off
  61. ZWrite Off
  62.  
  63. CGPROGRAM
  64. #pragma surface surf StandardSpecular nofog keepalpha vertex:vert
  65. #pragma target 3.0
  66. #pragma multi_compile_instancing
  67.  
  68. sampler2D _BumpMap;
  69. sampler2D _MainTex;
  70. sampler2D _SpecGlossMap;
  71. sampler2D _EmissionMap;
  72. sampler2D _EmissionTex;
  73.  
  74. half _MaskSoft, _MaskEmissOffset, _MaskBrightOffset;
  75. half4 _EmissionTex_ST;
  76. half4 _EmissionColor;
  77. fixed4 _Color;
  78. half _AlphaClip;
  79. half _BumpScale, _ColorPhase;
  80. half _Smoothness;
  81. half _Specular;
  82. fixed _QuantEmisPos;
  83.  
  84. float4 _EmSpeed;
  85. float4 _EmTxtrSize, _EmTxtrQuant;
  86.  
  87. half4 _EmisRemapR, _EmisRemapG, _EmisRemapB;
  88. float4 _EmStrobeBFALR, _EmStrobeBFALG, _EmStrobeBFALB;
  89.  
  90. struct Input {
  91. float2 uv_MainTex;
  92. float2 emisUV;
  93. float2 emisUVOffset;
  94. fixed4 color : COLOR;
  95. fixed3 strobe;
  96. };
  97.  
  98. float quant(float q, float v){
  99. return floor(q/v)*v;
  100. }
  101.  
  102. float2 quant(float2 q, float2 v){
  103. return floor(q/v)*v;
  104. }
  105.  
  106. float TriangleWave( float x ) { return abs( frac(x+0.5)*2.0 - 1.0 ); }
  107. float SmoothCurve( float x ) { return x * x *( 3.0 - 2.0 * x ); }
  108. float SmoothTriangleWave( float x ) { return SmoothCurve( TriangleWave( x ) ); }
  109.  
  110.  
  111. void vert (inout appdata_full v, out Input o) {
  112. UNITY_INITIALIZE_OUTPUT(Input,o);
  113.  
  114. o.emisUV = v.texcoord * _EmissionTex_ST.xy;
  115.  
  116. o.emisUVOffset = _Time.xx * _EmSpeed.xy + _EmissionTex_ST.zw;
  117. o.emisUVOffset = lerp( o.emisUVOffset, quant(o.emisUVOffset, 1/_EmTxtrQuant.xy), _QuantEmisPos);
  118. o.emisUVOffset = frac( o.emisUVOffset );
  119.  
  120. o.strobe =
  121. fixed3(
  122. saturate( _EmStrobeBFALR.r + SmoothTriangleWave( ((_Time.x*(1+v.color.r))+_ColorPhase)*_EmStrobeBFALR.g) * _EmStrobeBFALR.b),
  123. saturate( _EmStrobeBFALG.r + SmoothTriangleWave( ((_Time.x*(1+v.color.g))+_ColorPhase)*_EmStrobeBFALG.g) * _EmStrobeBFALG.b),
  124. saturate( _EmStrobeBFALB.r + SmoothTriangleWave( ((_Time.x*(1+v.color.b))+_ColorPhase)*_EmStrobeBFALB.g) * _EmStrobeBFALB.b)
  125. );
  126. }
  127.  
  128. void surf (Input IN, inout SurfaceOutputStandardSpecular o) {
  129.  
  130. fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
  131.  
  132. half mm = IN.color.a+IN.color.a*_MaskSoft;
  133. // lowers brightness for 'burned effect'
  134. half bright = smoothstep(mm+_MaskBrightOffset, mm-_MaskSoft+_MaskBrightOffset, c.a);
  135. o.Albedo = c*bright;
  136.  
  137. fixed4 tint = UNITY_ACCESS_INSTANCED_PROP(_Color_arr, _Color);
  138. o.Alpha = smoothstep(mm, mm-_MaskSoft, c.a); // mask itself
  139. clip(c.a-_AlphaClip);
  140.  
  141. fixed4 spec = tex2D(_SpecGlossMap, IN.uv_MainTex);
  142. o.Specular = spec.rgb * _Specular * bright;
  143. o.Smoothness = spec.a * _Smoothness * bright;
  144.  
  145. o.Normal = UnpackScaleNormal(tex2D (_BumpMap, IN.uv_MainTex), _BumpScale);
  146.  
  147. half3 e_clr = tex2D(_EmissionMap, IN.uv_MainTex);
  148. half3 e_ovr = tex2D(_EmissionTex, IN.emisUV + IN.emisUVOffset).rgb;
  149.  
  150. e_clr = IN.color.rgb * e_clr;
  151.  
  152. half3 osc =
  153. _EmisRemapR * saturate(lerp(e_clr.r, e_ovr.r*e_clr.r, _EmStrobeBFALR.a)) * IN.strobe.r +
  154. _EmisRemapG * saturate(lerp(e_clr.g, e_ovr.g*e_clr.g, _EmStrobeBFALG.a)) * IN.strobe.g +
  155. _EmisRemapB * saturate(lerp(e_clr.b, e_ovr.b*e_clr.b, _EmStrobeBFALB.a)) * IN.strobe.b;
  156.  
  157. tint.rgb = osc*tint.rgb;
  158.  
  159. o.Emission = tint.rgb * _EmissionColor * TriangleWave( smoothstep(mm+_MaskEmissOffset, mm-_MaskSoft+_MaskEmissOffset, c.a) );
  160. }
  161. ENDCG
  162. }
  163. FallBack "Diffuse"
  164. }
Add Comment
Please, Sign In to add comment