P33_EffectGrab.shader 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. Shader "P33EffectsShader/P33_EffectGrab"
  2. {
  3. Properties
  4. {
  5. [Toggle(_BLACKWHITEFLASHSWITCH_ON)] _BlackWhiteFlashSwitch("黑白闪开启", Float) = 0
  6. _BlackWhiteFlash("黑白闪对比度", Float) = 1.5
  7. _Color1("黑白闪颜色1", Color) = (1,1,1,0)
  8. _Color2("黑白闪颜色2", Color) = (0,0,0,0)
  9. _BlackWhiteFlashBlend("黑白闪和原图混合度", Range( 0 , 1)) = 0
  10. _GrabNoise("扭曲贴图", 2D) = "white" {}
  11. [Enum(RGB,0,R,1,G,2,B,3)]_NoiseTexCutRgba("扭曲贴图通道切换", Float) = 0
  12. _space_rd("扭曲强度", Range( 0 , 1)) = 0
  13. [Toggle(_POLARSWITCH_ON)] _PolarSwitch("极坐标开启", Float) = 0
  14. _RadialScale("径向缩放", Float) = 1
  15. _LengthScale("长度缩放", Float) = 1
  16. _U_Speed("X速度", Float) = 0
  17. _V_Speed("Y速度", Float) = 0
  18. _space_rd_mask("遮罩贴图", 2D) = "white" {}
  19. [Enum(RGB,0,R,1,G,2,B,3)]_MaskTexCutRgba2("遮罩贴图通道切换", Float) = 0
  20. [Enum(UnityEngine.Rendering.CompareFunction)]_ZTestMode("深度测试", Float) = 4
  21. [HideInInspector] _texcoord( "", 2D ) = "white" {}
  22. }
  23. SubShader
  24. {
  25. Tags { "RenderType"="Opaque" "Queue"="Transparent" }
  26. LOD 100
  27. CGINCLUDE
  28. #pragma target 3.0
  29. ENDCG
  30. Blend SrcAlpha OneMinusSrcAlpha
  31. AlphaToMask Off
  32. Cull Off
  33. ColorMask RGBA
  34. ZWrite Off
  35. ZTest [_ZTestMode]
  36. GrabPass{ }
  37. Pass
  38. {
  39. Name "Unlit"
  40. CGPROGRAM
  41. #if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
  42. #define ASE_DECLARE_SCREENSPACE_TEXTURE(tex) UNITY_DECLARE_SCREENSPACE_TEXTURE(tex);
  43. #else
  44. #define ASE_DECLARE_SCREENSPACE_TEXTURE(tex) UNITY_DECLARE_SCREENSPACE_TEXTURE(tex)
  45. #endif
  46. #ifndef UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX
  47. //only defining to not throw compilation error over Unity 5.5
  48. #define UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input)
  49. #endif
  50. #pragma vertex vert
  51. #pragma fragment frag
  52. #pragma multi_compile_instancing
  53. #include "UnityCG.cginc"
  54. #include "UnityShaderVariables.cginc"
  55. #pragma shader_feature_local _BLACKWHITEFLASHSWITCH_ON
  56. #pragma shader_feature_local _POLARSWITCH_ON
  57. struct appdata
  58. {
  59. float4 vertex : POSITION;
  60. float4 color : COLOR;
  61. float4 ase_texcoord : TEXCOORD0;
  62. UNITY_VERTEX_INPUT_INSTANCE_ID
  63. };
  64. struct v2f
  65. {
  66. float4 vertex : SV_POSITION;
  67. #ifdef ASE_NEEDS_FRAG_WORLD_POSITION
  68. float3 worldPos : TEXCOORD0;
  69. #endif
  70. float4 ase_texcoord1 : TEXCOORD1;
  71. float4 ase_texcoord2 : TEXCOORD2;
  72. float4 ase_color : COLOR;
  73. UNITY_VERTEX_INPUT_INSTANCE_ID
  74. UNITY_VERTEX_OUTPUT_STEREO
  75. };
  76. uniform half _ZTestMode;
  77. ASE_DECLARE_SCREENSPACE_TEXTURE( _GrabTexture )
  78. uniform sampler2D _GrabNoise;
  79. uniform half4 _GrabNoise_ST;
  80. uniform half _RadialScale;
  81. uniform half _LengthScale;
  82. uniform half _U_Speed;
  83. uniform half _V_Speed;
  84. uniform half _NoiseTexCutRgba;
  85. uniform half _space_rd;
  86. uniform half _BlackWhiteFlash;
  87. uniform half4 _Color1;
  88. uniform half4 _Color2;
  89. uniform half _BlackWhiteFlashBlend;
  90. uniform sampler2D _space_rd_mask;
  91. uniform half4 _space_rd_mask_ST;
  92. uniform half _MaskTexCutRgba2;
  93. inline float4 ASE_ComputeGrabScreenPos( float4 pos )
  94. {
  95. #if UNITY_UV_STARTS_AT_TOP
  96. float scale = -1.0;
  97. #else
  98. float scale = 1.0;
  99. #endif
  100. float4 o = pos;
  101. o.y = pos.w * 0.5f;
  102. o.y = ( pos.y - o.y ) * _ProjectionParams.x * scale + o.y;
  103. return o;
  104. }
  105. float4 CalculateContrast( float contrastValue, float4 colorTarget )
  106. {
  107. float t = 0.5 * ( 1.0 - contrastValue );
  108. return mul( float4x4( contrastValue,0,0,t, 0,contrastValue,0,t, 0,0,contrastValue,t, 0,0,0,1 ), colorTarget );
  109. }
  110. v2f vert ( appdata v )
  111. {
  112. v2f o;
  113. UNITY_SETUP_INSTANCE_ID(v);
  114. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  115. UNITY_TRANSFER_INSTANCE_ID(v, o);
  116. float4 ase_clipPos = UnityObjectToClipPos(v.vertex);
  117. float4 screenPos = ComputeScreenPos(ase_clipPos);
  118. o.ase_texcoord1 = screenPos;
  119. o.ase_texcoord2.xy = v.ase_texcoord.xy;
  120. o.ase_color = v.color;
  121. //setting value to unused interpolator channels and avoid initialization warnings
  122. o.ase_texcoord2.zw = 0;
  123. float3 vertexValue = float3(0, 0, 0);
  124. #if ASE_ABSOLUTE_VERTEX_POS
  125. vertexValue = v.vertex.xyz;
  126. #endif
  127. vertexValue = vertexValue;
  128. #if ASE_ABSOLUTE_VERTEX_POS
  129. v.vertex.xyz = vertexValue;
  130. #else
  131. v.vertex.xyz += vertexValue;
  132. #endif
  133. o.vertex = UnityObjectToClipPos(v.vertex);
  134. #ifdef ASE_NEEDS_FRAG_WORLD_POSITION
  135. o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
  136. #endif
  137. return o;
  138. }
  139. fixed4 frag (v2f i ) : SV_Target
  140. {
  141. UNITY_SETUP_INSTANCE_ID(i);
  142. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
  143. fixed4 finalColor;
  144. #ifdef ASE_NEEDS_FRAG_WORLD_POSITION
  145. float3 WorldPosition = i.worldPos;
  146. #endif
  147. float4 screenPos = i.ase_texcoord1;
  148. float4 ase_grabScreenPos = ASE_ComputeGrabScreenPos( screenPos );
  149. half4 ase_grabScreenPosNorm = ase_grabScreenPos / ase_grabScreenPos.w;
  150. half2 uv_GrabNoise = i.ase_texcoord2.xy * _GrabNoise_ST.xy + _GrabNoise_ST.zw;
  151. half2 CenteredUV15_g1 = ( uv_GrabNoise - float2( 0.5,0.5 ) );
  152. half2 break17_g1 = CenteredUV15_g1;
  153. half2 appendResult23_g1 = (half2(( length( CenteredUV15_g1 ) * _RadialScale * 2.0 ) , ( atan2( break17_g1.x , break17_g1.y ) * ( 1.0 / 6.28318548202515 ) * _LengthScale )));
  154. #ifdef _POLARSWITCH_ON
  155. half2 staticSwitch63 = appendResult23_g1;
  156. #else
  157. half2 staticSwitch63 = uv_GrabNoise;
  158. #endif
  159. half2 appendResult32 = (half2(( _Time.y * _U_Speed ) , ( _Time.y * _V_Speed )));
  160. half4 tex2DNode1 = tex2D( _GrabNoise, ( staticSwitch63 + appendResult32 ) );
  161. half3 temp_cast_1 = (tex2DNode1.r).xxx;
  162. half temp_output_19_0_g2 = _NoiseTexCutRgba;
  163. half3 lerpResult10_g2 = lerp( tex2DNode1.rgb , temp_cast_1 , saturate( floor( temp_output_19_0_g2 ) ));
  164. half3 temp_cast_2 = (tex2DNode1.g).xxx;
  165. half3 lerpResult12_g2 = lerp( lerpResult10_g2 , temp_cast_2 , saturate( floor( (0.0 + (temp_output_19_0_g2 - 1.0) * (1.0 - 0.0) / (2.0 - 1.0)) ) ));
  166. half3 temp_cast_3 = (tex2DNode1.b).xxx;
  167. half3 lerpResult15_g2 = lerp( lerpResult12_g2 , temp_cast_3 , saturate( floor( (0.0 + (temp_output_19_0_g2 - 2.0) * (1.0 - 0.0) / (3.0 - 2.0)) ) ));
  168. half3 temp_cast_4 = (tex2DNode1.a).xxx;
  169. half3 lerpResult17_g2 = lerp( lerpResult15_g2 , temp_cast_4 , saturate( floor( (0.0 + (temp_output_19_0_g2 - 3.0) * (1.0 - 0.0) / (4.0 - 3.0)) ) ));
  170. half4 screenColor46 = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_GrabTexture,( ase_grabScreenPosNorm + half4( ( lerpResult17_g2 * ( _space_rd * 0.1 * i.ase_color.a ) ) , 0.0 ) ).xy);
  171. half3 desaturateInitialColor75 = screenColor46.rgb;
  172. half desaturateDot75 = dot( desaturateInitialColor75, float3( 0.299, 0.587, 0.114 ));
  173. half3 desaturateVar75 = lerp( desaturateInitialColor75, desaturateDot75.xxx, 1.0 );
  174. half4 temp_output_132_0 = round( CalculateContrast(_BlackWhiteFlash,half4( desaturateVar75 , 0.0 )) );
  175. half4 temp_output_83_0 = ( ( 1.0 - temp_output_132_0 ) * _Color2 );
  176. half4 lerpResult94 = lerp( ( temp_output_132_0 * _Color1 ) , temp_output_83_0 , temp_output_83_0);
  177. #ifdef _BLACKWHITEFLASHSWITCH_ON
  178. half4 staticSwitch98 = lerpResult94;
  179. #else
  180. half4 staticSwitch98 = screenColor46;
  181. #endif
  182. half4 lerpResult101 = lerp( staticSwitch98 , screenColor46 , _BlackWhiteFlashBlend);
  183. float2 uv_space_rd_mask = i.ase_texcoord2.xy * _space_rd_mask_ST.xy + _space_rd_mask_ST.zw;
  184. half4 tex2DNode51 = tex2D( _space_rd_mask, uv_space_rd_mask );
  185. half3 temp_cast_11 = (tex2DNode51.r).xxx;
  186. half temp_output_19_0_g3 = _MaskTexCutRgba2;
  187. half3 lerpResult10_g3 = lerp( tex2DNode51.rgb , temp_cast_11 , saturate( floor( temp_output_19_0_g3 ) ));
  188. half3 temp_cast_12 = (tex2DNode51.g).xxx;
  189. half3 lerpResult12_g3 = lerp( lerpResult10_g3 , temp_cast_12 , saturate( floor( (0.0 + (temp_output_19_0_g3 - 1.0) * (1.0 - 0.0) / (2.0 - 1.0)) ) ));
  190. half3 temp_cast_13 = (tex2DNode51.b).xxx;
  191. half3 lerpResult15_g3 = lerp( lerpResult12_g3 , temp_cast_13 , saturate( floor( (0.0 + (temp_output_19_0_g3 - 2.0) * (1.0 - 0.0) / (3.0 - 2.0)) ) ));
  192. half3 temp_cast_14 = (tex2DNode51.a).xxx;
  193. half3 lerpResult17_g3 = lerp( lerpResult15_g3 , temp_cast_14 , saturate( floor( (0.0 + (temp_output_19_0_g3 - 3.0) * (1.0 - 0.0) / (4.0 - 3.0)) ) ));
  194. half4 appendResult23 = (half4(lerpResult101.rgb , ( screenColor46.a * lerpResult17_g3 ).x));
  195. finalColor = appendResult23;
  196. return finalColor;
  197. }
  198. ENDCG
  199. }
  200. }
  201. CustomEditor "P33_EffectGrab_GUI"
  202. Fallback Off
  203. }