后处理+FEEL完全改进

This commit is contained in:
SoulliesOfficial
2025-12-22 18:36:29 -05:00
parent c3914da4ac
commit a2052bfe16
1427 changed files with 193092 additions and 374110 deletions

View File

@@ -0,0 +1,122 @@
Shader "SLS/Postprocessing/AdvancedChromaticAberration"
{
SubShader
{
Tags
{
"RenderType" = "Opaque"
"RenderPipeline" = "UniversalPipeline"
}
ZWrite Off
Cull Off
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
// --- 参数定义 ---
float4 _ACA_Params1;
// x: Intensity (总强度)
// y: Center X
// z: Center Y
// w: Mask Radius (中心保留半径)
float4 _ACA_Params2;
// x: Jitter Intensity
// y: Jitter Speed
// z: Dispersion Map Strength (贴图影响力度)
// w: Mask Hardness (边缘硬度)
float4 _ACA_Split; // x: R权重, y: G权重, z: B权重
// 纹理
TEXTURE2D(_DispersionMap);
SAMPLER(sampler_DispersionMap); // 建议设置为 Repeat 模式
// --- 辅助函数 ---
// 简单的伪随机函数 (0-1)
float random(float2 uv)
{
return frac(sin(dot(uv, float2(12.9898, 78.233))) * 43758.5453123);
}
half4 Frag(Varyings input) : SV_Target
{
float2 uv = input.texcoord;
// 1. 参数解包
float intensity = _ACA_Params1.x;
float2 center = _ACA_Params1.yz;
float maskRadius = _ACA_Params1.w;
float jitterAmount = _ACA_Params2.x;
float jitterSpeed = _ACA_Params2.y;
float mapStrength = _ACA_Params2.z;
float maskHardness = _ACA_Params2.w;
float3 splitWeights = _ACA_Split.rgb;
// 2. 计算基础方向向量 (径向)
float2 dir = uv - center;
float dist = length(dir);
// 3. 计算中心遮罩 (Vignette Mask)
// 距离小于 Radius 的地方强度为 0向外渐变
float mask = smoothstep(maskRadius, maskRadius + maskHardness, dist);
// 如果在遮罩内,直接返回原图,节省性能
// (为了 Jitter 的连贯性,这里我们只把 mask 乘到 offset 上,不直接 return)
// 4. 计算 Jitter (采样抖动)
// 利用 Time 和 UV 做随机,模拟不稳定的信号
float timeVal = _Time.y * jitterSpeed;
// 这里的 floor 模拟“跳动”的帧率感,如果想要平滑 jitter 可以去掉 floor
float2 jitterUV = uv + float2(random(uv + timeVal), random(uv - timeVal)) * 0.1;
float2 jitterOffset = (float2(random(jitterUV), random(jitterUV * 1.5)) - 0.5) * 2.0; // -1 ~ 1
jitterOffset *= jitterAmount * 0.05; // 缩放幅度
// 5. 采样 Dispersion Map (破碎感)
// 让贴图随时间缓慢流动一点点,或者固定
float4 noiseTex = SAMPLE_TEXTURE2D(_DispersionMap, sampler_DispersionMap, uv * 3.0 + jitterOffset); // 缩放 UV
float noiseFactor = noiseTex.r * 2.0 - 1.0; // -1 ~ 1
// 混合 Map 影响
// 如果 mapStrength 为 0则 noiseFactor 为 0 (不影响),我们希望默认为 1
float finalNoise = lerp(1.0, noiseFactor, mapStrength);
// 6. 组合最终偏移量
// 基础方向 * (1 + 噪声) + 抖动
float2 finalOffset = dir * finalNoise;
// 加上纯粹的位置抖动 (不依赖方向)
finalOffset += jitterOffset;
// 应用遮罩和总强度
finalOffset *= mask * intensity;
// 7. 分离通道采样
// 注意URP 的 _BlitTexture 采样时最好 Clamp防止边缘溢出
float2 uvR = uv - finalOffset * splitWeights.r;
float2 uvG = uv - finalOffset * splitWeights.g;
float2 uvB = uv - finalOffset * splitWeights.b;
half r = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uvR).r;
half g = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uvG).g;
half b = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uvB).b;
// 8. 重新组合
return half4(r, g, b, 1.0);
}
ENDHLSL
Pass
{
Name "Advanced Chromatic Aberration"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
ENDHLSL
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: c195927c5e8d7b54482f7cc52dc314df
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,90 @@
Shader "SLS/Postprocessing/AdvancedVignette"
{
SubShader
{
Tags
{
"RenderType" = "Opaque"
"RenderPipeline" = "UniversalPipeline"
}
ZWrite Off
Cull Off
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
// --- 参数定义 ---
float4 _VignetteColors; // xy: Unused, z: Unused, w: Unused (颜色单独传)
float4 _ColorInner; // 内部颜色 (过渡色)
float4 _ColorOuter; // 外部颜色 (边缘色)
float3 _VignetteParams1;
// x: Intensity (强度)
// y: Smoothness (柔和度)
// z: Roundness (圆度)
float4 _VignetteCenter; // xy: Center
// 简单的伪随机噪声函数 (用于 Dithering)
float Random(float2 uv)
{
return frac(sin(dot(uv, float2(12.9898, 78.233))) * 43758.5453);
}
half4 Frag(Varyings input) : SV_Target
{
float2 uv = input.texcoord;
// 1. 参数解包
float intensity = _VignetteParams1.x;
float smoothness = max(0.001, _VignetteParams1.y);
float roundness = _VignetteParams1.z;
float2 center = _VignetteCenter.xy;
half3 colInner = _ColorInner.rgb;
half3 colOuter = _ColorOuter.rgb;
// 2. 计算距离场 (SDF)
float2 d = uv - center;
// 圆度计算
d = d * lerp(1.0, 0.5, roundness);
float vdist = length(d);
float boxDist = max(abs(d.x), abs(d.y));
vdist = lerp(boxDist, vdist, roundness);
// 3. 计算遮罩 (Mask)
// 归一化距离,使其适配 Intensity
float maxDist = 0.8;
float threshold = 1.0 - intensity;
// 计算平滑的 0-1 遮罩值
// mask = 0 (中心区域,显示原图) -> 1 (边缘区域,显示暗角)
float mask = smoothstep(threshold - smoothness * 0.5, threshold + smoothness * 0.5, vdist * 2.0);
// 5. 计算最终暗角颜色 (Gradient)
// 随着 mask 从 0 变到 1颜色从 Inner 变到 Outer
// 我们可以用 mask 本身作为插值系数,或者用 vdist
// 这里用 mask 保证颜色变化与透明度变化同步
half3 finalVignetteColor = lerp(colInner, colOuter, mask);
// 6. 混合原图
half4 sceneColor = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv);
// sceneColor * (1 - mask) + vignetteColor * mask
// 即Lerp(sceneColor, finalVignetteColor, mask)
return lerp(sceneColor, half4(finalVignetteColor, 1), mask);
}
ENDHLSL
Pass
{
Name "Advanced Vignette"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
ENDHLSL
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e9424f71b68fc594b82da3259df1d2c5
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,57 @@
Shader "SLS/Postprocessing/RGBSplitGlitch"
{
SubShader
{
Tags
{
"RenderType" = "Opaque"
"RenderPipeline" = "UniversalPipeline"
}
ZWrite Off
Cull Off
HLSLINCLUDE
// 1. 引入 Unity 核心库 (替代原本的 #include "PostProcessingPass.hlsl")
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
// 引入 Blit 库以获得 Vert 顶点函数和 _BlitTexture
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
// 2. 定义该效果专用的变量
float4 _RGBSplitGlitchParams;
#define _RGBSplitGlitchIntensity _RGBSplitGlitchParams.x
#define _TimeX _RGBSplitGlitchParams.y
// 3. 辅助函数 (仅在此 Shader 内部使用)
float randomNoise(float x, float y)
{
return frac(sin(dot(float2(x, y), float2(12.9898, 78.233))) * 43758.5453);
}
// 4. 片段着色器逻辑
float4 RGBSplitGlitchPassFragment(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float splitAmount = _RGBSplitGlitchIntensity * randomNoise(_TimeX, 2);
// 使用 _BlitTexture 采样当前画面
half4 colorR = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, input.texcoord);
half4 colorG = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp,
float2(input.texcoord.x + splitAmount, input.texcoord.y + splitAmount));
half4 colorB = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp,
float2(input.texcoord.x - splitAmount, input.texcoord.y - splitAmount));
return half4(colorR.r, colorG.g, colorB.b, 1);
}
ENDHLSL
Pass
{
Name "RGB Split Glitch"
HLSLPROGRAM
#pragma vertex Vert // 使用 Blit.hlsl 中的 Vert
#pragma fragment RGBSplitGlitchPassFragment
ENDHLSL
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6e8fe2c8a03163c419a4034561209dff
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,117 @@
Shader "SLS/Postprocessing/RadialBlur"
{
SubShader
{
Tags
{
"RenderType" = "Opaque"
"RenderPipeline" = "UniversalPipeline"
}
ZWrite Off
Cull Off
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
// 变量定义
float4 _RadialBlurParams;
#define _BlurRadius _RadialBlurParams.x
#define _RadialCenter _RadialBlurParams.yz
// --- 具体实现函数 ---
half4 RadialBlurPassFragment_4Tap(Varyings input): SV_Target
{
float2 uv = input.texcoord - _RadialCenter;
half scale = 1;
half4 color = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter);
scale = _BlurRadius + 1;
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter);
scale = 2 * _BlurRadius + 1;
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter);
scale = 3 * _BlurRadius + 1;
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter);
color *= 0.25f; // 1/4
return color;
}
half4 RadialBlurPassFragment_8Tap(Varyings input): SV_Target
{
float2 uv = input.texcoord - _RadialCenter;
half4 color = 0;
// 为了代码简洁,这里可以使用循环,但在 Shader 中手动展开(Unroll)通常性能更好或便于控制
// 这里保留你原本的展开逻辑
[unroll]
for(int i=0; i<8; i++)
{
half scale = i * _BlurRadius + 1;
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter);
}
return color * 0.125f;
}
half4 RadialBlurPassFragment_12Tap(Varyings input): SV_Target
{
float2 uv = input.texcoord - _RadialCenter;
half4 color = 0;
for(int i=0; i<12; i++) {
half scale = i * _BlurRadius + 1;
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter);
}
return color * 0.0833f;
}
half4 RadialBlurPassFragment_16Tap(Varyings input): SV_Target
{
float2 uv = input.texcoord - _RadialCenter;
half4 color = 0;
for(int i=0; i<16; i++) {
half scale = i * _BlurRadius + 1;
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter);
}
return color * 0.0625f;
}
ENDHLSL
Pass
{
Name "Radial Blur 4 Tap"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment RadialBlurPassFragment_4Tap
ENDHLSL
}
Pass
{
Name "Radial Blur 8 Tap"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment RadialBlurPassFragment_8Tap
ENDHLSL
}
Pass
{
Name "Radial Blur 12 Tap"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment RadialBlurPassFragment_12Tap
ENDHLSL
}
Pass
{
Name "Radial Blur 16 Tap"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment RadialBlurPassFragment_16Tap
ENDHLSL
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7528b766c67bf974e9d2eebb25b43c04
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
Shader "SLS/Postprocessing/Sharpen"
{
SubShader
{
Tags
{
"RenderType" = "Opaque"
"RenderPipeline" = "UniversalPipeline"
}
ZWrite Off
Cull Off
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
// 变量定义
float4 _SharpnessParams;
// x: Strength (锐化强度)
// y: Threshold (对比度阈值,用于降噪)
// z: Clamp (最大亮度变化限制,防光晕)
// w: Unused
half4 SharpenPassFragment(Varyings input) : SV_Target
{
half2 uv = input.texcoord;
// _BlitTexture_TexelSize 包含了纹理像素的大小 (1/width, 1/height)
float4 texelSize = _BlitTexture_TexelSize;
// 1. 5-Tap 采样 (中心 + 上下左右)
half4 center = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv);
half3 up = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + float2(0, texelSize.y)).rgb;
half3 down = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv - float2(0, texelSize.y)).rgb;
half3 left = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv - float2(texelSize.x, 0)).rgb;
half3 right = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + float2(texelSize.x, 0)).rgb;
// 2. 计算周围像素的平均值
half3 neighborsAvg = (up + down + left + right) * 0.25;
// 3. 计算差异 (边缘信号)
// 如果 center 比周围亮diff 为正;反之为负。
half3 diff = center.rgb - neighborsAvg;
// 参数解包
float strength = _SharpnessParams.x;
float threshold = _SharpnessParams.y;
float clampVal = _SharpnessParams.z;
// 4. 【优化一】对比度阈值 (Threshold) - 降噪用
// 计算差异的亮度值
float lumaDiff = dot(abs(diff), float3(0.2126, 0.7152, 0.0722));
// 如果差异小于阈值,则不进行锐化 (factor = 0)
// 使用 smoothstep 让过渡更平滑
float factor = smoothstep(threshold, threshold + 0.001, lumaDiff);
// 5. 应用锐化
half3 sharpened = center.rgb + diff * strength * factor;
// 6. 【优化二】钳制 (Clamp) - 防光晕用
// 限制锐化后的值与原始值的偏差不能超过 clampVal
sharpened = max(sharpened, center.rgb - clampVal); // 不能太暗
sharpened = min(sharpened, center.rgb + clampVal); // 不能太亮
return half4(sharpened, center.a);
}
ENDHLSL
Pass
{
Name "Sharpen Pass"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment SharpenPassFragment
ENDHLSL
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: ca578cdeed02a0e4185a591e727a1a6f
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,97 @@
Shader "SLS/Postprocessing/SpeedLines"
{
SubShader
{
Tags
{
"RenderType" = "Opaque"
"RenderPipeline" = "UniversalPipeline"
}
ZWrite Off
Cull Off
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
// 变量
float4 _Colour;
float _SpeedLinesTiling;
float _SpeedLinesRadialScale;
float _SpeedLinesPower;
float _SpeedLinesRemap;
float _SpeedLinesAnimation;
float _MaskScale;
float _MaskHardness;
float _MaskPower;
// --- 噪声算法库 (Simplex Noise) ---
float3 mod2D289( float3 x ) { return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0; }
float2 mod2D289( float2 x ) { return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0; }
float3 permute( float3 x ) { return mod2D289( ( ( x * 34.0 ) + 1.0 ) * x ); }
float snoise( float2 v )
{
const float4 C = float4( 0.211324865405187, 0.366025403784439, -0.577350269189626, 0.024390243902439 );
float2 i = floor( v + dot( v, C.yy ) );
float2 x0 = v - i + dot( i, C.xx );
float2 i1 = ( x0.x > x0.y ) ? float2( 1.0, 0.0 ) : float2( 0.0, 1.0 );
float4 x12 = x0.xyxy + C.xxzz; x12.xy -= i1;
i = mod2D289( i );
float3 p = permute( permute( i.y + float3( 0.0, i1.y, 1.0 ) ) + i.x + float3( 0.0, i1.x, 1.0 ) );
float3 m = max( 0.5 - float3( dot( x0, x0 ), dot( x12.xy, x12.xy ), dot( x12.zw, x12.zw ) ), 0.0 );
m = m * m; m = m * m;
float3 x = 2.0 * frac( p * C.www ) - 1.0; float3 h = abs( x ) - 0.5;
float3 ox = floor( x + 0.5 ); float3 a0 = x - ox;
m *= 1.79284291400159 - 0.85373472095314 * ( a0 * a0 + h * h );
float3 g;
g.x = a0.x * x0.x + h.x * x0.y; g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot( m, g );
}
// --- 主逻辑 ---
half4 SpeedLinesPassFragment(Varyings input) : SV_Target
{
half2 uv = input.texcoord;
half4 SceneColour7 = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv);
float2 CenteredUV15_g1 = ( uv - float2( 0.5,0.5 ) );
float2 break17_g1 = CenteredUV15_g1;
float2 appendResult23_g1 = (float2(( length( CenteredUV15_g1 ) * _SpeedLinesRadialScale * 2.0 ) , ( atan2( break17_g1.x , break17_g1.y ) * ( 1.0 / 6.28318548202515 ) * _SpeedLinesTiling )));
float2 appendResult58 = (float2(( -_SpeedLinesAnimation * _Time.y ) , 0.0));
float simplePerlin2D10 = snoise( ( appendResult23_g1 + appendResult58 ) );
simplePerlin2D10 = simplePerlin2D10*0.5 + 0.5;
float temp_output_1_0_g6 = _SpeedLinesRemap;
float SpeedLines21 = saturate( ( ( pow( simplePerlin2D10 , _SpeedLinesPower ) - temp_output_1_0_g6 ) / ( 1.0 - temp_output_1_0_g6 ) ) );
float2 texCoord60 = uv * float2( 2,2 ) + float2( -1,-1 );
float temp_output_1_0_g5 = _MaskScale;
float lerpResult71 = lerp( 0.0 , _MaskScale , _MaskHardness);
float Mask24 = pow( ( 1.0 - saturate( ( ( length( texCoord60 ) - temp_output_1_0_g5 ) / ( ( lerpResult71 - 0.001 ) - temp_output_1_0_g5 ) ) ) ) , _MaskPower );
float MaskedSpeedLines29 = ( SpeedLines21 * Mask24 );
float3 ColourRGB38 = (_Colour).rgb;
float ColourA40 = _Colour.a;
float4 speedLineColor = float4( ( MaskedSpeedLines29 * ColourRGB38 ) , SceneColour7.a );
float4 lerpResult2 = lerp( SceneColour7 , speedLineColor , ( MaskedSpeedLines29 * ColourA40 ));
return lerpResult2;
}
ENDHLSL
Pass
{
Name "Speed Lines Pass"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment SpeedLinesPassFragment
ENDHLSL
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: a46d3ad17881bcc40bb90b165375974f
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,135 @@
Shader "SLS/Postprocessing/StrobeFlash"
{
SubShader
{
Tags
{
"RenderType" = "Opaque"
"RenderPipeline" = "UniversalPipeline"
}
ZWrite Off
Cull Off
HLSLINCLUDE
#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.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
// --- 参数定义 ---
float4 _StrobeColorHigh;
float4 _StrobeColorLow;
float4 _StrobeParams;
float4 _StrobeAdvParams;
// x: Noise Reduction
// y: Softness
// z: Outline Thickness
// w: Outline Threshold (新增:深度差异阈值)
float4 _LuminanceWeights;
// --- 辅助函数 ---
half3 BoxBlur(float2 uv, float radius)
{
float4 offset = _BlitTexture_TexelSize.xyxy * radius * float4(-1, -1, 1, 1);
half3 c1 = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + offset.xy).rgb;
half3 c2 = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + offset.zy).rgb;
half3 c3 = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + offset.xw).rgb;
half3 c4 = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + offset.zw).rgb;
return (c1 + c2 + c3 + c4) * 0.25;
}
// 修改:增加 threshold 参数
float GetEdge(float2 uv, float thickness, float threshold)
{
if(thickness <= 0) return 0;
float2 size = _BlitTexture_TexelSize.xy * thickness;
float d1 = SampleSceneDepth(uv + size);
float d2 = SampleSceneDepth(uv - size);
float d3 = SampleSceneDepth(uv + float2(size.x, -size.y));
float d4 = SampleSceneDepth(uv + float2(-size.x, size.y));
d1 = LinearEyeDepth(d1, _ZBufferParams);
d2 = LinearEyeDepth(d2, _ZBufferParams);
d3 = LinearEyeDepth(d3, _ZBufferParams);
d4 = LinearEyeDepth(d4, _ZBufferParams);
float diff1 = abs(d1 - d2);
float diff2 = abs(d3 - d4);
// 使用传入的阈值,而不是写死的 0.1
// 只有当深度差 > threshold 时,才认为是边缘
return step(threshold, diff1 + diff2);
}
half4 StrobeFlashPassFragment(Varyings input) : SV_Target
{
half2 uv = input.texcoord;
float frequency = _StrobeParams.x;
float threshold = _StrobeParams.y;
float noiseReduction = _StrobeAdvParams.x;
float softness = _StrobeAdvParams.y;
// 新增参数获取
float outlineThickness = _StrobeAdvParams.z;
float outlineThreshold = max(0.001, _StrobeAdvParams.w); // 防止除0或负数
float3 lumWeights = _LuminanceWeights.rgb;
// 采样颜色 (带降噪)
half3 sceneColor;
if (noiseReduction > 0.01)
{
sceneColor = BoxBlur(uv, noiseReduction);
}
else
{
sceneColor = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv).rgb;
}
float luminance = dot(sceneColor, lumWeights);
float softRange = max(0.001, softness);
float t = smoothstep(threshold - softRange, threshold + softRange, luminance);
float isAuto = _StrobeParams.z;
float isManualInvert = _StrobeParams.w;
float invertSignal = 0;
if (isAuto > 0.5)
{
invertSignal = step(0, sin(_Time.y * frequency * PI));
}
invertSignal = max(invertSignal, isManualInvert);
// 边缘检测:传入 Thickness 和 Threshold
float edge = GetEdge(uv, outlineThickness, outlineThreshold);
t = abs(t - edge);
float3 finalColor;
if (invertSignal > 0.5)
{
finalColor = lerp(_StrobeColorHigh.rgb, _StrobeColorLow.rgb, t);
}
else
{
finalColor = lerp(_StrobeColorLow.rgb, _StrobeColorHigh.rgb, t);
}
return half4(finalColor, 1);
}
ENDHLSL
Pass
{
Name "Strobe Flash Pass"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment StrobeFlashPassFragment
ENDHLSL
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: aa12587766ec16842a16c1965e43da43
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant: