Before 优化 机场

This commit is contained in:
CortexCore
2025-03-10 18:06:44 +08:00
parent 350e6d67b2
commit 1f4e20f512
178 changed files with 17534 additions and 821 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2bda2a26e9068334093b9ae177d4f386
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,201 @@
// This shader uses some optimized gaussian sampling for better quality with decent performance.
// _BlurOffset property is ignored in this shader. It exists only to maintain a consistent API.
// See: https://www.rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/
Shader "Kamgam/UI Toolkit/BuiltIn/Blur Shader"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_BlurOffset("Blur Offset", Vector) = (1.0, 1.0, 0)
[KeywordEnum(Low, Medium, High)] _Samples("Sample Amount", Float) = 1
_AdditiveColor("Additive Color", Color) = (0, 0, 0, 0)
[MaterialToggle] _FlipVertical("flipVertical", Float) = 1
}
CGINCLUDE
#if _SAMPLES_LOW
#define SAMPLES 10
#elif _SAMPLES_MEDIUM
#define SAMPLES 30
#else
#define SAMPLES 100
#endif
#pragma multi_compile _SAMPLES_LOW _SAMPLES_MEDIUM _SAMPLES_HIGH
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_TexelSize;
float4 _MainTex_ST;
float4 _AdditiveColor;
float2 _BlurOffset;
float _FlipVertical;
// Based on linear sampling on the GPU.
// Weights from this excellent article:
// https://www.rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/
static const float offset[3] = { 0.0, 1.3846153846, 3.2307692308 };
static const float weight[3] = { 0.2270270270, 0.3162162162, 0.0702702703 };
float4 vert(float2 uv : TEXCOORD0) : SV_POSITION
{
float4 pos;
pos.xy = uv;
// This example is rendering with upside-down flipped projection,
// so flip the vertical UV coordinate too
if (_ProjectionParams.x < 0)
pos.y = 1 - pos.y;
pos.z = 0;
pos.w = 1;
return pos;
}
v2f Vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 BlurHorizontal(v2f input) : SV_Target
{
// See: https://forum.unity.com/threads/_maintex_texelsize-whats-the-meaning.110278/
// For a 1024 x 1024 texture this will be 1 / 1024.
float2 uv2px = _MainTex_TexelSize.xy;
// star form, blur with a sample for every step
half4 color;
int sampleDiv = SAMPLES - 1;
float weightSum = 0;
for (float i = 0; i < SAMPLES; i++)
{
// Linear kernel weight interpolation
float weight = 0.5 + (0.5 - abs(i / sampleDiv - 0.5));
weightSum += weight;
// x
float2 uv = input.uv + float2((i / sampleDiv - 0.5) * _BlurOffset.x, 0.0) * uv2px;
color += tex2D(_MainTex, uv) * weight;
}
color /= weightSum;
color.a = 1;
return color;
}
fixed4 BlurVertical(v2f input) : SV_Target
{
// See: https://forum.unity.com/threads/_maintex_texelsize-whats-the-meaning.110278/
// For a 1024 x 1024 texture this will be 1 / 1024.
float2 uv2px = _MainTex_TexelSize.xy;
// star form, blur with a sample for every step
half4 color;
int sampleDiv = SAMPLES - 1;
float weightSum = 0;
for (float i = 0; i < SAMPLES; i++)
{
// Linear kernel weight interpolation
float weight = 0.5 + (0.5 - abs(i / sampleDiv - 0.5));
weightSum += weight;
// y
float2 uv = input.uv + float2(0.0, (i / sampleDiv - 0.5) * _BlurOffset.y) * uv2px;
// Flip UVs if necessary, see
// https://docs.unity3d.com/Manual/SL-PlatformDifferences.html
// https://forum.unity.com/threads/how-does-unity-handle-the-uv-coordinate-inconsistency-across-different-api.979794/#post-6366516
// https://forum.unity.com/threads/command-buffer-blit-render-texture-result-is-upside-down.1463063/
if (_FlipVertical && _ProjectionParams.x < 0)
{
uv.y = 1 - uv.y;
}
color += tex2D(_MainTex, uv) * weight;
}
color /= weightSum;
color.a = tex2D(_MainTex, input.uv).a;
color += _AdditiveColor;
return color;
}
ENDCG
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
ZWrite Off
ZTest Always
Blend Off
Cull Off
Pass
{
Name "Blur Horizontal"
CGPROGRAM
v2f vert(appdata v)
{
return Vert(v);
}
fixed4 frag(v2f input) : SV_Target
{
return BlurHorizontal(input);
}
ENDCG
}
Pass
{
Name "Blur Vertical"
CGPROGRAM
v2f vert(appdata v)
{
return Vert(v);
}
fixed4 frag(v2f input) : SV_Target
{
return BlurVertical(input);
}
ENDCG
}
}
}

View File

@@ -0,0 +1,17 @@
fileFormatVersion: 2
guid: 02c585ad185879e4cb48d6e2683f5448
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 254328
packageName: UI Toolkit Blurred Background - Fast translucent background image
packageVersion: 1.0.4
assetPath: Assets/Kamgam/UIToolkitBlurredBackground/Runtime/Shaders/BuiltIn/UITKBlurShader.shader
uploadId: 644498

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7f097bcc1d3713849b7927fa6b5fa498
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,241 @@
Shader "Kamgam/UI Toolkit/URP/Blur Shader"
{
Properties
{
// MainTex is only used in ShaderGraph < 15
_MainTex("Texture", 2D) = "white" {}
_BlurOffset("Blur Offset", Vector) = (1.0, 1.0, 0)
[KeywordEnum(Low, Medium, High)] _Samples("Sample Amount", Float) = 1
}
HLSLINCLUDE
#if _SAMPLES_LOW
#define SAMPLES 10
#elif _SAMPLES_MEDIUM
#define SAMPLES 30
#else
#define SAMPLES 100
#endif
// TODO: Actually the only difference is the default source name _MainTex > _BlitTexture, so we could just extract that and use it in both.
#if UNITY_VERSION >= 202220
// Version compare, see: https://forum.unity.com/threads/urp-version-defines.1218915/#post-9021178
// Shader Graph >= 14.x
// Based on the default Hidden/Universal Render Pipleline/Blit shader found under
// packages/com.unity.render-pipelines.universal@x.y.z/Shaders/Utils/Blit.shader
#pragma multi_compile_fragment _ _LINEAR_TO_SRGB_CONVERSION
#pragma multi_compile _SAMPLES_LOW _SAMPLES_MEDIUM _SAMPLES_HIGH
// Core.hlsl for XR dependencies
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
SAMPLER(sampler_BlitTexture);
#if UNITY_VERSION <= 202320
float4 _BlitTexture_TexelSize;
#endif
float4 _BlurOffset;
half4 BlurHorizontal(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.texcoord;
// See: https://forum.unity.com/threads/_maintex_texelsize-whats-the-meaning.110278/
// For a 1024 x 1024 texture this will be 1 / 1024.
float2 uv2px = _BlitTexture_TexelSize.xy;
// star form, blur with a sample for every step
half4 color;
int sampleDiv = SAMPLES - 1;
float weightSum = 0;
for (float i = 0; i < SAMPLES; i++)
{
// Linear kernel weight interpolation
float weight = 0.5 + (0.5 - abs(i / sampleDiv - 0.5));
weightSum += weight;
// x
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_BlitTexture, uv + float2((i / sampleDiv - 0.5) * _BlurOffset.x, 0.0) * uv2px) * weight;
}
color /= weightSum;
color.a = 1;
#ifdef _LINEAR_TO_SRGB_CONVERSION
color = LinearToSRGB(color);
#endif
return color;
}
half4 BlurVertical(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.texcoord;
// See: https://forum.unity.com/threads/_maintex_texelsize-whats-the-meaning.110278/
// For a 1024 x 1024 texture this will be 1 / 1024.
float2 uv2px = _BlitTexture_TexelSize.xy;
// star form, blur with a sample for every step
half4 color;
int sampleDiv = SAMPLES - 1;
float weightSum = 0;
for (float i = 0; i < SAMPLES; i++)
{
// Linear kernel weight interpolation
float weight = 0.5 + (0.5 - abs(i / sampleDiv - 0.5));
weightSum += weight;
// y
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_BlitTexture, uv + float2(0.0, (i / sampleDiv - 0.5) * _BlurOffset.y) * uv2px) * weight;
}
color /= weightSum;
color.a = 1;
#ifdef _LINEAR_TO_SRGB_CONVERSION
color = LinearToSRGB(color);
#endif
return color;
}
#else
// Shader Graph < 15
// Based on the default Hidden/Universal Render Pipleline/Blit shader found under
// packages/com.unity.render-pipelines.universal@x.y.z/Shaders/Utils/Blit.shader
#pragma multi_compile_fragment _ _LINEAR_TO_SRGB_CONVERSION
#pragma multi_compile _ _USE_DRAW_PROCEDURAL
#pragma multi_compile _SAMPLES_LOW _SAMPLES_MEDIUM _SAMPLES_HIGH
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/Fullscreen.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
TEXTURE2D_X(_MainTex);
SAMPLER(sampler_MainTex);
float4 _MainTex_TexelSize;
float4 _BlurOffset;
half4 BlurHorizontal(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.uv;
// See: https://forum.unity.com/threads/_maintex_texelsize-whats-the-meaning.110278/
// For a 1024 x 1024 texture this will be 1 / 1024.
float2 uv2px = _MainTex_TexelSize.xy;
// star form, blur with a sample for every step
half4 color;
int sampleDiv = SAMPLES - 1;
float weightSum = 0;
for (float i = 0; i < SAMPLES; i++)
{
// Linear kernel weight interpolation
float weight = 0.5 + (0.5 - abs(i / sampleDiv - 0.5));
weightSum += weight;
// x
color += SAMPLE_TEXTURE2D_X(_MainTex, sampler_MainTex, uv + float2((i / sampleDiv - 0.5) * _BlurOffset.x, 0.0) * uv2px) * weight;
}
color /= weightSum;
color.a = 1;
#ifdef _LINEAR_TO_SRGB_CONVERSION
color = LinearToSRGB(color);
#endif
return color;
}
half4 BlurVertical(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.uv;
// See: https://forum.unity.com/threads/_maintex_texelsize-whats-the-meaning.110278/
// For a 1024 x 1024 texture this will be 1 / 1024.
float2 uv2px = _MainTex_TexelSize.xy;
// star form, blur with a sample for every step
half4 color;
int sampleDiv = SAMPLES - 1;
float weightSum = 0;
for (float i = 0; i < SAMPLES; i++)
{
// Linear kernel weight interpolation
float weight = 0.5 + (0.5 - abs(i / sampleDiv - 0.5));
weightSum += weight;
// y
color += SAMPLE_TEXTURE2D_X(_MainTex, sampler_MainTex, uv + float2(0.0, (i / sampleDiv - 0.5) * _BlurOffset.y) * uv2px) * weight;
}
color /= weightSum;
color.a = 1;
#ifdef _LINEAR_TO_SRGB_CONVERSION
color = LinearToSRGB(color);
#endif
return color;
}
#endif
ENDHLSL
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }
LOD 100
ZTest Always
ZWrite Off
Cull Off
Pass
{
Name "Blur Horizontal"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment BlurHorizontal
ENDHLSL
}
Pass
{
Name "Blur Vertical"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment BlurVertical
ENDHLSL
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 97c8e4e6da971644f8c6737a0516a6e9
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant: