后处理修复
This commit is contained in:
@@ -23,15 +23,14 @@ Shader "Hidden/Custom/Pixelate"
|
||||
half4 Frag(Varyings input) : SV_Target
|
||||
{
|
||||
float2 uv = input.texcoord;
|
||||
float2 strength = float2(_PixelateStrengthX, _PixelateStrengthY);
|
||||
|
||||
// 防止除数为0的极小可能崩溃
|
||||
strength = max(strength, float2(1.0, 1.0));
|
||||
float2 resolutionRatio = saturate(float2(_PixelateStrengthX, _PixelateStrengthY));
|
||||
// 使用当前渲染目标分辨率,而不是设备固定分辨率,兼容动态分辨率和渲染缩放。
|
||||
float2 targetResolution = max(floor(_ScreenParams.xy * resolutionRatio), float2(1.0, 1.0));
|
||||
|
||||
float2 uvScaled = uv * strength;
|
||||
float2 uvScaled = uv * targetResolution;
|
||||
float2 uvFloor = floor(uvScaled);
|
||||
float2 uvCenter = uvFloor + 0.5;
|
||||
float2 uvPixelated = uvCenter / strength;
|
||||
float2 uvPixelated = uvCenter / targetResolution;
|
||||
|
||||
// Blitter框架将自动把 SourceTexture 注入为 _BlitTexture
|
||||
return SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uvPixelated);
|
||||
|
||||
@@ -17,9 +17,12 @@ namespace SLSUtilities.Rendering.PostProcessing
|
||||
|
||||
[Tooltip("是否强制开启像素化效果")]
|
||||
public BoolParameter forceActive = new BoolParameter(false);
|
||||
|
||||
public FloatParameter strengthX = new FloatParameter(1920f);
|
||||
public FloatParameter strengthY = new FloatParameter(1080f);
|
||||
|
||||
[Tooltip("横向分辨率比例,0 到 1;1 为当前渲染分辨率")]
|
||||
public FloatParameter strengthX = new FloatParameter(1f);
|
||||
|
||||
[Tooltip("纵向分辨率比例,0 到 1;1 为当前渲染分辨率")]
|
||||
public FloatParameter strengthY = new FloatParameter(1f);
|
||||
|
||||
// 返回我们在 Shader 里定义的名字,保证管家可以据此获取材质
|
||||
public override string GetShaderName() => "Hidden/Custom/Pixelate";
|
||||
@@ -34,11 +37,11 @@ namespace SLSUtilities.Rendering.PostProcessing
|
||||
{
|
||||
if (material == null) return;
|
||||
|
||||
cmd.SetGlobalFloat(InternalShaderHelpers.ID._PixelateStrengthX, strengthX.value);
|
||||
cmd.SetGlobalFloat(InternalShaderHelpers.ID._PixelateStrengthY, strengthY.value);
|
||||
cmd.SetGlobalFloat(InternalShaderHelpers.ID._PixelateStrengthX, Mathf.Clamp01(strengthX.value));
|
||||
cmd.SetGlobalFloat(InternalShaderHelpers.ID._PixelateStrengthY, Mathf.Clamp01(strengthY.value));
|
||||
|
||||
// 使用你的统一管家分发的 Blitter 进行优雅渲染
|
||||
Blitter.BlitCameraTexture(cmd, source, destination, material, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user