Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "_GoodCompany/GC_UI_UberShader"
- {
- Properties
- {
- [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
- [Header(Shader Features)]
- [Toggle(MIPMAP_BIAS)]_a ("Custom Mipmap Bias", float) = 0
- [Toggle(RECTMASK)]_c ("Rectmask clipping", float) = 0
- [Toggle(SCROLLING)]_e ("Scrolling Texture", float) = 0
- [Toggle(IMPROVED_ALPHA)]_f ("Harder Alpha", float) = 0
- [Toggle(EXTERNAL_ALPHA)]_g ("Use external alpha texture", float) = 0
- [Toggle(COLOR_TRANSITION)]_h ("Do Color Transition", float) = 0
- [Toggle(TEXTURE_TRANSITION)]_i ("Do Texture Transition", float) = 0
- [Toggle(PREMULTIPLIED)]_j ("Premultiplied alpha (blend mode One/OneMinusSrcAlpha)", float) = 0
- [Header(Settings)]
- _Color("Tint", Color) = (1,1,1,1)
- _Scrolling("Scrolling direction", Vector) = (1,1,0,0)
- _MipmapBias("Mipmap bias", Range(-2, 1)) = 0
- _ExternalAlpha("External alpha texture", 2D) = "white" {}
- _TransitionReferenceTexture("Transition Reference Texture (greyscale)", 2D) = "white" {}
- _TransitionColorTexture("Transition Color Texture", 2D) = "grey" {}
- _TransitionColor("Transition Color", Color) = (0, 0, 0, 0)
- _TransitionValue("Transition Value", Range(0, 1)) = 1
- [Space(20)]
- [Header(BlendMode)]
- [Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("Source", Float) = 1
- [Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("Destination", Float) = 10
- //stuff the user probably doesn't understand anyways, we can bring it back if we end up needing it,
- //but until then it's here and scripts can touch it as usual
- [HideInInspector]_StencilComp("Stencil Comparison", Float) = 8
- [HideInInspector]_Stencil("Stencil ID", Float) = 0
- [HideInInspector]_StencilOp("Stencil Operation", Float) = 0
- [HideInInspector]_StencilWriteMask("Stencil Write Mask", Float) = 255
- [HideInInspector]_StencilReadMask("Stencil Read Mask", Float) = 255
- [HideInInspector]_ColorMask("Color Mask", Float) = 15
- }
- SubShader
- {
- Tags
- {
- "Queue" = "Transparent"
- "IgnoreProjector" = "True"
- "RenderType" = "Transparent"
- "PreviewType" = "Plane"
- "CanUseSpriteAtlas" = "True"
- }
- Stencil
- {
- Ref[_Stencil]
- Comp[_StencilComp]
- Pass[_StencilOp]
- ReadMask[_StencilReadMask]
- WriteMask[_StencilWriteMask]
- }
- LOD 0
- Cull Off
- Lighting Off
- ZWrite Off
- ZTest Always
- Blend [_SrcBlend] [_DstBlend]
- ColorMask[_ColorMask]
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- #include "UnityUI.cginc"
- #pragma shader_feature MIPMAP_BIAS
- #pragma shader_feature UNITY_UI_ALPHACLIP
- #pragma shader_feature RECTMASK
- #pragma shader_feature SCROLLING
- #pragma shader_feature IMPROVED_ALPHA
- #pragma shader_feature EXTERNAL_ALPHA
- #pragma shader_feature COLOR_TRANSITION
- #pragma shader_feature TEXTURE_TRANSITION
- #pragma shader_feature PREMULTIPLIED
- struct appdata_t
- {
- float4 vertex : POSITION;
- float4 color : COLOR;
- float2 texcoord : TEXCOORD0;
- };
- struct v2f
- {
- float4 vertex : SV_POSITION;
- fixed4 color : COLOR;
- half2 texcoord : TEXCOORD0;
- float4 worldPos : TEXCOORD2;
- };
- fixed4 _Color;
- sampler2D _MainTex;
- bool _UseAlphaClip;
- #ifdef SCROLLING
- float2 _Scrolling;
- #endif
- #ifdef RECTMASK
- float4 _ClipRect;
- #endif
- #ifdef MIPMAP_BIAS
- float _MipmapBias;
- #endif
- #ifdef EXTERNAL_ALPHA
- sampler2D _ExternalAlpha;
- #endif
- #ifdef COLOR_TRANSITION
- sampler2D _TransitionReferenceTexture;
- float4 _TransitionColor;
- float _TransitionValue;
- #else
- #ifdef TEXTURE_TRANSITION
- sampler2D _TransitionReferenceTexture;
- sampler2D _TransitionColorTexture;
- float _TransitionValue;
- #endif
- #endif
- v2f vert(appdata_t IN)
- {
- v2f OUT;
- OUT.worldPos = IN.vertex;
- OUT.vertex = UnityObjectToClipPos(IN.vertex);
- OUT.texcoord = IN.texcoord;
- #ifdef UNITY_HALF_TEXEL_OFFSET
- OUT.vertex.xy += (_ScreenParams.zw - 1.0)*float2(-1,1);
- #endif
- OUT.color = IN.color * _Color;
- return OUT;
- }
- float _CutOff;
- bool _HardBlend = false;
- bool _NoOuterClip = false;
- fixed4 frag(v2f IN) : SV_Target
- {
- float2 scrollingCoordinates = IN.texcoord;
- #ifdef SCROLLING
- scrollingCoordinates += _Scrolling * _Time.y;
- #endif
- #ifdef MIPMAP_BIAS
- half4 color = tex2Dbias(_MainTex, float4(scrollingCoordinates, 0, _MipmapBias));
- #else
- half4 color = tex2D(_MainTex, scrollingCoordinates);
- #endif
- color *= IN.color;
- #ifdef PREMULTIPLIED
- color.rgb *= IN.color.a;
- #endif
- #ifdef COLOR_TRANSITION
- float transitionTex = tex2D(_TransitionReferenceTexture, IN.texcoord).r;
- float transitionTexChange = fwidth(transitionTex) * 0.5;
- float4 transitionColor = float4(_TransitionColor.rgb, min(color.a, _TransitionColor.a));
- #ifdef PREMULTIPLIED
- transitionColor.rgb *= transitionColor.a;
- #endif
- float transitionAmount = 1 - smoothstep(_TransitionValue - transitionTexChange, _TransitionValue + transitionTexChange, 1 - transitionTex);
- color = lerp(color, transitionColor, transitionAmount);
- #else
- #ifdef TEXTURE_TRANSITION
- float transitionTex = tex2D(_TransitionReferenceTexture, IN.texcoord).r;
- float transitionTexChange = fwidth(transitionTex) * 0.5;
- #ifdef MIPMAP_BIAS
- float4 transitionColor = tex2Dbias(_TransitionColorTexture, float4(scrollingCoordinates, 0, _MipmapBias)) * IN.color;
- #else
- float4 transitionColor = tex2D(_TransitionColorTexture, scrollingCoordinates) * IN.color;
- #endif
- float transitionAmount = 1 - smoothstep(_TransitionValue - transitionTexChange, _TransitionValue + transitionTexChange, 1 - transitionTex);
- color = lerp(color, transitionColor, transitionAmount);
- #endif
- #endif
- #ifdef RECTMASK
- #ifdef PREMULTIPLIED
- color.rgba *= UnityGet2DClipping(IN.worldPos.xy, _ClipRect);
- #else
- color.a *= UnityGet2DClipping(IN.worldPos.xy, _ClipRect);
- #endif
- #endif
- #ifdef EXTERNAL_ALPHA
- #ifdef MIPMAP_BIAS
- float externalAlpha = tex2Dbias(_ExternalAlpha, float4(IN.texcoord, 0, _MipmapBias)).a;
- #else
- float externalAlpha = tex2D(_ExternalAlpha, IN.texcoord).a;
- #endif
- #ifdef PREMULTIPLIED
- color.rgba *= externalAlpha;
- #else
- color.a *= externalAlpha;
- #endif
- #endif
- #ifdef UNITY_UI_ALPHACLIP //if the keyword is set we don't even ask the property, we just clip
- clip(color.a - 0.001);
- #else
- if (_UseAlphaClip)
- clip(color.a - 0.001);
- #endif
- #ifdef IMPROVED_ALPHA
- float alphaChange = fwidth(color.a) * 0.5;
- float newAlpha = smoothstep(0.5-alphaChange, 0.5+alphaChange, color.a);
- #ifdef PREMULTIPLIED
- //max is here to prevent infinity
- float relativeAlpha = newAlpha / max(color.a, 0.000001);
- color.rgba *= relativeAlpha;
- #else
- color.a = newAlpha;
- #endif
- #endif
- return color;
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement