From 7db6220c30ca787dc59434679fa5828c4570be24 Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Fri, 15 Nov 2024 09:49:15 +0800 Subject: [PATCH] =?UTF-8?q?XMB=20shader=E7=8E=B0=E5=9C=A8=E6=98=AF?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=AE=8C=E5=A4=87=E7=9A=84ugui=20shader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Scene/AxibugEmuOnline.Client.unity | 20 ++++++++-- .../Assets/Script/UI/XMBBackGround.shader | 31 +++++++++++----- .../Script/UI/XMBBackGroundPreview.shader | 37 ++++++++++++++----- 3 files changed, 65 insertions(+), 23 deletions(-) diff --git a/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity b/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity index fc467af..33fd3b1 100644 --- a/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity +++ b/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity @@ -2499,7 +2499,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1639091784002085428, guid: 450328d5a907c8249a60bc3980ba66f6, type: 3} propertyPath: m_RootOrder - value: 0 + value: 1 objectReference: {fileID: 0} - target: {fileID: 1639091784002085428, guid: 450328d5a907c8249a60bc3980ba66f6, type: 3} propertyPath: m_AnchorMax.x @@ -13645,7 +13645,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} propertyPath: m_RootOrder - value: 2 + value: 3 objectReference: {fileID: 0} - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} propertyPath: m_AnchorMax.x @@ -13723,6 +13723,10 @@ PrefabInstance: propertyPath: m_Name value: InGameUI objectReference: {fileID: 0} + - target: {fileID: 1963501579241001457, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} --- !u!1001 &3531919738450164441 @@ -13736,6 +13740,10 @@ PrefabInstance: propertyPath: m_Name value: Overlay objectReference: {fileID: 0} + - target: {fileID: 3531919739338806916, guid: 1de15a80c8c1aa94486563740a15d91c, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 3531919739338806919, guid: 1de15a80c8c1aa94486563740a15d91c, type: 3} propertyPath: m_Pivot.x value: 0.5 @@ -13746,7 +13754,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 3531919739338806919, guid: 1de15a80c8c1aa94486563740a15d91c, type: 3} propertyPath: m_RootOrder - value: 3 + value: 4 objectReference: {fileID: 0} - target: {fileID: 3531919739338806919, guid: 1de15a80c8c1aa94486563740a15d91c, type: 3} propertyPath: m_AnchorMax.x @@ -13885,6 +13893,10 @@ PrefabInstance: propertyPath: m_Name value: OptionUI objectReference: {fileID: 0} + - target: {fileID: 4478785627166277609, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 4478785627166277610, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3} propertyPath: m_Pivot.x value: 0.5 @@ -13895,7 +13907,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4478785627166277610, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3} propertyPath: m_RootOrder - value: 1 + value: 2 objectReference: {fileID: 0} - target: {fileID: 4478785627166277610, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3} propertyPath: m_AnchorMax.x diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/XMBBackGround.shader b/AxibugEmuOnline.Client/Assets/Script/UI/XMBBackGround.shader index 66a9f36..cf9a146 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/XMBBackGround.shader +++ b/AxibugEmuOnline.Client/Assets/Script/UI/XMBBackGround.shader @@ -2,7 +2,9 @@ { Properties { - _MainTex ("Sprite Texture", 2D) = "white" {} + [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 @@ -11,7 +13,6 @@ _ColorMask ("Color Mask", Float) = 15 - [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0 [Space(10)] @@ -88,6 +89,7 @@ fixed4 color : COLOR; float2 texcoord : TEXCOORD0; float4 worldPosition : TEXCOORD1; + float4 mask : TEXCOORD2; UNITY_VERTEX_OUTPUT_STEREO }; @@ -95,6 +97,9 @@ fixed4 _TextureSampleAdd; float4 _ClipRect; sampler2D _MainTex; + float4 _MainTex_ST; + float _UIMaskSoftnessX; + float _UIMaskSoftnessY; float wave(float x, float frequency, float speed, float midHeight, float maxHeight) { @@ -116,10 +121,17 @@ v2f OUT; UNITY_SETUP_INSTANCE_ID(v); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT); + float4 vPosition = UnityObjectToClipPos(v.vertex); OUT.worldPosition = v.vertex; - OUT.vertex = UnityObjectToClipPos(OUT.worldPosition); + OUT.vertex = vPosition; - OUT.texcoord =v.texcoord; + 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))); OUT.color = v.color * _Color; return OUT; @@ -142,8 +154,8 @@ fixed4 frag(v2f IN) : SV_Target { - float2 uv= IN.texcoord; - // Lerped background + float2 uv= IN.texcoord; + // Lerped background float amount = (uv.x + uv.y) / 2.0; float3 bg = lerp(_Color2, _Color1, amount); @@ -164,7 +176,7 @@ float waveHeight2 = wave(uv.x, frequency2, speed2, midHeight2, maxHeight2); float waveCol2 = waveColor(uv, waveHeight2, maxHeight2, frequency2, power2); - float3 col = bg; + float3 col = bg; float3 waveCol1_temp=col/waveCol1; col = lerp(col,waveCol1_temp, step(uv.y, waveHeight1)); @@ -173,10 +185,11 @@ col = lerp(col,waveCol2_temp, step(uv.y, waveHeight2)); // Output to screen - fixed4 fragColor = float4(col,1.0); + fixed4 fragColor = float4(col,1.0)*IN.color; #ifdef UNITY_UI_CLIP_RECT - fragColor.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect); + half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(IN.mask.xy)) * IN.mask.zw); + fragColor.a *= m.x * m.y; #endif #ifdef UNITY_UI_ALPHACLIP diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/XMBBackGroundPreview.shader b/AxibugEmuOnline.Client/Assets/Script/UI/XMBBackGroundPreview.shader index 4ba64dd..5bd7a18 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/XMBBackGroundPreview.shader +++ b/AxibugEmuOnline.Client/Assets/Script/UI/XMBBackGroundPreview.shader @@ -2,7 +2,9 @@ { Properties { - _MainTex ("Sprite Texture", 2D) = "white" {} + [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 @@ -11,7 +13,6 @@ _ColorMask ("Color Mask", Float) = 15 - [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0 [Space(10)] @@ -88,6 +89,7 @@ fixed4 color : COLOR; float2 texcoord : TEXCOORD0; float4 worldPosition : TEXCOORD1; + float4 mask : TEXCOORD2; UNITY_VERTEX_OUTPUT_STEREO }; @@ -95,6 +97,9 @@ fixed4 _TextureSampleAdd; float4 _ClipRect; sampler2D _MainTex; + float4 _MainTex_ST; + float _UIMaskSoftnessX; + float _UIMaskSoftnessY; float wave(float x, float frequency, float speed, float midHeight, float maxHeight) { @@ -116,10 +121,17 @@ v2f OUT; UNITY_SETUP_INSTANCE_ID(v); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT); + float4 vPosition = UnityObjectToClipPos(v.vertex); OUT.worldPosition = v.vertex; - OUT.vertex = UnityObjectToClipPos(OUT.worldPosition); + OUT.vertex = vPosition; - OUT.texcoord =v.texcoord; + 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))); OUT.color = v.color * _Color; return OUT; @@ -142,8 +154,8 @@ fixed4 frag(v2f IN) : SV_Target { - float2 uv= IN.texcoord; - // Lerped background + float2 uv= IN.texcoord; + // Lerped background float amount = (uv.x + uv.y) / 2.0; float3 bg = lerp(_Color2, _Color1, amount); @@ -165,14 +177,19 @@ float waveCol2 = waveColor(uv, waveHeight2, maxHeight2, frequency2, power2); float3 col = bg; - col = lerp(col, col/waveCol1, step(uv.y, waveHeight1)); - col = lerp(col, col/waveCol2, step(uv.y, waveHeight2)); + + float3 waveCol1_temp=col/waveCol1; + col = lerp(col,waveCol1_temp, step(uv.y, waveHeight1)); + + float3 waveCol2_temp=col/waveCol2; + col = lerp(col,waveCol2_temp, step(uv.y, waveHeight2)); // Output to screen - fixed4 fragColor = float4(col,1.0); + fixed4 fragColor = float4(col,1.0)*IN.color; #ifdef UNITY_UI_CLIP_RECT - fragColor.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect); + half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(IN.mask.xy)) * IN.mask.zw); + fragColor.a *= m.x * m.y; #endif #ifdef UNITY_UI_ALPHACLIP