优化ui,谱面替换,以及科研模糊
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
Shader "Qjjxk/BlurImage"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[PerRendererData] _MainTex ("Texture", 2D) = "white" {}
|
||||
_BlurRadius ("BlurRadius", Range(0, 32)) = 5
|
||||
_Iteration ("Iteration", Range(1, 6)) = 1
|
||||
_Region ("Region", Vector) = (0, 0, 1, 1)
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"RenderType" = "Opaque"
|
||||
"RenderPipeline" = "UniversalPipeline"
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
#pragma vertex VertC
|
||||
#pragma fragment Frag
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment FragH
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment FragV
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment FragGrainy
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment FragKawase
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
HLSLINCLUDE
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
#if UNITY_VERSION >= 202220
|
||||
TEXTURE2D(_BlitTexture);
|
||||
SAMPLER(sampler_BlitTexture);
|
||||
float4 _BlitTexture_TexelSize;
|
||||
#else
|
||||
TEXTURE2D(_MainTex);
|
||||
SAMPLER(sampler_MainTex);
|
||||
float4 _MainTex_TexelSize;
|
||||
#endif
|
||||
|
||||
float _BlurRadius;
|
||||
float _Iteration;
|
||||
float4 _Region;
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
uint vertexID : SV_VertexID;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
#if UNITY_VERSION >= 202220
|
||||
#define BLURPIXEL(n, m, weight) SAMPLE_TEXTURE2D(_BlitTexture, sampler_BlitTexture, float2(input.uv.x + _BlitTexture_TexelSize.x * n * _BlurRadius, input.uv.y + _BlitTexture_TexelSize.y * m * _BlurRadius)) * weight
|
||||
#define BLUROFFSET(offset) SAMPLE_TEXTURE2D(_BlitTexture, sampler_BlitTexture, input.uv + offset * _BlitTexture_TexelSize.xy);
|
||||
#else
|
||||
#define BLURPIXEL(n, m, weight) SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, float2(input.uv.x + _MainTex_TexelSize.x * n * _BlurRadius, input.uv.y + _MainTex_TexelSize.y * m * _BlurRadius)) * weight
|
||||
#define BLUROFFSET(offset) SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv + offset * _MainTex_TexelSize.xy);
|
||||
#endif
|
||||
|
||||
Varyings Vert(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
|
||||
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
|
||||
output.uv = GetFullScreenTriangleTexCoord(input.vertexID);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
Varyings VertC(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
|
||||
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
|
||||
float2 uv = GetFullScreenTriangleTexCoord(input.vertexID);
|
||||
output.uv = lerp(_Region.xy, _Region.zw, uv);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 Frag(Varyings input) : SV_Target
|
||||
{
|
||||
#if UNITY_VERSION >= 202220
|
||||
return SAMPLE_TEXTURE2D(_BlitTexture, sampler_BlitTexture, input.uv);
|
||||
#else
|
||||
return SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv);
|
||||
#endif
|
||||
}
|
||||
|
||||
half4 FragH(Varyings input) : SV_Target
|
||||
{
|
||||
half4 color = half4(0, 0, 0, 0);
|
||||
|
||||
color += BLURPIXEL(-4, 0, 0.05);
|
||||
color += BLURPIXEL(-3, 0, 0.09);
|
||||
color += BLURPIXEL(-2, 0, 0.12);
|
||||
color += BLURPIXEL(-1, 0, 0.15);
|
||||
color += BLURPIXEL(-0, 0, 0.18);
|
||||
color += BLURPIXEL(1, 0, 0.15);
|
||||
color += BLURPIXEL(2, 0, 0.12);
|
||||
color += BLURPIXEL(3, 0, 0.09);
|
||||
color += BLURPIXEL(4, 0, 0.05);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
half4 FragV(Varyings input) : SV_Target
|
||||
{
|
||||
half4 color = half4(0, 0, 0, 0);
|
||||
|
||||
color += BLURPIXEL(0, -4, 0.05);
|
||||
color += BLURPIXEL(0, -3, 0.09);
|
||||
color += BLURPIXEL(0, -2, 0.12);
|
||||
color += BLURPIXEL(0, -1, 0.15);
|
||||
color += BLURPIXEL(0, -0, 0.18);
|
||||
color += BLURPIXEL(0, 1, 0.15);
|
||||
color += BLURPIXEL(0, 2, 0.12);
|
||||
color += BLURPIXEL(0, 3, 0.09);
|
||||
color += BLURPIXEL(0, 4, 0.05);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
float Rand(float2 n)
|
||||
{
|
||||
return sin(dot(n, half2(1233.224, 1743.335)));
|
||||
}
|
||||
|
||||
half4 FragGrainy(Varyings input) : SV_Target
|
||||
{
|
||||
half4 color = half4(0, 0, 0, 0);
|
||||
|
||||
float2 offset = float2(0, 0);
|
||||
float random = Rand(input.uv);
|
||||
|
||||
int iteration = round(_Iteration);
|
||||
for (int k = 0; k < iteration; k++)
|
||||
{
|
||||
random = frac(43758.5453 * random + 0.61432);
|
||||
offset.x = (random - 0.5) * 2.0;
|
||||
random = frac(43758.5453 * random + 0.61432);
|
||||
offset.y = (random - 0.5) * 2.0;
|
||||
|
||||
color += BLUROFFSET(offset * _BlurRadius);
|
||||
}
|
||||
|
||||
return color / iteration;
|
||||
}
|
||||
|
||||
half4 FragKawase(Varyings input) : SV_Target
|
||||
{
|
||||
half4 color = half4(0, 0, 0, 0);
|
||||
|
||||
color += BLUROFFSET(float2(_BlurRadius, _BlurRadius));
|
||||
color += BLUROFFSET(float2(_BlurRadius, -_BlurRadius));
|
||||
color += BLUROFFSET(float2(-_BlurRadius, _BlurRadius));
|
||||
color += BLUROFFSET(float2(-_BlurRadius, -_BlurRadius));
|
||||
|
||||
return color * 0.25;
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8de1a8020b4db9439e5366887b9e43f
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 308958
|
||||
packageName: Blur RawImage UGUI
|
||||
packageVersion: 1.4
|
||||
assetPath: Assets/BlurRawImage/Shader/BlurImage.shader
|
||||
uploadId: 761342
|
||||
Reference in New Issue
Block a user