Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
- Shader "UI/Substance"
- {
- Properties
- {
- [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
- _Color ("Tint", Color) = (1,1,1,1)
- _StencilComp ("Stencil Comparison", Float) = 8
- _Stencil ("Stencil ID", Float) = 0
- _StencilOp ("Stencil Operation", Float) = 0
- _StencilWriteMask ("Stencil Write Mask", Float) = 255
- _StencilReadMask ("Stencil Read Mask", Float) = 255
- _ColorMask ("Color Mask", Float) = 15
- [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
- // substance
- [NoScaleOffset]_RandomnessTex("Randomness Texture", 2D) = "white" {}
- _Magnitude("Magnitude", Range(0,1)) = 1
- [NoScaleOffset]_SurfaceMask("Surface mask ", 2D) = "white" {}
- [NoScaleOffset]_SurfaceMotionUp("Surface motion above", 2D) = "white" {}
- [NoScaleOffset]_SurfaceMotionDown("Surface motion below", 2D) = "white" {}
- _SurfaceCol("Surface color", Color) = (1,1,1,1)
- _Percentage("[0,1] Current substance percentage", Range(0,1)) = 0.5
- [NoScaleOffset]_ShapeTex("Shape (alpha), Frame (rgb)", 2D) = "white" {}
- [Toggle] _Effect1 ("Effect 1", Float) = 1
- _MotionSpeed1 ("Motion speed", Vector) = (1,1,0,0)
- [NoScaleOffset]_EffectTex1("Effect texture", 2D) = "white" {}
- [NoScaleOffset]_MotionTex1("Texture describing movement", 2D) = "white" {}
- _EffectCol1("Effect color", Color) = (1,1,1,1)
- [Toggle] _Effect2("Effect 2", Float) = 1
- _MotionSpeed2("Motion speed", Vector) = (1,1,0,0)
- [NoScaleOffset]_EffectTex2("Effect texture", 2D) = "white" {}
- [NoScaleOffset]_MotionTex2("Texture describing movement", 2D) = "white" {}
- _EffectCol2("Effect color", Color) = (1,1,1,1)
- }
- SubShader
- {
- Tags
- {
- "Queue"="Transparent"
- "IgnoreProjector"="True"
- "RenderType"="Transparent"
- "PreviewType"="Plane"
- "CanUseSpriteAtlas"="True"
- }
- Stencil
- {
- Ref [_Stencil]
- Comp [_StencilComp]
- Pass [_StencilOp]
- ReadMask [_StencilReadMask]
- WriteMask [_StencilWriteMask]
- }
- Cull Off
- Lighting Off
- ZWrite Off
- ZTest [unity_GUIZTestMode]
- Blend SrcAlpha OneMinusSrcAlpha
- ColorMask [_ColorMask]
- Pass
- {
- Name "Default"
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma target 2.0
- #include "UnityCG.cginc"
- #include "UnityUI.cginc"
- #pragma multi_compile __ UNITY_UI_ALPHACLIP
- struct appdata_t
- {
- float4 vertex : POSITION;
- float4 color : COLOR;
- float2 texcoord : TEXCOORD0;
- UNITY_VERTEX_INPUT_INSTANCE_ID
- };
- struct v2f
- {
- float4 vertex : SV_POSITION;
- fixed4 color : COLOR;
- float2 texcoord : TEXCOORD0;
- float4 worldPosition : TEXCOORD1;
- UNITY_VERTEX_OUTPUT_STEREO
- };
- fixed4 _Color;
- fixed4 _TextureSampleAdd;
- float4 _ClipRect;
- v2f vert(appdata_t IN)
- {
- v2f OUT;
- UNITY_SETUP_INSTANCE_ID(IN);
- UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
- OUT.worldPosition = IN.vertex;
- OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
- OUT.texcoord = IN.texcoord;
- OUT.color = IN.color * _Color;
- return OUT;
- }
- sampler2D _MainTex;
- sampler2D _SurfaceMask;
- sampler2D _SurfaceMotionUp;
- sampler2D _SurfaceMotionDown;
- half4 _SurfaceCol;
- sampler2D _RandomnessTex;
- float _Magnitude;
- uniform float _Percentage; // [0,1]
- sampler2D _ShapeTex;
- float _Effect1;
- sampler2D _MotionTex1;
- sampler2D _EffectTex1;
- half4 _EffectCol1;
- float4 _MotionSpeed1;
- float _Effect2;
- sampler2D _MotionTex2;
- sampler2D _EffectTex2;
- half4 _EffectCol2;
- float4 _MotionSpeed2;
- fixed4 frag(v2f i) : SV_Target
- {
- /*half4 color = (tex2D(_MainTex, i.texcoord) + _TextureSampleAdd) * i.color;
- color.a *= UnityGet2DClipping(i.worldPosition.xy, _ClipRect);
- #ifdef UNITY_UI_ALPHACLIP
- clip (color.a - 0.001);
- #endif
- return color;*/
- fixed4 col = fixed4(0,0,0,1); // fixed4(0,0,0,1)
- float alpha = col.a;
- fixed4 transparent = fixed4(0, 0, 0, 0);
- // FRAME
- float4 frameColor = tex2D(_ShapeTex, i.texcoord);
- float _FrameMask = frameColor.r; // greyscale texture
- // FRAME
- if( frameColor.a < 0.1)
- {
- return transparent;
- }
- // EFFECT 1
- if (_Effect1 > 0)
- {
- fixed4 motion1 = tex2D(_MotionTex1, i.texcoord);
- motion1.y -= _Time.x * _MotionSpeed1.y;
- motion1.x -= _Time.x * _MotionSpeed1.x;
- fixed4 effect1 = tex2D(_EffectTex1, motion1.xy) * motion1.a;
- effect1 *= _EffectCol1;
- col += effect1 * effect1.a;
- }
- // EFFECT 1
- // EFFECT 2
- if (_Effect2 > 0)
- {
- fixed4 motion2 = tex2D(_MotionTex2, i.texcoord);
- motion2.y -= _Time.x * _MotionSpeed2.y;
- motion2.x -= _Time.x * _MotionSpeed2.x;
- fixed4 effect2 = tex2D(_EffectTex2, motion2.xy) * motion2.a;
- effect2 *= _EffectCol2;
- col += effect2 * effect2.a;
- }
- // EFFECT 2
- col.a = alpha;
- // FULL SUBSTANCE
- if (_Percentage == 1)
- {
- return fixed4(col.rgb * _FrameMask, col.a);;
- }
- // FULL SUBSTANCE
- // SURFACE DISTORTION
- float2 distuv = float2(i.texcoord.x + _Time.x * 2 , i.texcoord.y + _Time.x * 2); // distortion y and x
- float2 disp = tex2D(_RandomnessTex, distuv).xy;
- disp = ((disp * 2) - 1) * _Magnitude;
- // SURFACE DISTORTION
- // SUBSTANCE PERCENTAGE
- int up = 0;
- float2 newUV;
- if (i.texcoord.y >= _Percentage) // above we want transparent background
- {
- fixed4 motion = tex2D(_SurfaceMotionUp, i.texcoord + disp);
- motion.x -= _Time.x * 8;
- newUV = float2(motion.x, 1 - (i.texcoord.y - _Percentage));
- up = 1;
- }
- else // below we use blended color
- {
- fixed4 motion = tex2D(_SurfaceMotionDown, i.texcoord + disp);
- motion.x -= _Time.x * 8;
- newUV = float2(motion.x, 1 - (_Percentage - i.texcoord.y));
- }
- fixed4 surfaceMask = tex2D(_SurfaceMask, newUV);
- if (up == 1)
- {
- col.a = surfaceMask.a;
- }
- // SUBSTANCE PERCENTAGE
- // BLEND
- surfaceMask *= _SurfaceCol;
- float srcFactor = surfaceMask.a;
- float dstFactor = 1 - srcFactor;
- fixed4 newCol = fixed4(col.rgb * dstFactor + surfaceMask.rgb * srcFactor, col.a);
- newCol = fixed4(newCol.rgb * _FrameMask, newCol.a);
- //return newCol;
- // BLEND
- // SURFACE
- //half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
- half4 color = newCol;
- color.a *= UnityGet2DClipping(i.worldPosition.xy, _ClipRect);
- #ifdef UNITY_UI_ALPHACLIP
- clip (color.a - 0.001);
- #endif
- return color;
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement