备份CatanBuilding瘦身独立工程
This commit is contained in:
8
LocalPackages/SoftMaskForUGUI/Shaders/Resources.meta
Normal file
8
LocalPackages/SoftMaskForUGUI/Shaders/Resources.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cabb208e7f3604e429ddca9c5141b821
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
Shader "Hidden/SoftMask" {
|
||||
|
||||
SubShader {
|
||||
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
|
||||
LOD 100
|
||||
|
||||
Cull Off
|
||||
ZWrite Off
|
||||
Blend SrcAlpha One
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
Pass {
|
||||
CGPROGRAM
|
||||
#pragma vertex vert_img
|
||||
#pragma fragment frag
|
||||
#pragma target 2.0
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
sampler2D _MainTex;
|
||||
float _Softness;
|
||||
float _Alpha;
|
||||
|
||||
fixed4 frag (v2f_img i) : SV_Target
|
||||
{
|
||||
half softness = max(_Softness, 0.0001f);
|
||||
return saturate(tex2D(_MainTex, i.uv).a/softness) * _Alpha;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2933b413a51fc4ff3a83c7ef4177ae84
|
||||
timeCreated: 1539779942
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,117 @@
|
||||
Shader "Hidden/UI/Default (SoftMaskable)"
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityUI.cginc"
|
||||
|
||||
#pragma multi_compile __ UNITY_UI_CLIP_RECT
|
||||
#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
||||
|
||||
#include "Packages/com.coffee.softmask-for-ugui/Shaders/SoftMask.cginc" // Add for soft mask
|
||||
#pragma shader_feature __ SOFTMASK_EDITOR // Add for soft mask
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
fixed4 _Color;
|
||||
fixed4 _TextureSampleAdd;
|
||||
float4 _ClipRect;
|
||||
float4 _MainTex_ST;
|
||||
|
||||
v2f vert(appdata_t v)
|
||||
{
|
||||
v2f OUT;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
|
||||
OUT.worldPosition = v.vertex;
|
||||
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
|
||||
|
||||
OUT.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
|
||||
|
||||
OUT.color = v.color * _Color;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
fixed4 frag(v2f IN) : SV_Target
|
||||
{
|
||||
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
|
||||
|
||||
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
|
||||
|
||||
#ifdef UNITY_UI_ALPHACLIP
|
||||
clip (color.a - 0.001);
|
||||
#endif
|
||||
|
||||
color.a *= SoftMask(IN.vertex, IN.worldPosition); // Add for soft mask
|
||||
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9839189d918374a318d397a86e90aa73
|
||||
timeCreated: 1539847292
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
68
LocalPackages/SoftMaskForUGUI/Shaders/SoftMask.cginc
Normal file
68
LocalPackages/SoftMaskForUGUI/Shaders/SoftMask.cginc
Normal file
@@ -0,0 +1,68 @@
|
||||
#ifndef UI_SOFTMASK_INCLUDED
|
||||
#define UI_SOFTMASK_INCLUDED
|
||||
|
||||
sampler2D _SoftMaskTex;
|
||||
float _Stencil;
|
||||
float4x4 _GameVP;
|
||||
float4x4 _GameTVP;
|
||||
half4 _MaskInteraction;
|
||||
uniform float _RenderScale;
|
||||
float CustomStep(float a, float x)
|
||||
{
|
||||
return x >= a;
|
||||
}
|
||||
|
||||
fixed Approximately(float4x4 a, float4x4 b)
|
||||
{
|
||||
float4x4 d = a - b;
|
||||
d = float4x4(
|
||||
abs(d[0]),
|
||||
abs(d[1]),
|
||||
abs(d[2]),
|
||||
abs(d[3])
|
||||
);
|
||||
|
||||
return step(
|
||||
max(d._m00,max(d._m01,max(d._m02,max(d._m03,
|
||||
max(d._m10,max(d._m11,max(d._m12,max(d._m13,
|
||||
max(d._m20,max(d._m21,max(d._m22,max(d._m23,
|
||||
max(d._m30,max(d._m31,max(d._m32,d._m33))))))))))))))),
|
||||
0.5);
|
||||
}
|
||||
|
||||
#if SOFTMASK_EDITOR
|
||||
float SoftMaskInternal(float4 clipPos, float4 wpos)
|
||||
#else
|
||||
float SoftMaskInternal(float4 clipPos)
|
||||
#endif
|
||||
{
|
||||
half2 view = clipPos.xy / (_ScreenParams.xy * _RenderScale);
|
||||
#if SOFTMASK_EDITOR
|
||||
fixed isSceneView = 1 - Approximately(UNITY_MATRIX_VP, _GameVP);
|
||||
float4 cpos = mul(_GameTVP, mul(UNITY_MATRIX_M, wpos));
|
||||
view = lerp(view, cpos.xy / cpos.w * 0.5 + 0.5, isSceneView);
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
view.y = lerp(view.y, 1 - view.y, CustomStep(0, _ProjectionParams.x));
|
||||
#endif
|
||||
#elif UNITY_UV_STARTS_AT_TOP
|
||||
view.y = lerp(view.y, 1 - view.y, CustomStep(0, _ProjectionParams.x));
|
||||
#endif
|
||||
|
||||
fixed4 mask = tex2D(_SoftMaskTex, view);
|
||||
half4 alpha = saturate(lerp(fixed4(1, 1, 1, 1), lerp(mask, 1 - mask, _MaskInteraction - 1), _MaskInteraction));
|
||||
#if SOFTMASK_EDITOR
|
||||
alpha *= CustomStep(0, view.x) * CustomStep(view.x, 1) * CustomStep(0, view.y) * CustomStep(view.y, 1);
|
||||
#endif
|
||||
|
||||
return alpha.x * alpha.y * alpha.z * alpha.w;
|
||||
}
|
||||
|
||||
#if SOFTMASK_EDITOR
|
||||
#define SOFTMASK_EDITOR_ONLY(x) x
|
||||
#define SoftMask(clipPos, worldPosition) SoftMaskInternal(clipPos, worldPosition)
|
||||
#else
|
||||
#define SOFTMASK_EDITOR_ONLY(x)
|
||||
#define SoftMask(clipPos, worldPosition) SoftMaskInternal(clipPos)
|
||||
#endif
|
||||
|
||||
#endif // UI_SOFTMASK_INCLUDED
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0f7e0d8262ac42cc9ec30a5aea12d72
|
||||
timeCreated: 1539995458
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user