备份CatanBuilding瘦身独立工程
This commit is contained in:
74
LocalPackages/zzwater/shaders/FSBlur.shader
Normal file
74
LocalPackages/zzwater/shaders/FSBlur.shader
Normal file
@@ -0,0 +1,74 @@
|
||||
Shader "zzwater/FSBlur"
|
||||
{
|
||||
|
||||
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
_DepthThreshold ("Depth Threshold", Range(0, 200)) = 50
|
||||
//_BlurRadius ("Blur Radius", Range(1, 10)) = 3
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline"}
|
||||
LOD 100
|
||||
ZWrite Off Cull Off
|
||||
Pass
|
||||
{
|
||||
Name "FSBlur"
|
||||
|
||||
HLSLPROGRAM
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
// The Blit.hlsl file provides the vertex shader (Vert),
|
||||
// the input structure (Attributes) and the output structure (Varyings)
|
||||
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
|
||||
|
||||
#pragma vertex Vert
|
||||
#pragma fragment frag
|
||||
|
||||
|
||||
float _DepthThreshold;
|
||||
SAMPLER(sampler_BlitTexture);
|
||||
float4 _BlitTexture_TexelSize;
|
||||
|
||||
|
||||
half4 frag (Varyings input) : SV_Target
|
||||
{
|
||||
// Sample depth
|
||||
float deviceDepth = SampleSceneDepth(input.texcoord);
|
||||
float linearDepth = LinearEyeDepth(deviceDepth, _ZBufferParams);
|
||||
float _BlurRadius = 5;
|
||||
|
||||
// Original color
|
||||
half4 originalColor = SAMPLE_TEXTURE2D(_BlitTexture, sampler_BlitTexture, input.texcoord);
|
||||
|
||||
// If depth is less than threshold, return original color
|
||||
if (linearDepth < _DepthThreshold)
|
||||
return originalColor;
|
||||
|
||||
// Simple box blur (much faster than Gaussian)
|
||||
half4 blurredColor = half4(0, 0, 0, 0);
|
||||
int samples = 0;
|
||||
|
||||
// Use fixed radius for simplicity
|
||||
for (int x = -_BlurRadius; x <= _BlurRadius; x++)
|
||||
{
|
||||
for (int y = -_BlurRadius; y <= _BlurRadius; y++)
|
||||
{
|
||||
float2 offset = float2(x, y) * _BlitTexture_TexelSize;
|
||||
blurredColor += SAMPLE_TEXTURE2D(_BlitTexture, sampler_BlitTexture, input.texcoord + offset);
|
||||
samples++;
|
||||
}
|
||||
}
|
||||
|
||||
// Average the samples
|
||||
return blurredColor / samples;
|
||||
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user