Skip to content

Commit

Permalink
Fix slight blur scaling with dynamic resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
alelievr committed Dec 18, 2023
1 parent fda692e commit 4fe545c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
16 changes: 1 addition & 15 deletions Assets/CustomPasses/SlightBlur/Resources/CompositeBlur.shader
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,12 @@
float4 _ViewportSize;
float _InvertMask;

// We need to clamp the UVs to avoid bleeding from bigger render tragets (when we have multiple cameras)
float2 ClampUVs(float2 uv)
{
uv = clamp(uv, 0, _RTHandleScale.xy - _ScreenSize.zw * 2); // clamp UV to 1 pixel to avoid bleeding
return uv;
}

float2 GetSampleUVs(Varyings varyings)
{
float depth = LoadCameraDepth(varyings.positionCS.xy);
PositionInputs posInput = GetPositionInput(varyings.positionCS.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V);
return posInput.positionNDC.xy * _RTHandleScale.xy;
}

float4 CompositeMaskedBlur(Varyings varyings) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(varyings);

float depth = LoadCameraDepth(varyings.positionCS.xy);
float2 uv = ClampUVs(varyings.positionCS.xy * _ScreenSize.zw * _RTHandleScale.xy);
float2 uv = varyings.positionCS.xy * _ScreenSize.zw * _RTHandleScale.xy / _DynamicResolutionFullscreenScale.xy;

float4 blurredBuffer = SAMPLE_TEXTURE2D_X_LOD(_Source, s_linear_clamp_sampler, uv, 0).rgba;
float4 mask = SAMPLE_TEXTURE2D_X_LOD(_Mask, s_linear_clamp_sampler, uv, 0);
Expand Down
2 changes: 1 addition & 1 deletion Assets/CustomPasses/SlightBlur/SlightBlur.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void GenerateGaussianMips(CustomPassContext ctx)
compositingProperties.SetTexture(ShaderID._Mask, maskBuffer);
compositingProperties.SetTexture(ShaderID._MaskDepth, maskDepthBuffer);
compositingProperties.SetFloat(ShaderID._InvertMask, invertMask ? 1 : 0);
// SetViewPortSize(ctx.cmd, compositingProperties, source);
SetViewPortSize(ctx.cmd, compositingProperties, source);
HDUtils.DrawFullScreen(ctx.cmd, compositeMaterial, source, compositingProperties, shaderPassId: 0); // Do not forget the shaderPassId! otherwise it won't work
}
}
Expand Down

0 comments on commit 4fe545c

Please sign in to comment.