当前位置:   article > 正文

【Unity3d Shader】闪卡:UGUI的RawImage实现3D动画效果_unity rawimage shader

unity rawimage shader

游戏开发中常常会有精美的2D立绘,这种2D立绘一般为一张静态贴图,图片精美,但看地来比较呆板,不够生动形象。基于此问题,我们可以开发自己的shader实现动态效果。

如下图:左图为静态原始效果,右图为特殊渲染后的动态效果。(当然可以用Spine等其它方式做成动图,但在本文讨论范围)。

gif图片数据丢失比较严重:细看可以看到,妹子衣服的摆动,水面的波纹,妹子眼珠的转动,前景树枝的摇曳,树枝后面光束的转动,扇子上面宝石的闪烁,等动态效果。

 


实现原理为:给RawImage设置为自定义的材质(image_3d.shader),然后设置材质中的各个参数来实现动画。(Image3D.cs的作用也后面再介绍)

image_3d.shader,实现了多种动化效果,并利用遮罩图片的rgb通道和配置参数来做为动画的参数输入。

 

遮罩图片1(下左图)R:扇子上的光;G:水面;B:前景树枝

遮罩图片2(下右图)R:妹子的衣服;G:妹子的头发;B:妹子的眼睛

如果一张遮罩够用的话,最好只用一张遮罩会比较省。

遮罩中的颜色的值比如: 遮罩2中的红色,会有比较明显的颜色浓度过度(其它也有),用于控制衣服摆动的幅度,比如衣服的边缘处摆动幅度大,红色就比较深。

因为遮罩图层可能会有重叠。PS中遮罩层的图层要设置为“变亮“(如下图)。这样0XFF0000FF和0X009900FF混合后的颜色值会为0XFF9900FF,在shader中可以取到正确的值。PS图层中默认的”正常“在不同图层有重叠时会有最终颜色0XFF0000FF会把0X009900FF盖住,达不到我们要的效果。

然后在片元着色器中做动画

因为咱们要在材质球中编辑各个参数,所以用的是shader_feature而没用multi_compile

下面代码为简单示例:

  1. fixed4 frag(v2f IN) : SV_Target
  2. {
  3. float2 mTexcoord = IN.texcoord;//原图的纹理坐标
  4. fixed3 mask = tex2D(_Mask, mTexcoord).rgb;//遮罩图
  5. mTexcoord += Wave(mTexcoord, _SpeedR, mask.r, _ParametersR);//用遮罩图的红色(mask.r)和其它参数(_SpeedR,_ParametersR )作为Wave函数的输入
  6. half4 color = (tex2D(_MainTex, mTexcoord) + _TextureSampleAdd);
  7. return color;
  8. }

 动画函数举例:波动

  1. //params.x: 1,y方向的振幅
  2. //params.y: 1,y方向的频率
  3. //params.z: 1,x方向的振幅
  4. //params.w: 1,x方向的频率
  5. half2 Wave(float2 uv, float speed, float concentration, float4 params)
  6. {
  7. half2 offset;
  8. half2 phase = (uv + speed * half2(_Time.y, _Time.y))* PI * 2;
  9. offset.y = params.x * sin(params.y * phase.x);
  10. offset.x = params.z * sin(params.w * phase.y);
  11. offset = offset * concentration * 0.01;
  12. return offset;
  13. }

因为image_3d.shader代码比较多,并且组合方式不一定是最适合您的,所以只建议参考。

相关的资源:点击这里可以下载

以上动画中的实际代码如下:(可用代码)

  1. // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
  2. Shader "mgo/image/image_3d"
  3. {
  4. Properties
  5. {
  6. [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
  7. _Color("Tint", Color) = (1,1,1,1)
  8. _StencilComp("Stencil Comparison", Float) = 8
  9. _Stencil("Stencil ID", Float) = 0
  10. _StencilOp("Stencil Operation", Float) = 0
  11. _StencilWriteMask("Stencil Write Mask", Float) = 255
  12. _StencilReadMask("Stencil Read Mask", Float) = 255
  13. _ColorMask("Color Mask", Float) = 15
  14. [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip("Use Alpha Clip", Float) = 0
  15. [Space(100)]
  16. [Header(The following is editable content for card)]
  17. [Toggle(_ENABLE_ANI)] _EnableAni("EnableAni", Int) = 0
  18. [NoScaleOffset]
  19. _Mask("Mask", 2D) = "white" {}
  20. //[KeywordEnum(Null, ThreeD, Wave, Flex, Move, Flash, Ripple, FlowLight, Spiral)] _Type_R("TypeR", Int) = 0
  21. [KeywordEnum(Null, ThreeD, Wave, Flex, Move, Flash, FlowLight, Ripple)] _Type_R("TypeR", Int) = 0
  22. _SpeedR("SpeedR", Range(-10,10)) = 1
  23. _ParametersR("ParametersR", vector) = (1,1,1,1)
  24. //[KeywordEnum(Null, Wave, Flex, Move, Flash, Ripple, FlowLight, Spiral)] _Type_G("TypeG", Int) = 0
  25. [KeywordEnum(Null, Wave, Flex, Move, Flash, FlowLight, Ripple)] _Type_G("TypeG", Int) = 0
  26. _SpeedG("SpeedG", Range(-10,10)) = 1
  27. _ParametersG("ParametersG", vector) = (1,1,1,1)
  28. //[KeywordEnum(Null, Wave, Flex, Move, Flash, Ripple, FlowLight, Spiral)] _Type_B("TypeB", Int) = 0
  29. [KeywordEnum(Null, Wave, Flex, Move, Flash, FlowLight, Ripple)] _Type_B("TypeB", Int) = 0
  30. _SpeedB("SpeedB", Range(-10,10)) = 1
  31. _ParametersB("ParametersB", vector) = (1,1,1,1)
  32. [NoScaleOffset]
  33. _Mask2("Mask2", 2D) = "white" {}
  34. //[KeywordEnum(Null, Wave, Flex, Move, Flash, Ripple, FlowLight, Spiral)] _Type2_R("Type2R", Int) = 0
  35. [KeywordEnum(Null, Wave, Flex, Move, Flash, FlowLight, Ripple)] _Type2_R("Type2R", Int) = 0
  36. _Speed2R("Speed2R", Range(-10,10)) = 1
  37. _Parameters2R("Parameters2R", vector) = (1,1,1,1)
  38. //[KeywordEnum(Null, Wave, Flex, Move, Flash, Ripple, FlowLight, Spiral)] _Type2_G("Type2G", Int) = 0
  39. [KeywordEnum(Null, Wave, Flex, Move, Flash, FlowLight, Ripple)] _Type2_G("Type2G", Int) = 0
  40. _Speed2G("Speed2G", Range(-10,10)) = 1
  41. _Parameters2G("Parameters2G", vector) = (1,1,1,1)
  42. //[KeywordEnum(Null, Wave, Flex, Move, Flash, Ripple, FlowLight, Spiral)] _Type2_B("Type2B", Int) = 0
  43. [KeywordEnum(Null, Wave, Flex, Move, Flash, FlowLight, Ripple)] _Type2_B("Type2B", Int) = 0
  44. _Speed2B("Speed2B", Range(-10,10)) = 1
  45. _Parameters2B("Parameters2B", vector) = (1,1,1,1)
  46. //--------------------------------------------
  47. [Space(100)]
  48. [Header(The following is editable content for effect)]
  49. [Header(Please do not check the effect options you do not use such as EnableFx1 EnableFx2 EnableFx3 EnableFx4)]
  50. [Toggle(_ENABLE_FX1)] _ENABLE_FX1("EnableFx1", Int) = 0
  51. [Toggle(_ENABLE_FX2)] _ENABLE_FX2("EnableFx2", Int) = 0
  52. [Toggle(_ENABLE_FX3)] _ENABLE_FX3("EnableFx3", Int) = 0
  53. [Toggle(_ENABLE_FX4)] _ENABLE_FX4("EnableFx4", Int) = 0
  54. [Header(effect 1 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz)]
  55. _Fx1Tex("Fx1 Texture", 2D) = "white" {}
  56. [KeywordEnum(NULL, MASK_R, MASK_G, MASK_B, MASK2_R, MASK2_G, MASK2_B)] _Fx1("Fx1 Mask Color", Int) = 0
  57. [Toggle] _Fx1IsOneMinus("Fx1IsOneMinus", Int) = 0
  58. _Fx1SpeedMove("Fx1SpeedMove", Range(-10,10)) = 0
  59. _Fx1ParametersMove("Fx1ParametersMove", vector) = (1,1,1,1)
  60. _Fx1SpeedWave("Fx1SpeedWave", Range(-10,10)) = 0
  61. _Fx1ParametersWave("Fx1ParametersWave", vector) = (1,1,1,1)
  62. _Fx1SpeedFlex("Fx1SpeedFlex", Range(-10,10)) = 0
  63. _Fx1ParametersFlex("Fx1ParametersFlex", vector) = (1,1,1,1)
  64. _Fx1SpeedSpiral("Fx1SpeedSpiral", Range(-10,10)) = 0
  65. _Fx1ParametersSpiral("Fx1ParametersSpiral", vector) = (1,1,1,1)
  66. _Fx1SpeedFrameAni("Fx1SpeedFrameAni", Range(-10,10)) = 0
  67. _Fx1ParametersFrameAni("Fx1ParametersFrameAni", vector) = (1,1,1,1)
  68. _Fx1SpeedFlash("Fx1SpeedFlash", Range(-10,10)) = 0
  69. _Fx1ParametersFlash("Fx1ParametersFlash", vector) = (1,1,1,1)
  70. [Space(50)]
  71. [Header(effect 2 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz)]
  72. _Fx2Tex("Fx2 Texture", 2D) = "white" {}
  73. [KeywordEnum(NULL, MASK_R, MASK_G, MASK_B, MASK2_R, MASK2_G, MASK2_B)] _Fx2("Fx2 Mask Color", Int) = 0
  74. [Toggle] _Fx2IsOneMinus("Fx2IsOneMinus", Int) = 0
  75. _Fx2SpeedMove("Fx2SpeedMove", Range(-10,10)) = 0
  76. _Fx2ParametersMove("Fx2ParametersMove", vector) = (1,1,1,1)
  77. _Fx2SpeedWave("Fx2SpeedWave", Range(-10,10)) = 0
  78. _Fx2ParametersWave("Fx2ParametersWave", vector) = (1,1,1,1)
  79. _Fx2SpeedFlex("Fx2SpeedFlex", Range(-10,10)) = 0
  80. _Fx2ParametersFlex("Fx2ParametersFlex", vector) = (1,1,1,1)
  81. _Fx2SpeedSpiral("Fx2SpeedSpiral", Range(-10,10)) = 0
  82. _Fx2ParametersSpiral("Fx2ParametersSpiral", vector) = (1,1,1,1)
  83. _Fx2SpeedFrameAni("Fx2SpeedFrameAni", Range(-10,10)) = 0
  84. _Fx2ParametersFrameAni("Fx2ParametersFrameAni", vector) = (1,1,1,1)
  85. _Fx2SpeedFlash("Fx2SpeedFlash", Range(-10,10)) = 0
  86. _Fx2ParametersFlash("Fx2ParametersFlash", vector) = (1,1,1,1)
  87. [Space(50)]
  88. [Header(effect 3 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz)]
  89. _Fx3Tex("Fx3 Texture", 2D) = "white" {}
  90. [KeywordEnum(NULL, MASK_R, MASK_G, MASK_B, MASK2_R, MASK2_G, MASK2_B)] _Fx3("Fx3 Mask Color", Int) = 0
  91. [Toggle] _Fx3IsOneMinus("Fx3IsOneMinus", Int) = 0
  92. _Fx3SpeedMove("Fx3SpeedMove", Range(-10,10)) = 0
  93. _Fx3ParametersMove("Fx3ParametersMove", vector) = (1,1,1,1)
  94. _Fx3SpeedWave("Fx3SpeedWave", Range(-10,10)) = 0
  95. _Fx3ParametersWave("Fx3ParametersWave", vector) = (1,1,1,1)
  96. _Fx3SpeedFlex("Fx3SpeedFlex", Range(-10,10)) = 0
  97. _Fx3ParametersFlex("Fx3ParametersFlex", vector) = (1,1,1,1)
  98. _Fx3SpeedSpiral("Fx3SpeedSpiral", Range(-10, 10)) = 0
  99. _Fx3ParametersSpiral("Fx3ParametersSpiral", vector) = (1, 1, 1, 1)
  100. _Fx3SpeedFrameAni("Fx3SpeedFrameAni", Range(-10, 10)) = 0
  101. _Fx3ParametersFrameAni("Fx3ParametersFrameAni", vector) = (1, 1, 1, 1)
  102. _Fx3SpeedFlash("Fx3SpeedFlash", Range(-10,10)) = 0
  103. _Fx3ParametersFlash("Fx3ParametersFlash", vector) = (1,1,1,1)
  104. [Space(50)]
  105. [Header(effect 4 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz)]
  106. _Fx4Tex("Fx4 Texture", 2D) = "white" {}
  107. [KeywordEnum(NULL, MASK_R, MASK_G, MASK_B, MASK2_R, MASK2_G, MASK2_B)] _Fx3("Fx4 Mask Color", Int) = 0
  108. [Toggle] _Fx4IsOneMinus("Fx4IsOneMinus", Int) = 0
  109. _Fx4SpeedMove("Fx4SpeedMove", Range(-10,10)) = 0
  110. _Fx4ParametersMove("Fx4ParametersMove", vector) = (1,1,1,1)
  111. _Fx4SpeedWave("Fx4SpeedWave", Range(-10,10)) = 0
  112. _Fx4ParametersWave("Fx4ParametersWave", vector) = (1,1,1,1)
  113. _Fx4SpeedFlex("Fx4SpeedFlex", Range(-10,10)) = 0
  114. _Fx4ParametersFlex("Fx4ParametersFlex", vector) = (1,1,1,1)
  115. _Fx4SpeedSpiral("Fx4SpeedSpiral", Range(-10, 10)) = 0
  116. _Fx4ParametersSpiral("Fx4ParametersSpiral", vector) = (1, 1, 1, 1)
  117. _Fx4SpeedFrameAni("Fx4SpeedFrameAni", Range(-10, 10)) = 0
  118. _Fx4ParametersFrameAni("Fx4ParametersFrameAni", vector) = (1, 1, 1, 1)
  119. _Fx4SpeedFlash("Fx4SpeedFlash", Range(-10,10)) = 0
  120. _Fx4ParametersFlash("Fx4ParametersFlash", vector) = (1,1,1,1)
  121. }
  122. SubShader
  123. {
  124. Tags
  125. {
  126. "Queue" = "Transparent"
  127. "IgnoreProjector" = "True"
  128. "RenderType" = "Transparent"
  129. "PreviewType" = "Plane"
  130. "CanUseSpriteAtlas" = "True"
  131. }
  132. Stencil
  133. {
  134. Ref[_Stencil]
  135. Comp[_StencilComp]
  136. Pass[_StencilOp]
  137. ReadMask[_StencilReadMask]
  138. WriteMask[_StencilWriteMask]
  139. }
  140. Cull Off
  141. Lighting Off
  142. ZWrite Off
  143. ZTest[unity_GUIZTestMode]
  144. Blend SrcAlpha OneMinusSrcAlpha
  145. ColorMask[_ColorMask]
  146. Pass
  147. {
  148. Name "Default"
  149. CGPROGRAM
  150. #pragma vertex vert
  151. #pragma fragment frag
  152. #pragma target 2.0
  153. #include "UnityCG.cginc"
  154. #include "UnityUI.cginc"
  155. #pragma multi_compile __ UNITY_UI_CLIP_RECT
  156. #pragma multi_compile __ UNITY_UI_ALPHACLIP
  157. #pragma shader_feature _ENABLE_ANI
  158. //#pragma shader_feature _TYPE_R_NULL _TYPE_R_THREED _TYPE_R_WAVE _TYPE_R_FLEX _TYPE_R_MOVE _TYPE_R_FLASH _TYPE_R_RIPPLE _TYPE_R_FLOWLIGHT _TYPE_R_SPIRAL
  159. //#pragma shader_feature _TYPE_G_NULL _TYPE_G_WAVE _TYPE_G_FLEX _TYPE_G_MOVE _TYPE_G_FLASH _TYPE_G_RIPPLE _TYPE_G_FLOWLIGHT _TYPE_G_SPIRAL
  160. //#pragma shader_feature _TYPE_B_NULL _TYPE_B_WAVE _TYPE_B_FLEX _TYPE_B_MOVE _TYPE_B_FLASH _TYPE_B_RIPPLE _TYPE_B_FLOWLIGHT _TYPE_B_SPIRAL
  161. //#pragma shader_feature _TYPE2_R_NULL _TYPE2_R_WAVE _TYPE2_R_FLEX _TYPE2_R_MOVE _TYPE2_R_FLASH _TYPE2_R_RIPPLE _TYPE2_R_FLOWLIGHT _TYPE2_R_SPIRAL
  162. //#pragma shader_feature _TYPE2_G_NULL _TYPE2_G_WAVE _TYPE2_G_FLEX _TYPE2_G_MOVE _TYPE2_G_FLASH _TYPE2_G_RIPPLE _TYPE2_G_FLOWLIGHT _TYPE2_G_SPIRAL
  163. //#pragma shader_feature _TYPE2_B_NULL _TYPE2_B_WAVE _TYPE2_B_FLEX _TYPE2_B_MOVE _TYPE2_B_FLASH _TYPE2_B_RIPPLE _TYPE2_B_FLOWLIGHT _TYPE2_B_SPIRAL
  164. #pragma shader_feature _TYPE_R_NULL _TYPE_R_WAVE _TYPE_R_FLEX _TYPE_R_MOVE _TYPE_R_FLASH _TYPE_R_FLOWLIGHT _TYPE_R_RIPPLE _TYPE_R_THREED
  165. #pragma shader_feature _TYPE_G_NULL _TYPE_G_WAVE _TYPE_G_FLEX _TYPE_G_MOVE _TYPE_G_FLASH _TYPE_G_FLOWLIGHT _TYPE_G_RIPPLE
  166. #pragma shader_feature _TYPE_B_NULL _TYPE_B_WAVE _TYPE_B_FLEX _TYPE_B_MOVE _TYPE_B_FLASH _TYPE_B_FLOWLIGHT _TYPE_B_RIPPLE
  167. #pragma shader_feature _TYPE2_R_NULL _TYPE2_R_WAVE _TYPE2_R_FLEX _TYPE2_R_MOVE _TYPE2_R_FLASH _TYPE2_R_FLOWLIGHT _TYPE2_R_RIPPLE
  168. #pragma shader_feature _TYPE2_G_NULL _TYPE2_G_WAVE _TYPE2_G_FLEX _TYPE2_G_MOVE _TYPE2_G_FLASH _TYPE2_G_FLOWLIGHT _TYPE2_G_RIPPLE
  169. #pragma shader_feature _TYPE2_B_NULL _TYPE2_B_WAVE _TYPE2_B_FLEX _TYPE2_B_MOVE _TYPE2_B_FLASH _TYPE2_B_FLOWLIGHT _TYPE2_B_RIPPLE
  170. #pragma shader_feature _ENABLE_FX1
  171. #pragma shader_feature _FX1_MASK_NULL _FX1_MASK_R _FX1_MASK_G _FX1_MASK_B _FX1_MASK2_R _FX1_MASK2_G _FX1_MASK2_B
  172. #pragma shader_feature _ENABLE_FX2
  173. #pragma shader_feature _FX2_MASK_NULL _FX2_MASK_R _FX2_MASK_G _FX2_MASK_B _FX2_MASK2_R _FX2_MASK2_G _FX2_MASK2_B
  174. #pragma shader_feature _ENABLE_FX3
  175. #pragma shader_feature _FX3_MASK_NULL _FX3_MASK_R _FX3_MASK_G _FX3_MASK_B _FX3_MASK2_R _FX3_MASK2_G _FX3_MASK2_B
  176. #pragma shader_feature _ENABLE_FX4
  177. #pragma shader_feature _FX4_MASK_NULL _FX4_MASK_R _FX4_MASK_G _FX4_MASK_B _FX4_MASK2_R _FX4_MASK2_G _FX4_MASK2_B
  178. #define PI 3.1415926
  179. struct appdata_t
  180. {
  181. float4 vertex : POSITION;
  182. float4 color : COLOR;
  183. float2 texcoord : TEXCOORD0;
  184. UNITY_VERTEX_INPUT_INSTANCE_ID
  185. };
  186. struct v2f
  187. {
  188. float4 vertex : SV_POSITION;
  189. fixed4 color : COLOR;
  190. float2 texcoord : TEXCOORD0;
  191. float4 worldPosition : TEXCOORD1;
  192. #if _ENABLE_FX1
  193. float2 fx1Texcoord : TEXCOORD2;
  194. #endif
  195. #if _ENABLE_FX2
  196. float2 fx2Texcoord : TEXCOORD3;
  197. #endif
  198. #if _ENABLE_FX3
  199. float2 fx3Texcoord : TEXCOORD4;
  200. #endif
  201. #if _ENABLE_FX4
  202. float2 fx4Texcoord : TEXCOORD5;
  203. #endif
  204. UNITY_VERTEX_OUTPUT_STEREO
  205. };
  206. sampler2D _MainTex;
  207. fixed4 _Color;
  208. fixed4 _TextureSampleAdd;
  209. float4 _ClipRect;
  210. float4 _MainTex_ST;
  211. uniform sampler2D _Mask;
  212. uniform float4 _Mask_ST;
  213. uniform float _SpeedR;
  214. uniform float4 _ParametersR;
  215. uniform float _SpeedG;
  216. uniform float4 _ParametersG;
  217. uniform float _SpeedB;
  218. uniform float4 _ParametersB;
  219. uniform sampler2D _Mask2;
  220. uniform float4 _Mask2_ST;
  221. uniform float _Speed2R;
  222. uniform float4 _Parameters2R;
  223. uniform float _Speed2G;
  224. uniform float4 _Parameters2G;
  225. uniform float _Speed2B;
  226. uniform float4 _Parameters2B;
  227. uniform sampler2D _Fx1Tex;
  228. uniform float4 _Fx1Tex_ST;
  229. uniform bool _Fx1IsOneMinus;
  230. uniform float _Fx1SpeedMove;
  231. uniform float4 _Fx1ParametersMove;
  232. uniform float _Fx1SpeedWave;
  233. uniform float4 _Fx1ParametersWave;
  234. uniform float _Fx1SpeedFlex;
  235. uniform float4 _Fx1ParametersFlex;
  236. uniform float _Fx1SpeedSpiral;
  237. uniform float4 _Fx1ParametersSpiral;
  238. uniform float _Fx1SpeedFrameAni;
  239. uniform float4 _Fx1ParametersFrameAni;
  240. uniform float _Fx1SpeedFlash;
  241. uniform float4 _Fx1ParametersFlash;
  242. uniform sampler2D _Fx2Tex;
  243. uniform float4 _Fx2Tex_ST;
  244. uniform bool _Fx2IsOneMinus;
  245. uniform float _Fx2SpeedMove;
  246. uniform float4 _Fx2ParametersMove;
  247. uniform float _Fx2SpeedWave;
  248. uniform float4 _Fx2ParametersWave;
  249. uniform float _Fx2SpeedFlex;
  250. uniform float4 _Fx2ParametersFlex;
  251. uniform float _Fx2SpeedSpiral;
  252. uniform float4 _Fx2ParametersSpiral;
  253. uniform float _Fx2SpeedFrameAni;
  254. uniform float4 _Fx2ParametersFrameAni;
  255. uniform float _Fx2SpeedFlash;
  256. uniform float4 _Fx2ParametersFlash;
  257. uniform sampler2D _Fx3Tex;
  258. uniform float4 _Fx3Tex_ST;
  259. uniform bool _Fx3IsOneMinus;
  260. uniform float _Fx3SpeedMove;
  261. uniform float4 _Fx3ParametersMove;
  262. uniform float _Fx3SpeedWave;
  263. uniform float4 _Fx3ParametersWave;
  264. uniform float _Fx3SpeedFlex;
  265. uniform float4 _Fx3ParametersFlex;
  266. uniform float _Fx3SpeedSpiral;
  267. uniform float4 _Fx3ParametersSpiral;
  268. uniform float _Fx3SpeedFrameAni;
  269. uniform float4 _Fx3ParametersFrameAni;
  270. uniform float _Fx3SpeedFlash;
  271. uniform float4 _Fx3ParametersFlash;
  272. uniform sampler2D _Fx4Tex;
  273. uniform float4 _Fx4Tex_ST;
  274. uniform bool _Fx4IsOneMinus;
  275. uniform float _Fx4SpeedMove;
  276. uniform float4 _Fx4ParametersMove;
  277. uniform float _Fx4SpeedWave;
  278. uniform float4 _Fx4ParametersWave;
  279. uniform float _Fx4SpeedFlex;
  280. uniform float4 _Fx4ParametersFlex;
  281. uniform float _Fx4SpeedSpiral;
  282. uniform float4 _Fx4ParametersSpiral;
  283. uniform float _Fx4SpeedFrameAni;
  284. uniform float4 _Fx4ParametersFrameAni;
  285. uniform float _Fx4SpeedFlash;
  286. uniform float4 _Fx4ParametersFlash;
  287. //函数定义区
  288. //params.x: 自动情况下x方向移动的振幅
  289. //params.y: 大于0表示开启自动3d运动 小于等于0用于手动拖动操作。
  290. //params.z: 手动拖动操作时x方向的振幅
  291. //params.w: 手动拖动操作时y方向的振幅
  292. half2 ThreeD(float2 uv, float speed, float concentration, float4 params)
  293. {
  294. half2 offset;
  295. if (params.y > 0)
  296. {
  297. half2 phase = (speed * _Time.y) * PI * 2;
  298. offset.x = params.x * sin(phase);
  299. offset.y = 0;
  300. }
  301. else
  302. {
  303. offset.x = params.z;
  304. offset.y = params.w;
  305. }
  306. offset = offset * concentration * 0.01;
  307. return offset;
  308. }
  309. //params.x: 1,y方向的振幅
  310. //params.y: 1,y方向的频率
  311. //params.z: 1,x方向的振幅
  312. //params.w: 1,x方向的频率
  313. half2 Wave(float2 uv, float speed, float concentration, float4 params)
  314. {
  315. half2 offset;
  316. half2 phase = (uv + speed * half2(_Time.y, _Time.y))* PI * 2;
  317. offset.y = params.x * sin(params.y * phase.x);
  318. offset.x = params.z * sin(params.w * phase.y);
  319. offset = offset * concentration * 0.01;
  320. return offset;
  321. }
  322. //params.x: 1,x方向的振幅
  323. //params.y: 1,x方向的频率
  324. //params.z: 1,y方向的振幅
  325. //params.w: 1,y方向的频率
  326. half2 Flex(float2 uv, float speed, float concentration, float4 params)
  327. {
  328. half2 offset;
  329. half2 phase = (uv + speed * half2(_Time.y, _Time.y))* PI * 2;
  330. offset.x = params.x * sin(params.y * phase.x);
  331. offset.y = params.z * sin(params.w * phase.y);
  332. offset = offset * concentration * 0.01;
  333. return offset;
  334. }
  335. //params.x: 1,x方向的速度
  336. //params.y: 1,x方向的速度
  337. //params.z: 0,useless
  338. //params.w: 0,useless
  339. half2 Move(float2 uv, float speed, float concentration, float4 params)
  340. {
  341. half2 offset;
  342. half2 phase = speed * _Time.y;
  343. offset.x = phase * params.x % 1;
  344. offset.y = phase * params.y % 1;
  345. return offset;
  346. }
  347. //params.x: 1,red
  348. //params.y: 1,green
  349. //params.z: 1,blue
  350. //params.w: 0.2,最暗值
  351. half3 Flash(float2 uv, float speed, float concentration, float4 params)
  352. {
  353. half3 color;
  354. if (concentration > 0.01)
  355. {
  356. half2 phase = (speed * _Time.y) * PI * 2;
  357. half light = saturate(lerp(params.w, 1, (sin(phase) + 1) * 0.5)) * concentration;
  358. color = light * half3(params.x, params.y, params.z);
  359. }
  360. else
  361. {
  362. color = 0;
  363. }
  364. return color;
  365. }
  366. //params.x: 3,振幅
  367. //params.y: 9,频率
  368. //params.z: 0.5, 中心x
  369. //params.w: 0.5, 中心y
  370. half2 Ripple(float2 uv, float speed, float concentration, float4 params)
  371. {
  372. half dis = distance(float2(uv.x, uv.y * 1), params.zw);
  373. half2 offset = saturate(1 - dis) * params.x * sin((dis * params.y + _Time.y * speed) * 2 * PI);
  374. offset = offset * concentration * 0.01;
  375. return offset;
  376. }
  377. //params.x: 0,光柱旋转角度
  378. //params.y: 2,光柱频率(注意是否刷到目标位置)
  379. //params.z: 0.2,光柱宽度(0~1)表示百分比
  380. //params.w: 999900,光柱颜色(0~999999) red:990000 green:009900 blue:000099 yellow:999900 white:999999
  381. half3 Flowlight(float2 uv, float speed, float concentration, float4 params)
  382. {
  383. //sampler2D fxTex,
  384. /*half2 offset;
  385. offset.y = 0;
  386. offset.x = (speed * _Time.y % 1 - 0.5) * params.x;
  387. half3 color = tex2D(fxTex, uv + offset);
  388. color = color * params.y * concentration;
  389. return color;*/
  390. half width = params.z;
  391. half rotation = params.x * PI / 180;
  392. half offset = (speed * _Time.y % 1 - 0.5) * params.y;
  393. float s, c;
  394. sincos(rotation, s, c);
  395. float2x2 rotMatrix = float2x2(c, -s, s, c);
  396. half2 fxUV = mul(uv, rotMatrix);
  397. half3 color = 0;
  398. if (fxUV.x > offset && fxUV.x < offset + width)
  399. {
  400. color = half3(params.w / 10000 % 100, params.w / 100 % 100, params.w % 100) * concentration * 0.05;
  401. fixed dis = abs(offset + width * 0.5 - fxUV.x);
  402. fixed featherWidth = 0.2;
  403. if (dis > width * (0.5 - featherWidth))
  404. {
  405. color *= lerp(1, 0, (dis - width * (0.5 - featherWidth)) / (width * featherWidth));
  406. }
  407. }
  408. return color;
  409. }
  410. //params.x: 0.5, 扭曲程度
  411. //params.y: 1, 中心扭曲加速度
  412. //params.z: 0.5, 中心x
  413. //params.w: 0.5, 中心y
  414. half2 Spiral(float2 uv, float speed, float concentration, float4 params)
  415. {
  416. half dis = distance(uv.xy, params.zw);
  417. float rotation = params.x * pow(dis, -params.y);
  418. rotation += speed * _Time.y * 2 * PI;
  419. float s, c;
  420. sincos(rotation, s, c);
  421. float2x2 rotMatrix = float2x2(c, -s, s, c);
  422. half2 offset = mul(uv - params.zw, rotMatrix) + params.zw;
  423. return offset;
  424. }
  425. //params.x: 4, 水平x方向有几个元素
  426. //params.y: 4, 垂直y方向有几个元素
  427. //params.z: 0, useless
  428. //params.w: 0, useless
  429. half2 FrameAni(float2 uv, float speed, float concentration, float4 params)
  430. {
  431. half2 offset = uv / params.xy;
  432. fixed frame = floor(_Time.w * speed % (params.x * params.y));
  433. fixed2 step = 1 / params.xy;
  434. offset.x += (frame % params.x) * step.x;
  435. offset.y += (1 - floor(frame / params.x) * step.y - step.y);
  436. return offset;
  437. }
  438. v2f vert(appdata_t v)
  439. {
  440. v2f OUT;
  441. UNITY_SETUP_INSTANCE_ID(v);
  442. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
  443. OUT.worldPosition = v.vertex;
  444. OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
  445. OUT.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
  446. #if _ENABLE_ANI
  447. #if _ENABLE_FX1
  448. OUT.fx1Texcoord = TRANSFORM_TEX(v.texcoord, _Fx1Tex);
  449. #endif
  450. #if _ENABLE_FX2
  451. OUT.fx2Texcoord = TRANSFORM_TEX(v.texcoord, _Fx2Tex);
  452. #endif
  453. #if _ENABLE_FX3
  454. OUT.fx3Texcoord = TRANSFORM_TEX(v.texcoord, _Fx3Tex);
  455. #endif
  456. #if _ENABLE_FX4
  457. OUT.fx4Texcoord = TRANSFORM_TEX(v.texcoord, _Fx4Tex);
  458. #endif
  459. #endif
  460. OUT.color = v.color * _Color;
  461. return OUT;
  462. }
  463. fixed4 frag(v2f IN) : SV_Target
  464. {
  465. #if _ENABLE_ANI
  466. fixed3 depth = tex2D(_Mask2, IN.texcoord).rgb;
  467. float2 mTexcoord = IN.texcoord;
  468. fixed4 mColor = IN.color;
  469. fixed3 mask = tex2D(_Mask, mTexcoord).rgb;
  470. fixed3 mask2 = tex2D(_Mask2, mTexcoord).rgb;
  471. //threeD------------------------------------------------------------------------------------------------------------------------------
  472. #if _TYPE_R_THREED
  473. mTexcoord += ThreeD(mTexcoord, _SpeedR, mask.r, _ParametersR);
  474. mask2 = tex2D(_Mask2, mTexcoord).rgb;
  475. #endif
  476. //wave------------------------------------------------------------------------------------------------------------------------------
  477. #if _TYPE_R_WAVE
  478. mTexcoord += Wave(mTexcoord, _SpeedR, mask.r, _ParametersR);
  479. mask2 = tex2D(_Mask2, mTexcoord).rgb;
  480. #endif
  481. #if _TYPE_G_WAVE
  482. mTexcoord += Wave(mTexcoord, _SpeedG, mask.g, _ParametersG);
  483. mask2 = tex2D(_Mask2, mTexcoord).rgb;
  484. #endif
  485. #if _TYPE_B_WAVE
  486. mTexcoord += Wave(mTexcoord, _SpeedB, mask.b, _ParametersB);
  487. mask2 = tex2D(_Mask2, mTexcoord).rgb;
  488. #endif
  489. #if _TYPE2_R_WAVE
  490. mTexcoord += Wave(mTexcoord, _Speed2R, mask2.r, _Parameters2R);
  491. #endif
  492. #if _TYPE2_G_WAVE
  493. mTexcoord += Wave(mTexcoord, _Speed2G, mask2.g, _Parameters2G);
  494. #endif
  495. #if _TYPE2_B_WAVE
  496. mTexcoord += Wave(mTexcoord, _Speed2B, mask2.b, _Parameters2B);
  497. #endif
  498. //flex------------------------------------------------------------------------------------------------------------------------------
  499. #if _TYPE_R_FLEX
  500. mTexcoord += Flex(mTexcoord, _SpeedR, mask.r, _ParametersR);
  501. mask2 = tex2D(_Mask2, mTexcoord).rgb;
  502. #endif
  503. #if _TYPE_G_FLEX
  504. mTexcoord += Flex(mTexcoord, _SpeedG, mask.g, _ParametersG);
  505. mask2 = tex2D(_Mask2, mTexcoord).rgb;
  506. #endif
  507. #if _TYPE_B_FLEX
  508. mTexcoord += Flex(mTexcoord, _SpeedB, mask.b, _ParametersB);
  509. mask2 = tex2D(_Mask2, mTexcoord).rgb;
  510. #endif
  511. #if _TYPE2_R_FLEX
  512. mTexcoord += Flex(mTexcoord, _Speed2R, mask2.r, _Parameters2R);
  513. #endif
  514. #if _TYPE2_G_FLEX
  515. mTexcoord += Flex(mTexcoord, _Speed2G, mask2.g, _Parameters2G);
  516. #endif
  517. #if _TYPE2_B_FLEX
  518. mTexcoord += Flex(mTexcoord, _Speed2B, mask2.b, _Parameters2B);
  519. #endif
  520. //move-----------------------------------------------------------------------------------------------------------------------------
  521. #if _TYPE_R_MOVE
  522. mTexcoord += Move(mTexcoord, _SpeedR, mask.r, _ParametersR);
  523. mask2 = tex2D(_Mask2, mTexcoord).rgb;
  524. #endif
  525. #if _TYPE_G_MOVE
  526. mTexcoord += Move(mTexcoord, _SpeedG, mask.g, _ParametersG);
  527. mask2 = tex2D(_Mask2, mTexcoord).rgb;
  528. #endif
  529. #if _TYPE_B_MOVE
  530. mTexcoord += Move(mTexcoord, _SpeedB, mask.b, _ParametersB);
  531. mask2 = tex2D(_Mask2, mTexcoord).rgb;
  532. #endif
  533. #if _TYPE2_R_MOVE
  534. mTexcoord += Move(mTexcoord, _Speed2R, mask2.r, _Parameters2R);
  535. #endif
  536. #if _TYPE2_G_MOVE
  537. mTexcoord += Move(mTexcoord, _Speed2G, mask2.g, _Parameters2G);
  538. #endif
  539. #if _TYPE2_B_MOVE
  540. mTexcoord += Move(mTexcoord, _Speed2B, mask2.b, _Parameters2B);
  541. #endif
  542. //flash-----------------------------------------------------------------------------------------------------------------------------
  543. #if _TYPE_R_FLASH
  544. mColor.rgb += Flash(mTexcoord, _SpeedR, mask.r, _ParametersR);
  545. #endif
  546. #if _TYPE_G_FLASH
  547. mColor.rgb += Flash(mTexcoord, _SpeedG, mask.g, _ParametersG);
  548. #endif
  549. #if _TYPE_B_FLASH
  550. mColor.rgb += Flash(mTexcoord, _SpeedB, mask.b, _ParametersB);
  551. #endif
  552. #if _TYPE2_R_FLASH
  553. mColor.rgb += Flash(mTexcoord, _Speed2R, mask2.r, _Parameters2R);
  554. #endif
  555. #if _TYPE2_G_FLASH
  556. mColor.rgb += Flash(mTexcoord, _Speed2G, mask2.g, _Parameters2G);
  557. #endif
  558. #if _TYPE2_B_FLASH
  559. mColor.rgb += Flash(mTexcoord, _Speed2B, mask2.b, _Parameters2B);
  560. #endif
  561. //ripple------------------------------------------------------------------------------------------------------------------------------
  562. #if _TYPE_R_RIPPLE
  563. mTexcoord += Ripple(mTexcoord, _SpeedR, mask.r, _ParametersR);
  564. mask2 = tex2D(_Mask2, mTexcoord).rgb;
  565. #endif
  566. #if _TYPE_G_RIPPLE
  567. mTexcoord += Ripple(mTexcoord, _SpeedG, mask.g, _ParametersG);
  568. mask2 = tex2D(_Mask2, mTexcoord).rgb;
  569. #endif
  570. #if _TYPE_B_RIPPLE
  571. mTexcoord += Ripple(mTexcoord, _SpeedB, mask.b, _ParametersB);
  572. mask2 = tex2D(_Mask2, mTexcoord).rgb;
  573. #endif
  574. #if _TYPE2_R_RIPPLE
  575. mTexcoord += Ripple(mTexcoord, _Speed2R, mask2.r, _Parameters2R);
  576. #endif
  577. #if _TYPE2_G_RIPPLE
  578. mTexcoord += Ripple(mTexcoord, _Speed2G, mask2.g, _Parameters2G);
  579. #endif
  580. #if _TYPE2_B_RIPPLE
  581. mTexcoord += Ripple(mTexcoord, _Speed2B, mask2.b, _Parameters2B);
  582. #endif
  583. //flowlight------------------------------------------------------------------------------------------------------------------------------
  584. #if _TYPE_R_FLOWLIGHT
  585. mColor.rgb += Flowlight(mTexcoord, _SpeedR, mask.r, _ParametersR);
  586. #endif
  587. #if _TYPE_G_FLOWLIGHT
  588. mColor.rgb += Flowlight(mTexcoord, _SpeedG, mask.g, _ParametersG);
  589. #endif
  590. #if _TYPE_B_FLOWLIGHT
  591. mColor.rgb += Flowlight(mTexcoord, _SpeedB, mask.b, _ParametersB);
  592. #endif
  593. #if _TYPE2_R_FLOWLIGHT
  594. mColor.rgb += Flowlight(mTexcoord, _Speed2R, mask2.r, _Parameters2R);
  595. #endif
  596. #if _TYPE2_G_FLOWLIGHT
  597. mColor.rgb += Flowlight(mTexcoord, _Speed2G, mask2.g, _Parameters2G);
  598. #endif
  599. #if _TYPE2_B_FLOWLIGHT
  600. mColor.rgb += Flowlight(mTexcoord, _Speed2B, mask2.b, _Parameters2B);
  601. #endif
  602. //
  603. spiral------------------------------------------------------------------------------------------------------------------------------
  604. //#if _TYPE_R_SPIRAL
  605. // mTexcoord += Spiral(mTexcoord, _SpeedR, mask.r, _ParametersR);
  606. //#endif
  607. //#if _TYPE_G_SPIRAL
  608. // mTexcoord += Spiral(mTexcoord, _SpeedG, mask.g, _ParametersG);
  609. //#endif
  610. //#if _TYPE_B_SPIRAL
  611. // mTexcoord += Spiral(mTexcoord, _SpeedB, mask.b, _ParametersB);
  612. //#endif
  613. //#if _TYPE2_R_SPIRAL
  614. // mTexcoord += Spiral(mTexcoord, _Speed2R, mask2.r, _Parameters2R);
  615. //#endif
  616. //#if _TYPE2_G_SPIRAL
  617. // mTexcoord += Spiral(mTexcoord, _Speed2G, mask2.g, _Parameters2G);
  618. //#endif
  619. //#if _TYPE2_B_SPIRAL
  620. // mTexcoord += Spiral(mTexcoord, _Speed2B, mask2.b, _Parameters2B);
  621. //#endif
  622. #if _ENABLE_FX1 || _ENABLE_FX2 || _ENABLE_FX3 || _ENABLE_FX4
  623. float2 fxUV;
  624. fixed3 fxColor;
  625. float concentration;
  626. #endif
  627. #if _ENABLE_FX1_ENABLE_FX1 START
  628. #if _FX1_MASK_R
  629. concentration = mask.r;
  630. #elif _FX1_MASK_G
  631. concentration = mask.g;
  632. #elif _FX1_MASK_B
  633. concentration = mask.b;
  634. #elif _FX1_MASK2_R
  635. concentration = mask2.r;
  636. #elif _FX1_MASK2_G
  637. concentration = mask2.g;
  638. #elif _FX1_MASK2_B
  639. concentration = mask2.b;
  640. #elif _FX1_MASK_NULL
  641. concentration = 1;
  642. #endif
  643. if (_Fx1IsOneMinus)
  644. {
  645. concentration = 1 - concentration;
  646. }
  647. fxUV = IN.fx1Texcoord;
  648. if (_Fx1SpeedMove != 0.0)
  649. {
  650. fxUV += Move(fxUV, _Fx1SpeedMove, 1, _Fx1ParametersMove);
  651. }
  652. if (_Fx1SpeedWave != 0.0)
  653. {
  654. fxUV += Wave(fxUV, _Fx1SpeedWave, 1, _Fx1ParametersWave);
  655. }
  656. if (_Fx1SpeedFlex != 0.0)
  657. {
  658. fxUV += Flex(fxUV, _Fx1SpeedFlex, 1, _Fx1ParametersFlex);
  659. }
  660. if (_Fx1SpeedSpiral != 0.0)
  661. {
  662. fxUV = Spiral(fxUV, _Fx1SpeedSpiral, 1, _Fx1ParametersSpiral);
  663. }
  664. if (_Fx1SpeedFrameAni != 0.0)
  665. {
  666. fxUV = FrameAni(fxUV, _Fx1SpeedFrameAni, 1, _Fx1ParametersFrameAni);
  667. }
  668. fxColor = tex2D(_Fx1Tex, fxUV).rgb * concentration;
  669. if (_Fx1SpeedFlash != 0.0)
  670. {
  671. if (fxColor.r > 0.001 || fxColor.g > 0.001 || fxColor.b > 0.001)
  672. {
  673. fxColor.rgb *= Flash(fxUV, _Fx1SpeedFlash, 1, _Fx1ParametersFlash);
  674. }
  675. }
  676. mColor.rgb += fxColor;
  677. #endif_ENABLE_FX1 END
  678. #if _ENABLE_FX2_ENABLE_FX2 START
  679. #if _FX2_MASK_R
  680. concentration = mask.r;
  681. #elif _FX2_MASK_G
  682. concentration = mask.g;
  683. #elif _FX2_MASK_B
  684. concentration = mask.b;
  685. #elif _FX2_MASK2_R
  686. concentration = mask2.r;
  687. #elif _FX2_MASK2_G
  688. concentration = mask2.g;
  689. #elif _FX2_MASK2_B
  690. concentration = mask2.b;
  691. #elif _FX2_MASK_NULL
  692. concentration = 1;
  693. #endif
  694. if (_Fx2IsOneMinus)
  695. {
  696. concentration = 1 - concentration;
  697. }
  698. fxUV = IN.fx2Texcoord;
  699. if (_Fx2SpeedMove != 0.0)
  700. {
  701. fxUV += Move(fxUV, _Fx2SpeedMove, 1, _Fx2ParametersMove);
  702. }
  703. if (_Fx2SpeedWave != 0.0)
  704. {
  705. fxUV += Wave(fxUV, _Fx2SpeedWave, 1, _Fx2ParametersWave);
  706. }
  707. if (_Fx2SpeedFlex != 0.0)
  708. {
  709. fxUV += Flex(fxUV, _Fx2SpeedFlex, 1, _Fx2ParametersFlex);
  710. }
  711. if (_Fx2SpeedSpiral != 0.0)
  712. {
  713. fxUV = Spiral(fxUV, _Fx2SpeedSpiral, 1, _Fx2ParametersSpiral);
  714. }
  715. if (_Fx2SpeedFrameAni != 0.0)
  716. {
  717. fxUV = FrameAni(fxUV, _Fx2SpeedFrameAni, 1, _Fx2ParametersFrameAni);
  718. }
  719. fxColor = tex2D(_Fx2Tex, fxUV).rgb * concentration;
  720. if (_Fx2SpeedFlash != 0.0)
  721. {
  722. if (fxColor.r > 0.001 || fxColor.g > 0.001 || fxColor.b > 0.001)
  723. {
  724. fxColor.rgb *= Flash(fxUV, _Fx2SpeedFlash, 1, _Fx2ParametersFlash);
  725. }
  726. }
  727. mColor.rgb += fxColor;
  728. #endif_ENABLE_FX2 END
  729. #if _ENABLE_FX3_ENABLE_FX3 START
  730. #if _FX3_MASK_R
  731. concentration = mask.r;
  732. #elif _FX3_MASK_G
  733. concentration = mask.g;
  734. #elif _FX3_MASK_B
  735. concentration = mask.b;
  736. #elif _FX3_MASK2_R
  737. concentration = mask2.r;
  738. #elif _FX3_MASK2_G
  739. concentration = mask2.g;
  740. #elif _FX3_MASK2_B
  741. concentration = mask2.b;
  742. #elif _FX3_MASK_NULL
  743. concentration = 1;
  744. #endif
  745. if (_Fx3IsOneMinus)
  746. {
  747. concentration = 1 - concentration;
  748. }
  749. fxUV = IN.fx3Texcoord;
  750. if (_Fx3SpeedMove != 0.0)
  751. {
  752. fxUV += Move(fxUV, _Fx3SpeedMove, 1, _Fx3ParametersMove);
  753. }
  754. if (_Fx3SpeedWave != 0.0)
  755. {
  756. fxUV += Wave(fxUV, _Fx3SpeedWave, 1, _Fx3ParametersWave);
  757. }
  758. if (_Fx3SpeedFlex != 0.0)
  759. {
  760. fxUV += Flex(fxUV, _Fx3SpeedFlex, 1, _Fx3ParametersFlex);
  761. }
  762. if (_Fx3SpeedSpiral != 0.0)
  763. {
  764. fxUV = Spiral(fxUV, _Fx3SpeedSpiral, 1, _Fx3ParametersSpiral);
  765. }
  766. if (_Fx3SpeedFrameAni != 0.0)
  767. {
  768. fxUV = FrameAni(fxUV, _Fx3SpeedFrameAni, 1, _Fx3ParametersFrameAni);
  769. }
  770. fxColor = tex2D(_Fx3Tex, fxUV).rgb * concentration;
  771. if (_Fx3SpeedFlash != 0.0)
  772. {
  773. if (fxColor.r > 0.001 || fxColor.g > 0.001 || fxColor.b > 0.001)
  774. {
  775. fxColor.rgb *= Flash(fxUV, _Fx3SpeedFlash, 1, _Fx3ParametersFlash);
  776. }
  777. }
  778. mColor.rgb += fxColor;
  779. #endif_ENABLE_FX3 END
  780. #if _ENABLE_FX4_ENABLE_FX4 START
  781. #if _FX4_MASK_R
  782. concentration = mask.r;
  783. #elif _FX4_MASK_G
  784. concentration = mask.g;
  785. #elif _FX4_MASK_B
  786. concentration = mask.b;
  787. #elif _FX4_MASK2_R
  788. concentration = mask2.r;
  789. #elif _FX4_MASK2_G
  790. concentration = mask2.g;
  791. #elif _FX4_MASK2_B
  792. concentration = mask2.b;
  793. #elif _FX4_MASK_NULL
  794. concentration = 1;
  795. #endif
  796. if (_Fx4IsOneMinus)
  797. {
  798. concentration = 1 - concentration;
  799. }
  800. fxUV = IN.fx4Texcoord;
  801. if (_Fx4SpeedMove != 0.0)
  802. {
  803. fxUV += Move(fxUV, _Fx4SpeedMove, 1, _Fx4ParametersMove);
  804. }
  805. if (_Fx4SpeedWave != 0.0)
  806. {
  807. fxUV += Wave(fxUV, _Fx4SpeedWave, 1, _Fx4ParametersWave);
  808. }
  809. if (_Fx4SpeedFlex != 0.0)
  810. {
  811. fxUV += Flex(fxUV, _Fx4SpeedFlex, 1, _Fx4ParametersFlex);
  812. }
  813. if (_Fx4SpeedSpiral != 0.0)
  814. {
  815. fxUV = Spiral(fxUV, _Fx4SpeedSpiral, 1, _Fx4ParametersSpiral);
  816. }
  817. if (_Fx3SpeedFrameAni != 0.0)
  818. {
  819. fxUV = FrameAni(fxUV, _Fx4SpeedFrameAni, 1, _Fx4ParametersFrameAni);
  820. }
  821. fxColor = tex2D(_Fx4Tex, fxUV).rgb * concentration;
  822. if (_Fx4SpeedFlash != 0.0)
  823. {
  824. if (fxColor.r > 0.001 || fxColor.g > 0.001 || fxColor.b > 0.001)
  825. {
  826. fxColor.rgb *= Flash(fxUV, _Fx4SpeedFlash, 1, _Fx4ParametersFlash);
  827. }
  828. }
  829. mColor.rgb += fxColor;
  830. #endif_ENABLE_FX4 END
  831. half4 color = (tex2D(_MainTex, mTexcoord) + _TextureSampleAdd) * mColor;
  832. #else
  833. half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
  834. #endif
  835. #ifdef UNITY_UI_CLIP_RECT
  836. color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
  837. #endif
  838. #ifdef UNITY_UI_ALPHACLIP
  839. clip(color.a - 0.001);
  840. #endif
  841. return color;
  842. }
  843. ENDCG
  844. }
  845. }
  846. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/122612
推荐阅读
相关标签
  

闽ICP备14008679号