Files
Cielonos/Assets/Shaders/ScriptablePostProcessor/PostProcessingPass.hlsl
SoulliesOfficial ef7b479712 initial
2025-11-25 08:19:33 -05:00

405 lines
17 KiB
HLSL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef ECHOVOID_POSTPROCESSING_PASS
#define ECHOVOID_POSTPROCESSING_PASS
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
TEXTURE2D_X(_CameraOpaqueTexture);
SAMPLER(sampler_CameraOpaqueTexture);
// PostProcessor - RGB Split Glitch Pass || BEGIN ------
float4 _RGBSplitGlitchParams;
#define _RGBSplitGlitchIntensity _RGBSplitGlitchParams.x
#define _TimeX _RGBSplitGlitchParams.y
float randomNoise(float x, float y)
{
return frac(sin(dot(float2(x, y), float2(12.9898, 78.233))) * 43758.5453);
}
float4 RGBSplitGlitchPassFragment(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float splitAmount = _RGBSplitGlitchIntensity * randomNoise(_TimeX, 2);
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);
}
// PostProcessor - RGB Split Glitch Pass || END ------
// PostProcessor - RGB Split Glitch Pass || BEGIN ------
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); //1 MAD
scale = _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 2 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 3 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
color *= 0.25f; // 1/4
return color;
}
half4 RadialBlurPassFragment_8Tap(Varyings input): SV_Target
{
float2 uv = input.texcoord - _RadialCenter;
half scale = 1;
half4 color = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 2 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 3 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 4 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 5 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 6 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 7 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
color *= 0.125f; // 1/8
return color;
}
half4 RadialBlurPassFragment_12Tap(Varyings input): SV_Target
{
float2 uv = input.texcoord - _RadialCenter;
half scale = 1;
half4 color = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 2 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 3 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 4 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 5 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 6 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 7 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 8 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 9 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 10 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 11 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
color *= 0.0833f; // 1/12
return color;
}
half4 RadialBlurPassFragment_20Tap(Varyings input): SV_Target
{
float2 uv = input.texcoord - _RadialCenter;
half scale = 1;
half4 color = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 2 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 3 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 4 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 5 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 6 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 7 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 8 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 9 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 10 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 11 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 12 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 13 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 14 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 15 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 16 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 17 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 18 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 19 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
color *= 0.05f; // 1/20
return color;
}
half4 RadialBlurPassFragment_30Tap(Varyings input): SV_Target
{
float2 uv = input.texcoord - _RadialCenter;
half scale = 1;
half4 color = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 2 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 3 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 4 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 5 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 6 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 7 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 8 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 9 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 10 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 11 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 12 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 13 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 14 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 15 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 16 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 17 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 18 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 19 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 20 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 21 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 22 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 23 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 24 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 25 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 26 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 27 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 28 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
scale = 29 * _BlurRadius + 1; //1 MAD
color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv * scale + _RadialCenter); //1 MAD
color *= 0.0333f; // 1/30
return color;
}
// PostProcessor - RGB Split Glitch Pass || END ------
// PostProcessor - Anime Speed Lines || BEGIN ------
float4 _Colour;
float _SpeedLinesTiling;
float _SpeedLinesRadialScale;
float _SpeedLinesPower;
float _SpeedLinesRemap;
float _SpeedLinesAnimation;
float _MaskScale;
float _MaskHardness;
float _MaskPower;
// 2. 移植原 Shader 中的 snoise (Simplex Noise) 函数
// (这段代码从原 shader 中原封不动地复制过来)
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 );
}
// 3. 移植原 Shader 的 frag 函数逻辑
half4 SpeedLinesPassFragment(Varyings input) : SV_Target
{
// input.texcoord 是 URP 框架提供的正确 UV 坐标
half2 uv = input.texcoord;
// [cite: 26] 用 URP 的方式采样屏幕纹理(原图)
half4 SceneColour7 = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv);
// --- 下面是原 frag 函数 [cite: 27-34] 的核心逻辑,几乎是 1:1 复制 ---
// [cite: 27] 计算中心 UV
float2 CenteredUV15_g1 = ( uv - float2( 0.5,0.5 ) );
float2 break17_g1 = CenteredUV15_g1;
// [cite: 27] 转换为极坐标(长度和角度)并应用 Tiling
float2 appendResult23_g1 = (float2(( length( CenteredUV15_g1 ) * _SpeedLinesRadialScale * 2.0 ) , ( atan2( break17_g1.x , break17_g1.y ) * ( 1.0 / 6.28318548202515 ) * _SpeedLinesTiling )));
// [cite: 28] 应用时间动画
// _Time.y 是 Unity 内置的 Shader 变量,可以直接使用
float2 appendResult58 = (float2(( -_SpeedLinesAnimation * _Time.y ) , 0.0));
// [cite: 28, 29] 采样 Simplex Noise
float simplePerlin2D10 = snoise( ( appendResult23_g1 + appendResult58 ) );
simplePerlin2D10 = simplePerlin2D10*0.5 + 0.5; // 重新映射到 0-1
// [cite: 29] 应用 Power 和 Remap生成线条
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 ) ) );
// [cite: 30, 31] 计算中心径向遮罩
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 );
// [cite: 32] 组合线条和遮罩
float MaskedSpeedLines29 = ( SpeedLines21 * Mask24 );
// [cite: 33] 获取颜色
float3 ColourRGB38 = (_Colour).rgb;
float ColourA40 = _Colour.a; // Alpha 用作混合强度
// [cite: 33] 创建速度线颜色
float4 speedLineColor = float4( ( MaskedSpeedLines29 * ColourRGB38 ) , SceneColour7.a );
// [cite: 34] 最终混合:(原图, 速度线, 混合量)
// 混合量 = 线条 * 遮罩 * 颜色Alpha
float4 lerpResult2 = lerp( SceneColour7 , speedLineColor , ( MaskedSpeedLines29 * ColourA40 ));
return lerpResult2;
}
// PostProcessor - Anime Speed Lines || END ------
#endif // ECHOVOID_POSTPROCESSING_PASS (确保这是你文件的最后一行)