feat: support XBOX One/Series

close #385, close #394
This commit is contained in:
mob-sakai
2026-06-17 20:14:16 +09:00
parent f538ef2cba
commit 72bb1c5131
19 changed files with 91 additions and 123 deletions
@@ -1,21 +1,19 @@
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
SurfaceDescriptionInputs _fragInput; half4 uieffect_frag(SurfaceDescriptionInputs fragInput, float2 uv)
half4 uieffect_frag(float2 uv)
{ {
float2 prevUv = _fragInput.uv0.xy; float2 prevUv = fragInput.uv0.xy;
_fragInput.uv0.xy = uv; fragInput.uv0.xy = uv;
SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(_fragInput); SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(fragInput);
_fragInput.uv0.xy = prevUv; //fragInput.uv0.xy = prevUv;
half alpha = surfaceDescription.Alpha; half alpha = surfaceDescription.Alpha;
return half4(surfaceDescription.BaseColor * alpha + surfaceDescription.Emission, alpha); return half4(surfaceDescription.BaseColor * alpha + surfaceDescription.Emission, alpha);
} }
#define CANVAS_SHADERGRAPH
#define UIEFFECT_FRAG_STRUCT SurfaceDescriptionInputs
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
PackedVaryings vert_override(Attributes input) PackedVaryings vert_override(Attributes input)
{ {
Varyings output = BuildVaryings(input); Varyings output = BuildVaryings(input);
@@ -29,12 +27,11 @@ half4 frag_override(PackedVaryings packedInput) : SV_TARGET
Varyings unpacked = UnpackVaryings(packedInput); Varyings unpacked = UnpackVaryings(packedInput);
UNITY_SETUP_INSTANCE_ID(unpacked); UNITY_SETUP_INSTANCE_ID(unpacked);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked); UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
SurfaceDescriptionInputs surfaceDescriptionInputs = BuildSurfaceDescriptionInputs(unpacked); SurfaceDescriptionInputs fragInput = BuildSurfaceDescriptionInputs(unpacked);
SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(fragInput);
_fragInput = surfaceDescriptionInputs; const half4 origin = uieffect_frag(fragInput, fragInput.uv0.xy);
const half4 origin = uieffect_frag(_fragInput.uv0.xy); half4 color = uieffect(origin, fragInput.uv0.xy, unpacked.texCoord2, float4(unpacked.positionWS, 1), fragInput);
half4 color = uieffect(origin, _fragInput.uv0.xy, unpacked.texCoord2, float4(unpacked.positionWS, 1));
//Round up the alpha color coming from the interpolator (to 1.0/256.0 steps) //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 //The incoming alpha could have numerical instability, which makes it very sensible to
@@ -151,23 +151,21 @@ SubShader {
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
v2f _fragInput; fixed4 uieffect_frag(v2f IN, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
v2f IN = _fragInput;
float2 uvMove = uv - IN.texcoord0; float2 uvMove = uv - IN.texcoord0;
fixed4 color = fixed4(IN.color.rgb, tex2D(_MainTex, IN.texcoord0 + uvMove).a); fixed4 color = fixed4(IN.color.rgb, tex2D(_MainTex, IN.texcoord0 + uvMove).a);
color.rgb *= color.a; color.rgb *= color.a;
return color; return color;
} }
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT v2f
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
fixed4 frag (v2f IN) : COLOR fixed4 frag (v2f IN) : COLOR
{ {
_fragInput = IN; half4 color = uieffect(IN.texcoord0, IN.uvMask, IN.worldPosition, IN);
half4 color = uieffect(IN.texcoord0, IN.uvMask, IN.worldPosition);
color *= IN.color.a; color *= IN.color.a;
// Alternative implementation to UnityGet2DClipping with support for softness. // Alternative implementation to UnityGet2DClipping with support for softness.
@@ -156,10 +156,8 @@ SubShader{
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
v2f _fragInput; fixed4 uieffect_frag(v2f IN, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
v2f IN = _fragInput;
float2 uvMove = uv - IN.texcoord0; float2 uvMove = uv - IN.texcoord0;
fixed4 color = tex2D(_MainTex, IN.texcoord0 + uvMove); fixed4 color = tex2D(_MainTex, IN.texcoord0 + uvMove);
color = fixed4 (tex2D(_FaceTex, IN.texcoord1).rgb * IN.color.rgb, color.a); color = fixed4 (tex2D(_FaceTex, IN.texcoord1).rgb * IN.color.rgb, color.a);
@@ -167,13 +165,13 @@ SubShader{
return color; return color;
} }
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT v2f
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
fixed4 frag (v2f IN) : SV_Target fixed4 frag (v2f IN) : SV_Target
{ {
_fragInput = IN; half4 color = uieffect(IN.texcoord0, IN.uvMask, IN.worldPosition, IN);
half4 color = uieffect(IN.texcoord0, IN.uvMask, IN.worldPosition);
color *= IN.color.a; color *= IN.color.a;
// Alternative implementation to UnityGet2DClipping with support for softness. // Alternative implementation to UnityGet2DClipping with support for softness.
@@ -278,10 +278,8 @@ SubShader {
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
pixel_t _fragInput; fixed4 uieffect_frag(pixel_t input, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
pixel_t input = _fragInput;
float2 uvMove = uv - input.atlas; float2 uvMove = uv - input.atlas;
float c = tex2D(_MainTex, input.atlas + uvMove).a; float c = tex2D(_MainTex, input.atlas + uvMove).a;
@@ -345,14 +343,14 @@ SubShader {
} }
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT pixel_t
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
fixed4 PixShader(pixel_t input) : SV_Target fixed4 PixShader(pixel_t input) : SV_Target
{ {
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input; half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition, input);
half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition);
faceColor *= input.color.a; faceColor *= input.color.a;
#if UNITY_UI_CLIP_RECT #if UNITY_UI_CLIP_RECT
@@ -267,10 +267,8 @@ SubShader {
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
pixel_t _fragInput; fixed4 uieffect_frag(pixel_t input, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
pixel_t input = _fragInput;
float2 uvMove = uv - input.atlas; float2 uvMove = uv - input.atlas;
float c = tex2D(_MainTex, input.atlas + uvMove).a; float c = tex2D(_MainTex, input.atlas + uvMove).a;
@@ -340,14 +338,14 @@ SubShader {
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT pixel_t
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
fixed4 PixShader(pixel_t input) : SV_Target fixed4 PixShader(pixel_t input) : SV_Target
{ {
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input; half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition, input);
half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition);
faceColor *= input.color.a; faceColor *= input.color.a;
// Alternative implementation to UnityGet2DClipping with support for softness. // Alternative implementation to UnityGet2DClipping with support for softness.
@@ -236,10 +236,8 @@ SubShader {
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
pixel_t _fragInput; fixed4 uieffect_frag(pixel_t input, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
pixel_t input = _fragInput;
float2 uvMove = uv - input.texcoord0.xy; float2 uvMove = uv - input.texcoord0.xy;
half d = tex2D(_MainTex, input.texcoord0.xy + uvMove).a * input.param.x; half d = tex2D(_MainTex, input.texcoord0.xy + uvMove).a * input.param.x;
half4 c = input.faceColor * saturate(d - input.param.w); half4 c = input.faceColor * saturate(d - input.param.w);
@@ -268,14 +266,14 @@ SubShader {
} }
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT pixel_t
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
fixed4 PixShader(pixel_t input) : SV_Target fixed4 PixShader(pixel_t input) : SV_Target
{ {
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input; half4 c = uieffect(input.texcoord0.xy, input.uvMask, input.worldPosition, input);
half4 c = uieffect(input.texcoord0.xy, input.uvMask, input.worldPosition);
c *= input.alpha; c *= input.alpha;
// Alternative implementation to UnityGet2DClipping with support for softness. // Alternative implementation to UnityGet2DClipping with support for softness.
@@ -228,10 +228,8 @@ SubShader {
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
pixel_t _fragInput; fixed4 uieffect_frag(pixel_t input, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
pixel_t input = _fragInput;
float2 uvMove = uv - input.texcoord0; float2 uvMove = uv - input.texcoord0;
float d = tex2D(_MainTex, input.texcoord0.xy + uvMove).a; float d = tex2D(_MainTex, input.texcoord0.xy + uvMove).a;
@@ -282,14 +280,14 @@ SubShader {
} }
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT pixel_t
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
fixed4 PixShader(pixel_t input) : SV_Target fixed4 PixShader(pixel_t input) : SV_Target
{ {
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input; half4 faceColor = uieffect(input.texcoord0, input.uvMask, input.worldPosition, input);
half4 faceColor = uieffect(input.texcoord0, input.uvMask, input.worldPosition);
faceColor *= input.alpha; faceColor *= input.alpha;
// Alternative implementation to UnityGet2DClipping with support for softness // Alternative implementation to UnityGet2DClipping with support for softness
@@ -235,10 +235,8 @@ SubShader {
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
pixel_t _fragInput; fixed4 uieffect_frag(pixel_t input, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
pixel_t input = _fragInput;
float2 uvMove = uv - input.texcoord0.xy; float2 uvMove = uv - input.texcoord0.xy;
half d = tex2D(_MainTex, input.texcoord0.xy + uvMove).a * input.param.x; half d = tex2D(_MainTex, input.texcoord0.xy + uvMove).a * input.param.x;
@@ -268,6 +266,7 @@ SubShader {
} }
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT pixel_t
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
@@ -275,8 +274,7 @@ SubShader {
fixed4 PixShader(pixel_t input) : SV_Target fixed4 PixShader(pixel_t input) : SV_Target
{ {
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input; half4 c = uieffect(input.texcoord0.xy, input.uvMask, input.worldPosition, input);
half4 c = uieffect(input.texcoord0.xy, input.uvMask, input.worldPosition);
c *= input.alpha; c *= input.alpha;
// Alternative implementation to UnityGet2DClipping with support for softness. // Alternative implementation to UnityGet2DClipping with support for softness.
@@ -280,10 +280,8 @@ SubShader {
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
pixel_t _fragInput; fixed4 uieffect_frag(pixel_t input, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
pixel_t input = _fragInput;
float2 uvMove = uv - input.atlas; float2 uvMove = uv - input.atlas;
float c = tex2D(_MainTex, input.atlas + uvMove).a; float c = tex2D(_MainTex, input.atlas + uvMove).a;
@@ -346,14 +344,14 @@ SubShader {
return faceColor; return faceColor;
} }
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT pixel_t
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
fixed4 PixShader(pixel_t input) : SV_Target fixed4 PixShader(pixel_t input) : SV_Target
{ {
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input; half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition, input);
half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition);
faceColor *= input.color.a; faceColor *= input.color.a;
#if UNITY_UI_CLIP_RECT #if UNITY_UI_CLIP_RECT
@@ -144,10 +144,8 @@ SubShader {
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
v2f _fragInput; fixed4 uieffect_frag(v2f IN, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
v2f IN = _fragInput;
float2 uvMove = uv - IN.texcoord0; float2 uvMove = uv - IN.texcoord0;
fixed4 color = fixed4(IN.color.rgb, tex2D(_MainTex, IN.texcoord0 + uvMove).a); fixed4 color = fixed4(IN.color.rgb, tex2D(_MainTex, IN.texcoord0 + uvMove).a);
color.rgb *= color.a; color.rgb *= color.a;
@@ -155,13 +153,13 @@ SubShader {
} }
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT v2f
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
fixed4 frag (v2f IN) : COLOR fixed4 frag (v2f IN) : COLOR
{ {
_fragInput = IN; fixed4 color = uieffect(IN.texcoord0, IN.uvMask, IN.worldPosition, IN);
fixed4 color = uieffect(IN.texcoord0, IN.uvMask, IN.worldPosition);
color *= IN.color.a; color *= IN.color.a;
// Alternative implementation to UnityGet2DClipping with support for softness. // Alternative implementation to UnityGet2DClipping with support for softness.
@@ -157,10 +157,8 @@ SubShader{
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
v2f _fragInput; fixed4 uieffect_frag(v2f IN, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
v2f IN = _fragInput;
float2 uvMove = uv - IN.texcoord0; float2 uvMove = uv - IN.texcoord0;
fixed4 color = tex2D(_MainTex, IN.texcoord0 + uvMove); fixed4 color = tex2D(_MainTex, IN.texcoord0 + uvMove);
color = fixed4 (tex2D(_FaceTex, IN.texcoord1).rgb * IN.color.rgb, color.a); color = fixed4 (tex2D(_FaceTex, IN.texcoord1).rgb * IN.color.rgb, color.a);
@@ -169,13 +167,13 @@ SubShader{
} }
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT v2f
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
fixed4 frag (v2f IN) : SV_Target fixed4 frag (v2f IN) : SV_Target
{ {
_fragInput = IN; fixed4 color = uieffect(IN.texcoord0, IN.uvMask, IN.worldPosition, IN);
fixed4 color = uieffect(IN.texcoord0, IN.uvMask, IN.worldPosition);
color *= IN.color.a; color *= IN.color.a;
// Alternative implementation to UnityGet2DClipping with support for softness. // Alternative implementation to UnityGet2DClipping with support for softness.
@@ -272,10 +272,8 @@ SubShader {
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
pixel_t _fragInput; fixed4 uieffect_frag(pixel_t input, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
pixel_t input = _fragInput;
float2 uvMove = uv - input.atlas; float2 uvMove = uv - input.atlas;
float c = tex2D(_MainTex, input.atlas + uvMove).a; float c = tex2D(_MainTex, input.atlas + uvMove).a;
@@ -339,14 +337,14 @@ SubShader {
} }
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT pixel_t
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
fixed4 PixShader(pixel_t input) : SV_Target fixed4 PixShader(pixel_t input) : SV_Target
{ {
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input; half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition, input);
half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition);
faceColor *= input.color.a; faceColor *= input.color.a;
#if UNITY_UI_CLIP_RECT #if UNITY_UI_CLIP_RECT
@@ -258,10 +258,8 @@ SubShader {
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
pixel_t _fragInput; fixed4 uieffect_frag(pixel_t input, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
pixel_t input = _fragInput;
float2 uvMove = uv - input.atlas; float2 uvMove = uv - input.atlas;
float c = tex2D(_MainTex, input.atlas + uvMove).a; float c = tex2D(_MainTex, input.atlas + uvMove).a;
@@ -330,14 +328,14 @@ SubShader {
} }
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT pixel_t
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
fixed4 PixShader(pixel_t input) : SV_Target fixed4 PixShader(pixel_t input) : SV_Target
{ {
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input; half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition, input);
half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition);
faceColor *= input.color.a; faceColor *= input.color.a;
// Alternative implementation to UnityGet2DClipping with support for softness. // Alternative implementation to UnityGet2DClipping with support for softness.
@@ -228,10 +228,8 @@ SubShader {
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
pixel_t _fragInput; fixed4 uieffect_frag(pixel_t input, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
pixel_t input = _fragInput;
float2 uvMove = uv - input.texcoord0.xy; float2 uvMove = uv - input.texcoord0.xy;
half d = tex2D(_MainTex, input.texcoord0.xy + uvMove).a * input.param.x; half d = tex2D(_MainTex, input.texcoord0.xy + uvMove).a * input.param.x;
half4 c = input.faceColor * saturate(d - input.param.w); half4 c = input.faceColor * saturate(d - input.param.w);
@@ -260,14 +258,14 @@ SubShader {
} }
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT pixel_t
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
fixed4 PixShader(pixel_t input) : SV_Target fixed4 PixShader(pixel_t input) : SV_Target
{ {
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input; half4 c = uieffect(input.texcoord0.xy, input.uvMask, input.worldPosition, input);
half4 c = uieffect(input.texcoord0.xy, input.uvMask, input.worldPosition);
c *= input.alpha; c *= input.alpha;
// Alternative implementation to UnityGet2DClipping with support for softness. // Alternative implementation to UnityGet2DClipping with support for softness.
@@ -228,10 +228,8 @@ SubShader {
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
pixel_t _fragInput; fixed4 uieffect_frag(pixel_t input, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
pixel_t input = _fragInput;
float2 uvMove = uv - input.texcoord0; float2 uvMove = uv - input.texcoord0;
float d = tex2D(_MainTex, input.texcoord0.xy + uvMove).a; float d = tex2D(_MainTex, input.texcoord0.xy + uvMove).a;
@@ -282,14 +280,14 @@ SubShader {
} }
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT pixel_t
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
fixed4 PixShader(pixel_t input) : SV_Target fixed4 PixShader(pixel_t input) : SV_Target
{ {
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input; half4 faceColor = uieffect(input.texcoord0, input.uvMask, input.worldPosition, input);
half4 faceColor = uieffect(input.texcoord0, input.uvMask, input.worldPosition);
faceColor *= input.alpha; faceColor *= input.alpha;
// Alternative implementation to UnityGet2DClipping with support for softness // Alternative implementation to UnityGet2DClipping with support for softness
@@ -229,10 +229,8 @@ SubShader {
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
pixel_t _fragInput; fixed4 uieffect_frag(pixel_t input, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
pixel_t input = _fragInput;
float2 uvMove = uv - input.texcoord0.xy; float2 uvMove = uv - input.texcoord0.xy;
half d = tex2D(_MainTex, input.texcoord0.xy + uvMove).a * input.param.x; half d = tex2D(_MainTex, input.texcoord0.xy + uvMove).a * input.param.x;
half4 c = input.faceColor * saturate(d - input.param.w); half4 c = input.faceColor * saturate(d - input.param.w);
@@ -261,14 +259,14 @@ SubShader {
} }
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT pixel_t
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
fixed4 PixShader(pixel_t input) : SV_Target fixed4 PixShader(pixel_t input) : SV_Target
{ {
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input; half4 c = uieffect(input.texcoord0.xy, input.uvMask, input.worldPosition, input);
half4 c = uieffect(input.texcoord0.xy, input.uvMask, input.worldPosition);
c *= input.alpha; c *= input.alpha;
// Alternative implementation to UnityGet2DClipping with support for softness. // Alternative implementation to UnityGet2DClipping with support for softness.
@@ -272,10 +272,8 @@ SubShader {
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
pixel_t _fragInput; fixed4 uieffect_frag(pixel_t input, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
pixel_t input = _fragInput;
float2 uvMove = uv - input.atlas; float2 uvMove = uv - input.atlas;
float c = tex2D(_MainTex, input.atlas + uvMove).a; float c = tex2D(_MainTex, input.atlas + uvMove).a;
@@ -339,14 +337,14 @@ SubShader {
} }
#define UIEFFECT_TEXTMESHPRO 1 #define UIEFFECT_TEXTMESHPRO 1
#define UIEFFECT_FRAG_STRUCT pixel_t
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
fixed4 PixShader(pixel_t input) : SV_Target fixed4 PixShader(pixel_t input) : SV_Target
{ {
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
_fragInput = input; half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition, input);
half4 faceColor = uieffect(input.atlas, input.uvMask, input.worldPosition);
faceColor *= input.color.a; faceColor *= input.color.a;
#if UNITY_UI_CLIP_RECT #if UNITY_UI_CLIP_RECT
+29 -24
View File
@@ -81,6 +81,11 @@ uniform const matrix _CanvasToWorldMatrix;
#endif #endif
#endif #endif
#ifndef UIEFFECT_FRAG_STRUCT
struct uieffect_v2f{};
#define UIEFFECT_FRAG_STRUCT uieffect_v2f
#endif
#define TONE_NONE (!TONE_GRAYSCALE && !TONE_SEPIA && !TONE_NEGATIVE && !TONE_RETRO && !TONE_POSTERIZE) #define TONE_NONE (!TONE_GRAYSCALE && !TONE_SEPIA && !TONE_NEGATIVE && !TONE_RETRO && !TONE_POSTERIZE)
#define SAMPLING_NONE (!SAMPLING_BLUR_FAST && !SAMPLING_BLUR_MEDIUM && !SAMPLING_BLUR_DETAIL && !SAMPLING_PIXELATION && !SAMPLING_RGB_SHIFT && !SAMPLING_EDGE_LUMINANCE && !SAMPLING_EDGE_ALPHA) #define SAMPLING_NONE (!SAMPLING_BLUR_FAST && !SAMPLING_BLUR_MEDIUM && !SAMPLING_BLUR_DETAIL && !SAMPLING_PIXELATION && !SAMPLING_RGB_SHIFT && !SAMPLING_EDGE_LUMINANCE && !SAMPLING_EDGE_ALPHA)
#define TRANSITION_NONE (!TRANSITION_FADE && !TRANSITION_CUTOFF && !TRANSITION_DISSOLVE && !TRANSITION_SHINY && !TRANSITION_MASK && !TRANSITION_MELT && !TRANSITION_BURN && !TRANSITION_PATTERN && !TRANSITION_BLAZE) #define TRANSITION_NONE (!TRANSITION_FADE && !TRANSITION_CUTOFF && !TRANSITION_DISSOLVE && !TRANSITION_SHINY && !TRANSITION_MASK && !TRANSITION_MELT && !TRANSITION_BURN && !TRANSITION_PATTERN && !TRANSITION_BLAZE)
@@ -94,8 +99,8 @@ uniform const matrix _CanvasToWorldMatrix;
#endif #endif
#define UIEFFECT_UV_MASK(uv, uvMask) step(uvMask.x, uv.x) * step(uv.x, uvMask.z) * step(uvMask.y, uv.y) * step(uv.y, uvMask.w) #define UIEFFECT_UV_MASK(uv, uvMask) step(uvMask.x, uv.x) * step(uv.x, uvMask.z) * step(uvMask.y, uv.y) * step(uv.y, uvMask.w)
#define UIEFFECT_SAMPLE(uv) uieffect_frag(uv) #define UIEFFECT_SAMPLE(in, uv) uieffect_frag(in, uv)
#define UIEFFECT_SAMPLE_CLAMP(uv, uvMask) uieffect_frag(uv) * UIEFFECT_UV_MASK(uv, uvMask) #define UIEFFECT_SAMPLE_CLAMP(in, uv, uvMask) uieffect_frag(in, uv) * UIEFFECT_UV_MASK(uv, uvMask)
#ifdef CANVAS_SHADERGRAPH #ifdef CANVAS_SHADERGRAPH
#define TEX_SAMPLE_CLAMP(uv, uvMask) SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv) * UIEFFECT_UV_MASK(uv, uvMask) #define TEX_SAMPLE_CLAMP(uv, uvMask) SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv) * UIEFFECT_UV_MASK(uv, uvMask)
@@ -273,7 +278,7 @@ half4 apply_color_filter(int mode, half4 inColor, half4 factor, float intensity,
return color; return color;
} }
half4 apply_sampling_filter(float2 uv, const float4 uvMask, const float isShadow) half4 apply_sampling_filter(UIEFFECT_FRAG_STRUCT IN, float2 uv, const float4 uvMask, const float isShadow)
{ {
#if SAMPLING_BLUR_FAST || SAMPLING_BLUR_MEDIUM || SAMPLING_BLUR_DETAIL #if SAMPLING_BLUR_FAST || SAMPLING_BLUR_MEDIUM || SAMPLING_BLUR_DETAIL
{ {
@@ -305,7 +310,7 @@ half4 apply_sampling_filter(float2 uv, const float4 uvMask, const float isShadow
const float weight = KERNEL_[x] * KERNEL_[y] const float weight = KERNEL_[x] * KERNEL_[y]
* step(uvMask.x, bluredUv.x) * step(bluredUv.x, uvMask.z) * step(uvMask.x, bluredUv.x) * step(bluredUv.x, uvMask.z)
* step(uvMask.y, bluredUv.y) * step(bluredUv.y, uvMask.w); * step(uvMask.y, bluredUv.y) * step(bluredUv.y, uvMask.w);
o += UIEFFECT_SAMPLE(bluredUv) * weight; o += UIEFFECT_SAMPLE(IN, bluredUv) * weight;
sum += weight; sum += weight;
} }
} }
@@ -315,7 +320,7 @@ half4 apply_sampling_filter(float2 uv, const float4 uvMask, const float isShadow
} }
#endif #endif
return UIEFFECT_SAMPLE_CLAMP(uv, uvMask); return UIEFFECT_SAMPLE_CLAMP(IN, uv, uvMask);
} }
float2 move_transition_filter(const float4 uvMask, const float alpha) float2 move_transition_filter(const float4 uvMask, const float alpha)
@@ -552,12 +557,12 @@ float is_edge_shiny(const float2 uvLocal)
#endif #endif
} }
half4 uieffect_internal(float2 uv, float4 uvMask, const float2 uvLocal, const float2 uvGrad, const float isShadow) half4 uieffect_internal(UIEFFECT_FRAG_STRUCT IN, float2 uv, float4 uvMask, const float2 uvLocal, const float2 uvGrad, const float isShadow)
{ {
const half alpha = transition_alpha(uvLocal); const half alpha = transition_alpha(uvLocal);
const float edgeFactor = edge(uv, uvMask, _EdgeWidth); const float edgeFactor = edge(uv, uvMask, _EdgeWidth);
uv += move_transition_filter(uvMask, alpha); uv += move_transition_filter(uvMask, alpha);
half4 color = apply_sampling_filter(uv, uvMask, isShadow); half4 color = apply_sampling_filter(IN, uv, uvMask, isShadow);
color = apply_gradation_filter(color, uvGrad); color = apply_gradation_filter(color, uvGrad);
color = apply_tone_filter(color); color = apply_tone_filter(color);
color = apply_transition_filter(color, alpha, uvLocal, edgeFactor); color = apply_transition_filter(color, alpha, uvLocal, edgeFactor);
@@ -584,7 +589,7 @@ half4 uieffect_internal(float2 uv, float4 uvMask, const float2 uvLocal, const fl
} }
} }
half4 uieffect(half4 origin, float2 uv, float4 uvMask, float4 wpos) half4 uieffect(half4 origin, float2 uv, float4 uvMask, float4 wpos, UIEFFECT_FRAG_STRUCT IN)
{ {
#ifdef NO_UIEFFECT #ifdef NO_UIEFFECT
return origin; return origin;
@@ -622,9 +627,9 @@ half4 uieffect(half4 origin, float2 uv, float4 uvMask, float4 wpos)
#elif SAMPLING_RGB_SHIFT #elif SAMPLING_RGB_SHIFT
{ {
const half2 offset = half2(_SamplingIntensity * texel_size().x * 20, 0); const half2 offset = half2(_SamplingIntensity * texel_size().x * 20, 0);
const half2 r = uieffect_internal(uv + offset, uvMask, uvLocal, uvGrad, isShadow).ra; const half2 r = uieffect_internal(IN, uv + offset, uvMask, uvLocal, uvGrad, isShadow).ra;
const half2 g = uieffect_internal(uv, uvMask, uvLocal, uvGrad, isShadow).ga; const half2 g = uieffect_internal(IN, uv, uvMask, uvLocal, uvGrad, isShadow).ga;
const half2 b = uieffect_internal(uv - offset, uvMask, uvLocal, uvGrad, isShadow).ba; const half2 b = uieffect_internal(IN, uv - offset, uvMask, uvLocal, uvGrad, isShadow).ba;
return half4(r.x * r.y, g.x * g.y, b.x * b.y, (r.y + g.y + b.y) / 3); return half4(r.x * r.y, g.x * g.y, b.x * b.y, (r.y + g.y + b.y) / 3);
} }
// Sampling.EdgeLuminance/EdgeAlpha // Sampling.EdgeLuminance/EdgeAlpha
@@ -634,32 +639,32 @@ half4 uieffect(half4 origin, float2 uv, float4 uvMask, float4 wpos)
const float2 d = texel_size() * _SamplingWidth; const float2 d = texel_size() * _SamplingWidth;
// Pixel values around the current pixel (3x3, 8 neighbors) // Pixel values around the current pixel (3x3, 8 neighbors)
const half v00 = to_value(UIEFFECT_SAMPLE_CLAMP((uv + half2(-d.x, -d.y)), uvMask)); const half v00 = to_value(UIEFFECT_SAMPLE_CLAMP(IN, (uv + half2(-d.x, -d.y)), uvMask));
const half v01 = to_value(UIEFFECT_SAMPLE_CLAMP((uv + half2(-d.x, 0.0)), uvMask)); const half v01 = to_value(UIEFFECT_SAMPLE_CLAMP(IN, (uv + half2(-d.x, 0.0)), uvMask));
const half v02 = to_value(UIEFFECT_SAMPLE_CLAMP((uv + half2(-d.x, +d.y)), uvMask)); const half v02 = to_value(UIEFFECT_SAMPLE_CLAMP(IN, (uv + half2(-d.x, +d.y)), uvMask));
const half v10 = to_value(UIEFFECT_SAMPLE_CLAMP((uv + half2(0.0, -d.y)), uvMask)); const half v10 = to_value(UIEFFECT_SAMPLE_CLAMP(IN, (uv + half2(0.0, -d.y)), uvMask));
const half v12 = to_value(UIEFFECT_SAMPLE_CLAMP((uv + half2(0.0, +d.y)), uvMask)); const half v12 = to_value(UIEFFECT_SAMPLE_CLAMP(IN, (uv + half2(0.0, +d.y)), uvMask));
const half v20 = to_value(UIEFFECT_SAMPLE_CLAMP((uv + half2(+d.x, -d.y)), uvMask)); const half v20 = to_value(UIEFFECT_SAMPLE_CLAMP(IN, (uv + half2(+d.x, -d.y)), uvMask));
const half v21 = to_value(UIEFFECT_SAMPLE_CLAMP((uv + half2(+d.x, 0.0)), uvMask)); const half v21 = to_value(UIEFFECT_SAMPLE_CLAMP(IN, (uv + half2(+d.x, 0.0)), uvMask));
const half v22 = to_value(UIEFFECT_SAMPLE_CLAMP((uv + half2(+d.x, +d.y)), uvMask)); const half v22 = to_value(UIEFFECT_SAMPLE_CLAMP(IN, (uv + half2(+d.x, +d.y)), uvMask));
// Apply Sobel operator // Apply Sobel operator
half sobel_h = v00 * -1.0 + v01 * -2.0 + v02 * -1.0 + v20 * 1.0 + v21 * 2.0 + v22 * 1.0; half sobel_h = v00 * -1.0 + v01 * -2.0 + v02 * -1.0 + v20 * 1.0 + v21 * 2.0 + v22 * 1.0;
half sobel_v = v00 * -1.0 + v10 * -2.0 + v20 * -1.0 + v02 * 1.0 + v12 * 2.0 + v22 * 1.0; half sobel_v = v00 * -1.0 + v10 * -2.0 + v20 * -1.0 + v02 * 1.0 + v12 * 2.0 + v22 * 1.0;
const half sobel = sqrt(sobel_h * sobel_h + sobel_v * sobel_v) * _SamplingIntensity; const half sobel = sqrt(sobel_h * sobel_h + sobel_v * sobel_v) * _SamplingIntensity;
return lerp(half4(0, 0, 0, 0), uieffect_internal(uv, uvMask, uvLocal, uvGrad, isShadow), inv_lerp(0.5, 1, sobel)); return lerp(half4(0, 0, 0, 0), uieffect_internal(IN, uv, uvMask, uvLocal, uvGrad, isShadow), inv_lerp(0.5, 1, sobel));
} }
#endif #endif
return lerp(origin, uieffect_internal(uv, uvMask, uvLocal, uvGrad, isShadow), rate); return lerp(origin, uieffect_internal(IN, uv, uvMask, uvLocal, uvGrad, isShadow), rate);
} }
half4 uieffect(float2 uv, float4 uvMask, float4 wpos) half4 uieffect(float2 uv, float4 uvMask, float4 wpos, UIEFFECT_FRAG_STRUCT IN)
{ {
const half4 origin = UIEFFECT_SAMPLE_CLAMP(uv, uvMask); const half4 origin = UIEFFECT_SAMPLE_CLAMP(IN, uv, uvMask);
return uieffect(origin, uv, uvMask, wpos); return uieffect(origin, uv, uvMask, wpos, IN);
} }
#endif // UI_EFFECT_INCLUDED #endif // UI_EFFECT_INCLUDED
+3 -5
View File
@@ -147,16 +147,15 @@ Shader "Hidden/UI/Default (UIEffect)"
} }
// ==== UIEFFECT START ==== // ==== UIEFFECT START ====
v2f _fragInput; fixed4 uieffect_frag(v2f IN, float2 uv)
fixed4 uieffect_frag(float2 uv)
{ {
v2f IN = _fragInput;
half4 color = (tex2D(_MainTex, uv) + _TextureSampleAdd); half4 color = (tex2D(_MainTex, uv) + _TextureSampleAdd);
color.rgb *= IN.color.rgb; color.rgb *= IN.color.rgb;
color.rgb *= color.a; color.rgb *= color.a;
return color; return color;
} }
#define UIEFFECT_FRAG_STRUCT v2f
#include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc" #include "Packages/com.coffee.ui-effect/Shaders/UIEffect.cginc"
// ==== UIEFFECT END ==== // ==== UIEFFECT END ====
@@ -169,8 +168,7 @@ Shader "Hidden/UI/Default (UIEffect)"
const half invAlphaPrecision = half(1.0 / alphaPrecision); const half invAlphaPrecision = half(1.0 / alphaPrecision);
IN.color.a = round(IN.color.a * alphaPrecision) * invAlphaPrecision; IN.color.a = round(IN.color.a * alphaPrecision) * invAlphaPrecision;
_fragInput = IN; half4 c = uieffect(IN.texcoord, IN.uvMask, IN.worldPosition, IN);
half4 c = uieffect(IN.texcoord, IN.uvMask, IN.worldPosition);
c *= IN.color.a; c *= IN.color.a;
#ifdef UNITY_UI_CLIP_RECT #ifdef UNITY_UI_CLIP_RECT