Skip to content

Fix issues with bloom sampling outside #1930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed an error when building the player.
- Fixed issue with box light not visible if range is below one and range attenuation is off.
- Fixed alpha not having TAA applied to it.
- Fixed issue with bloom showing a thin black line after rescaling window.

### Changed
- Preparation pass for RTSSShadows to be supported by render graph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ class AlphaCopyPassData
public TextureHandle outputAlpha;
}

class GuardBandPassData
{
public ClearWithGuardBandsParameters parameters;
public TextureHandle source;
}

class StopNaNPassData
{
public StopNaNParameters parameters;
Expand Down Expand Up @@ -235,23 +229,6 @@ TextureHandle DoCopyAlpha(RenderGraph renderGraph, HDCamera hdCamera, TextureHan
return renderGraph.defaultResources.whiteTextureXR;
}

TextureHandle ClearWithGuardBands(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle source)
{
using (var builder = renderGraph.AddRenderPass<GuardBandPassData>("Guard Band Clear", out var passData, ProfilingSampler.Get(HDProfileId.GuardBandClear)))
{
passData.source = builder.WriteTexture(source);
passData.parameters = PrepareClearWithGuardBandsParameters(hdCamera);

builder.SetRenderFunc(
(GuardBandPassData data, RenderGraphContext ctx) =>
{
ClearWithGuardBands(data.parameters, ctx.cmd, data.source);
});

return passData.source;
}
}

TextureHandle StopNaNsPass(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle source)
{
// Optional NaN killer before post-processing kicks in
Expand Down Expand Up @@ -1016,9 +993,6 @@ public void Render(RenderGraph renderGraph,

if (m_PostProcessEnabled)
{

source = ClearWithGuardBands(renderGraph, hdCamera, source);

source = StopNaNsPass(renderGraph, hdCamera, source);

source = DynamicExposurePass(renderGraph, hdCamera, source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,27 +449,6 @@ ClearWithGuardBandsParameters PrepareClearWithGuardBandsParameters(HDCamera came
return parameters;
}

static void ClearWithGuardBands(in ClearWithGuardBandsParameters parameters, CommandBuffer cmd, RTHandle source)
{
// Guard bands (also known as "horrible hack") to avoid bleeding previous RTHandle
// content into smaller viewports with some effects like Bloom that rely on bilinear
// filtering and can't use clamp sampler and the likes
// Note: some platforms can't clear a partial render target so we directly draw black triangles
{
int w = parameters.cameraWidth;
int h = parameters.cameraHeight;
cmd.SetRenderTarget(source, 0, CubemapFace.Unknown, -1);

if (w < source.rt.width || h < source.rt.height)
{
cmd.SetViewport(new Rect(w, 0, k_RTGuardBandSize, h));
cmd.DrawProcedural(Matrix4x4.identity, parameters.clearMaterial, 0, MeshTopology.Triangles, 3, 1);
cmd.SetViewport(new Rect(0, h, w + k_RTGuardBandSize, k_RTGuardBandSize));
cmd.DrawProcedural(Matrix4x4.identity, parameters.clearMaterial, 0, MeshTopology.Triangles, 3, 1);
}
}
}

public void Render(CommandBuffer cmd, HDCamera camera, BlueNoise blueNoise, RTHandle colorBuffer, RTHandle afterPostProcessTexture, RenderTargetIdentifier finalRT, RTHandle depthBuffer, RTHandle depthMipChain, RTHandle motionVecTexture, bool flipY)
{
var dynResHandler = DynamicResolutionHandler.instance;
Expand Down Expand Up @@ -497,8 +476,6 @@ void PoolSource(ref RTHandle src, RTHandle dst)

if (m_PostProcessEnabled)
{
ClearWithGuardBands(PrepareClearWithGuardBandsParameters(camera), cmd, source);

// Optional NaN killer before post-processing kicks in
bool stopNaNs = camera.stopNaNs && m_StopNaNFS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void KMain(uint3 dispatchThreadId : SV_DispatchThreadID)
float3 output = acc / wSum;

// Guard bands
output *= all(dispatchThreadId.xy < uint2(_TexelSize.xy));
output *= all(dispatchThreadId.xy <= uint2(_TexelSize.xy));

_OutputTexture[COORD_TEXTURE2D_X(posInputs.positionSS)] = output;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ void KMain(uint3 dispatchThreadId : SV_DispatchThreadID)
{
UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z);
PositionInputs posInputs = GetPositionInput(float2(dispatchThreadId.xy), _TexelSize.zw, uint2(GROUP_SIZE, GROUP_SIZE));
float2 uv = ClampAndScaleUVForBilinear(posInputs.positionNDC, _TexelSize.zw) ;
float3 highRes = LOAD_TEXTURE2D_X(_InputHighTexture, posInputs.positionSS).xyz;
float2 uv = ClampAndScaleUV(posInputs.positionNDC, _BloomBicubicParams.zw, 1.0f);
float3 highRes = LOAD_TEXTURE2D_X(_InputHighTexture, clamp(posInputs.positionSS, 0, _TexelSize.xy - 1)).xyz;

#if LOW_QUALITY
float3 lowRes = SAMPLE_TEXTURE2D_X_LOD(_InputLowTexture, sampler_LinearClamp, uv, 0.0).xyz;
Expand All @@ -43,7 +43,7 @@ void KMain(uint3 dispatchThreadId : SV_DispatchThreadID)
float3 output = lerp(highRes, lowRes, Scatter);

// Guard bands
output *= all(dispatchThreadId.xy < uint2(_TexelSize.xy));
output *= all(dispatchThreadId.xy <= uint2(_TexelSize.xy));

_OutputTexture[COORD_TEXTURE2D_X(dispatchThreadId.xy)] = output;
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,9 @@ void MAIN(uint3 dispatchThreadId : SV_DispatchThreadID)
float mip = min(kMaxMips, (1.0 / (SampleCount - 1.5)) * samp0CoC * Radius);
#endif

// Avoid bleeding with the RTHandle autosize system
#if FAR
// A bit more generous maxCoord because of trilinear being involved.
float texelsToClamp = 2.0f;
#else
float texelsToClamp = 1.0f;
#endif
uint mipCeiled = ceil(mip);
float texelsToClamp = (1u << mipCeiled) + 1;

float4 acc = 0.0;
float nearWeightAcc = 0.0;
float accAlpha = 0.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ internal enum HDProfileId
UpsampleLowResTransparent,

// Post-processing
GuardBandClear,
AlphaCopy,
StopNaNs,
FixedExposure,
Expand Down