-
-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add CompositeCanvasRenderer support
- Loading branch information
Showing
5 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
214 changes: 214 additions & 0 deletions
214
...es~/CompositeCanvasRenderer Support/Hidden-UI-CompositeCanvasRenderer-SoftMaskable.shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
Shader "Hidden/UI/CompositeCanvasRenderer (SoftMaskable)" | ||
{ | ||
Properties | ||
{ | ||
[Header(Main)] | ||
[PerRendererData] _MainTex ("Main Texture", 2D) = "white" {} | ||
_Color ("Tint", Color) = (1,1,1,1) | ||
|
||
[Header(Detail)] | ||
[Toggle(ENABLE_DETAIL)] _DETAIL ("Enable Detail", Float) = 0 | ||
_DetailTex ("Detail Texture", 2D) = "white" {} | ||
|
||
[Header(UV Animation)] | ||
[Toggle(ENABLE_UV_ANIMATION)] _UV_ANIMATION ("Enable UV Animation", Float) = 0 | ||
_UvTex ("UV Animation Texture (RG)", 2D) = "black" {} | ||
_UvSpeed("UV Animation Speed", Vector) = (0,0,0,0) | ||
_UvModifier ("UV Modifier", Range(-0.1, 0.1)) = 0 | ||
|
||
[Header(Mask)] | ||
[Toggle(ENABLE_MASK)] _MASK ("Enable Mask", Float) = 0 | ||
_MaskTex ("Mask Texture", 2D) = "white" {} | ||
_MaskSpeed("Mask Speed", Vector) = (0,0,0,0) | ||
|
||
[Header(Color Mode)] | ||
[KeywordEnum(Multipry, Additive, Subtract, Fill)] Color_Mode ("Color Mode", Int) = 0 | ||
|
||
[Header(Blend Mode)] | ||
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("Src Blend Mode", Int) = 1 | ||
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("Dst Blend Mode", Int) = 10 | ||
|
||
[Header(Stencil)] | ||
_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 [_SrcBlend] [_DstBlend] | ||
ColorMask [_ColorMask] | ||
|
||
Pass | ||
{ | ||
Name "Default" | ||
CGPROGRAM | ||
#pragma vertex vert | ||
#pragma fragment frag | ||
#pragma target 2.0 | ||
|
||
#include "UnityCG.cginc" | ||
#include "UnityUI.cginc" | ||
|
||
#include "Packages/com.coffee.softmask-for-ugui/Shaders/UISoftMask.cginc" // Add for soft mask | ||
#pragma multi_compile_local UI_SOFT_MASKABLE UI_SOFT_MASKABLE_EDITOR // Add for soft mask | ||
#pragma multi_compile_local _ UI_SOFT_MASKABLE_STEREO // Add for soft mask (stereo) | ||
|
||
#pragma multi_compile_local _ UNITY_UI_CLIP_RECT | ||
#pragma multi_compile_local _ UNITY_UI_ALPHACLIP | ||
#pragma multi_compile_local _ COLOR_MODE_ADDITIVE COLOR_MODE_FILL COLOR_MODE_SUBTRACT | ||
#pragma shader_feature_local ENABLE_DETAIL | ||
#pragma shader_feature_local ENABLE_UV_ANIMATION | ||
#pragma shader_feature_local ENABLE_MASK | ||
|
||
sampler2D _MainTex; | ||
fixed4 _Color; | ||
fixed4 _TextureSampleAdd; | ||
float4 _ClipRect; | ||
float4 _MainTex_ST; | ||
float _UIMaskSoftnessX; | ||
float _UIMaskSoftnessY; | ||
int _UIVertexColorAlwaysGammaSpace; | ||
sampler2D _UvTex; | ||
float2 _UvSpeed; | ||
float _UvModifier; | ||
sampler2D _MaskTex; | ||
float4 _MaskTex_ST; | ||
float2 _MaskSpeed; | ||
sampler2D _DetailTex; | ||
float4 _DetailTex_ST; | ||
|
||
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; | ||
float4 mask : TEXCOORD2; | ||
UNITY_VERTEX_OUTPUT_STEREO | ||
}; | ||
|
||
half4 applyColor(half4 color, half4 factor) | ||
{ | ||
#if COLOR_MODE_FILL | ||
color.rgb = factor.rgb * color.a; | ||
#elif COLOR_MODE_ADDITIVE | ||
color.rgb += factor.rgb * color.a; | ||
#elif COLOR_MODE_SUBTRACT | ||
color.rgb -= factor.rgb * color.a; | ||
#else | ||
color.rgb *= factor.rgb; | ||
#endif | ||
|
||
return color *= factor.a; | ||
} | ||
|
||
v2f vert(appdata_t v) | ||
{ | ||
v2f OUT; | ||
UNITY_SETUP_INSTANCE_ID(v); | ||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT); | ||
float4 vPosition = UnityObjectToClipPos(v.vertex); | ||
OUT.worldPosition = v.vertex; | ||
OUT.vertex = vPosition; | ||
|
||
float2 pixelSize = vPosition.w; | ||
pixelSize /= float2(1, 1) * abs(mul((float2x2)UNITY_MATRIX_P, _ScreenParams.xy)); | ||
|
||
float4 clampedRect = clamp(_ClipRect, -2e10, 2e10); | ||
float2 maskUV = (v.vertex.xy - clampedRect.xy) / (clampedRect.zw - clampedRect.xy); | ||
OUT.texcoord = TRANSFORM_TEX(v.texcoord.xy, _MainTex); | ||
OUT.mask = float4(v.vertex.xy * 2 - clampedRect.xy - clampedRect.zw, | ||
0.25 / (0.25 * half2(_UIMaskSoftnessX, _UIMaskSoftnessY) + abs(pixelSize.xy))); | ||
|
||
if (_UIVertexColorAlwaysGammaSpace) | ||
{ | ||
if (!IsGammaSpace()) | ||
{ | ||
v.color.rgb = UIGammaToLinear(v.color.rgb); | ||
} | ||
} | ||
|
||
OUT.color = v.color * _Color; | ||
return OUT; | ||
} | ||
|
||
fixed4 frag(v2f IN) : SV_Target | ||
{ | ||
//Round up the alpha color coming from the interpolator (to 1.0/256.0 steps) | ||
//The incoming alpha could have numerical instability, which makes it very sensible to | ||
//HDR color transparency blend, when it blends with the world's texture. | ||
const half alphaPrecision = half(0xff); | ||
const half invAlphaPrecision = half(1.0 / alphaPrecision); | ||
float2 uv = IN.texcoord; | ||
|
||
#if ENABLE_UV_ANIMATION | ||
uv += (tex2D(_UvTex, uv + _Time.y * _UvSpeed).rg - 0.5) * _UvModifier; | ||
#endif | ||
|
||
IN.color.a = round(IN.color.a * alphaPrecision) * invAlphaPrecision; | ||
half4 color = tex2D(_MainTex, uv) + _TextureSampleAdd; | ||
|
||
#if ENABLE_DETAIL | ||
color.rgb = tex2D(_DetailTex, uv).rgb; | ||
#endif | ||
|
||
#if UNITY_UI_CLIP_RECT | ||
half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(IN.mask.xy)) * IN.mask.zw); | ||
color.a *= m.x * m.y; | ||
#endif | ||
|
||
color.a *= SoftMask(IN.vertex, mul(unity_ObjectToWorld, IN.worldPosition)); // Add for soft mask | ||
|
||
|
||
#if UNITY_UI_ALPHACLIP | ||
SoftMaskClip (color.a - 0.001); | ||
#endif | ||
|
||
#if ENABLE_MASK | ||
const float2 maskUv = TRANSFORM_TEX(IN.texcoord.xy, _MaskTex); | ||
color *= tex2D(_MaskTex, maskUv + _Time.y * _MaskSpeed).a; | ||
#endif | ||
|
||
return applyColor(color, IN.color); | ||
} | ||
ENDCG | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...ompositeCanvasRenderer Support/Hidden-UI-CompositeCanvasRenderer-SoftMaskable.shader.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters