Restructured for new direction.
This commit is contained in:
142
Assets/Shaders/UIEdgeDarken/UIEdgeDarken.shader
Normal file
142
Assets/Shaders/UIEdgeDarken/UIEdgeDarken.shader
Normal file
@@ -0,0 +1,142 @@
|
||||
Shader "BriarQueen/UI/Edge Darken"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
|
||||
_Color ("Tint", Color) = (0, 0, 0, 0.65)
|
||||
|
||||
_Amount ("Amount", Range(0, 1)) = 1
|
||||
_EdgeDarkness ("Edge Darkness", Range(0, 1)) = 1
|
||||
_CenterDarkness ("Center Darkness", Range(0, 1)) = 0
|
||||
_EdgeWidth ("Edge Width", Range(0.001, 0.5)) = 0.22
|
||||
_Softness ("Softness", Range(0.001, 0.5)) = 0.18
|
||||
[HideInInspector] _RectSize ("Rect Size", Vector) = (1, 1, 0, 0)
|
||||
[HideInInspector] _RectPivot ("Rect Pivot", Vector) = (0.5, 0.5, 0, 0)
|
||||
|
||||
_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
|
||||
}
|
||||
|
||||
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_local _ UNITY_UI_CLIP_RECT
|
||||
#pragma multi_compile_local _ UNITY_UI_ALPHACLIP
|
||||
|
||||
struct AppData
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 localPosition : TEXCOORD1;
|
||||
float4 worldPosition : TEXCOORD2;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
fixed4 _Color;
|
||||
fixed4 _TextureSampleAdd;
|
||||
float4 _ClipRect;
|
||||
|
||||
float _Amount;
|
||||
float _EdgeDarkness;
|
||||
float _CenterDarkness;
|
||||
float _EdgeWidth;
|
||||
float _Softness;
|
||||
float4 _RectSize;
|
||||
float4 _RectPivot;
|
||||
|
||||
Varyings Vert(AppData input)
|
||||
{
|
||||
Varyings output;
|
||||
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
output.worldPosition = input.vertex;
|
||||
output.vertex = UnityObjectToClipPos(input.vertex);
|
||||
output.uv = input.texcoord;
|
||||
output.localPosition = input.vertex.xy;
|
||||
output.color = input.color * _Color;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
fixed4 Frag(Varyings input) : SV_Target
|
||||
{
|
||||
fixed4 color = (tex2D(_MainTex, input.uv) + _TextureSampleAdd) * input.color;
|
||||
|
||||
float2 safeRectSize = max(_RectSize.xy, float2(0.0001, 0.0001));
|
||||
float2 rectUv = saturate((input.localPosition / safeRectSize) + _RectPivot.xy);
|
||||
float edgeDistance = min(
|
||||
min(rectUv.x, 1.0 - rectUv.x),
|
||||
min(rectUv.y, 1.0 - rectUv.y));
|
||||
float outerEdge = 1.0 - smoothstep(_EdgeWidth, _EdgeWidth + _Softness, edgeDistance);
|
||||
float darkness = lerp(_CenterDarkness, _EdgeDarkness, outerEdge);
|
||||
|
||||
color.a *= saturate(_Amount) * darkness;
|
||||
|
||||
#ifdef UNITY_UI_CLIP_RECT
|
||||
color.a *= UnityGet2DClipping(input.worldPosition.xy, _ClipRect);
|
||||
#endif
|
||||
|
||||
#ifdef UNITY_UI_ALPHACLIP
|
||||
clip(color.a - 0.001);
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user