Skip to content
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

[HDRP] Physically-based DoF speed and robustness improvements + bugfixes #2353

Merged
merged 25 commits into from
Oct 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8aea89c
Fix near edges - remove old alpha normalization code
pmavridis Oct 21, 2020
33094ad
Fix alpha output
pmavridis Oct 21, 2020
c6d9d9f
Dof alpha output: preserve pixels with zero alpha
pmavridis Oct 21, 2020
1a24588
Physical DoF: generate color pyramid
pmavridis Oct 22, 2020
72cd729
Physical DoF: mip map selection based on radius
pmavridis Oct 22, 2020
d71fe33
Remove the preview indicator from the UI
pmavridis Oct 22, 2020
ecc26e7
Old (not rendergraph) pipeline implementation
pmavridis Oct 22, 2020
0c923d6
fix mem leak
pmavridis Oct 22, 2020
397a346
Support for much larger CoC radii
pmavridis Oct 22, 2020
88f90d7
Shader cleanup
pmavridis Oct 22, 2020
ed2d3c0
Tweak lod selection
pmavridis Oct 22, 2020
8fbea7d
Improve sampling noise
pmavridis Oct 22, 2020
82c6842
Fix post-dof TAA in rendergraph
pmavridis Oct 22, 2020
d755047
Shader cleanup
pmavridis Oct 23, 2020
31f309d
Bugfix for taa in DoF
pmavridis Oct 23, 2020
ccd8011
Bugfix for RTHandles: scale and clamp the UVs properly
pmavridis Oct 23, 2020
eaf9e1b
Temporary fix for Rendergraph post-dof TAA
pmavridis Oct 23, 2020
8aaf50f
Commit minor fixes before rebase
pmavridis Oct 23, 2020
4bbfc77
Revert "Remove the preview indicator from the UI"
pmavridis Oct 23, 2020
c29249b
Tweak parameter range to a more safe range
pmavridis Oct 23, 2020
a58f1c7
Remove unused code
pmavridis Oct 25, 2020
95f3b03
Remove unused code 2
pmavridis Oct 25, 2020
5a5bdbe
Dof shader: tweak sampling
pmavridis Oct 25, 2020
a98db85
Dof shader: tweak sampling
pmavridis Oct 25, 2020
0eeada8
Update changelog
pmavridis Oct 25, 2020
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
Prev Previous commit
Next Next commit
Support for much larger CoC radii
  • Loading branch information
pmavridis committed Oct 25, 2020
commit 397a346ddcd251479abc86dd961113724b2680ba
Original file line number Diff line number Diff line change
Expand Up @@ -2552,7 +2552,7 @@ static void DoPhysicallyBasedDepthOfField(in DepthOfFieldParameters dofParameter

// Map the old "max radius" parameters to a bigger range, so we can work on more challenging scenes
float maxRadius = Mathf.Max(dofParameters.farMaxBlur, dofParameters.nearMaxBlur);
float cocLimit = Mathf.Clamp(4 * maxRadius, 1, 64);
float cocLimit = Mathf.Clamp(16 * maxRadius, 1, 256);

ComputeShader cs;
int kernel;
Expand Down Expand Up @@ -2610,15 +2610,54 @@ static void DoPhysicallyBasedDepthOfField(in DepthOfFieldParameters dofParameter
cs = dofParameters.dofCoCPyramidCS;
kernel = dofParameters.dofCoCPyramidKernel;

float numMips = Mathf.Floor(Mathf.Log(Mathf.Max((dofParameters.camera.actualWidth + 31), (dofParameters.camera.actualHeight + 31)), 2));

cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._InputTexture, fullresCoC);
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip1, fullresCoC, 1);
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip2, fullresCoC, 2);
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip3, fullresCoC, 3);
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip4, fullresCoC, 4);
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip5, fullresCoC, 5);
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip6, fullresCoC, 6);
cmd.SetComputeVectorParam(cs, HDShaderIDs._Params, new Vector4(numMips, 0, 0, 0));
cmd.DispatchCompute(cs, kernel, (dofParameters.camera.actualWidth + 31) / 32, (dofParameters.camera.actualHeight + 31) / 32, dofParameters.camera.viewCount);

// do we need a second pass for the rest?
if (numMips > 6.0f && cocLimit > 64)
{
GetMipMapDimensions(fullresCoC, 6, out var mipMapWidth, out var mipMapHeight);
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._InputTexture, fullresCoC, 6);
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip1, fullresCoC, 7);

if (numMips > 7)
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip2, fullresCoC, 8);
else
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip2, fullresCoC, 1); // we will never write on this, but still need to bind something

if (numMips > 8)
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip3, fullresCoC, 9);
else
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip3, fullresCoC, 2); // we will never write on this, but still need to bind something

if (numMips > 9)
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip4, fullresCoC, 10);
else
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip4, fullresCoC, 3); // we will never write on this, but still need to bind something

if (numMips > 10)
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip5, fullresCoC, 11);
else
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip5, fullresCoC, 4); // we will never write on this, but still need to bind something

if (numMips > 11)
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip6, fullresCoC, 12);
else
cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._OutputMip6, fullresCoC, 5); // we will never write on this, but still need to bind something

cmd.SetComputeVectorParam(cs, HDShaderIDs._Params, new Vector4(numMips - 6.0f, 0, 0, 0));
cmd.DispatchCompute(cs, kernel, (mipMapWidth + 31) / 32, (mipMapHeight + 31) / 32, dofParameters.camera.viewCount);
}

// DoF color pyramid
if (sourcePyramid != null)
{
Expand All @@ -2644,8 +2683,7 @@ static void DoPhysicallyBasedDepthOfField(in DepthOfFieldParameters dofParameter
kernel = dofParameters.pbDoFGatherKernel;
float sampleCount = Mathf.Max(dofParameters.nearSampleCount, dofParameters.farSampleCount);

// We only have up to 6 mip levels
float mipLevel = Mathf.Min(6, 1 + Mathf.Ceil(Mathf.Log(cocLimit, 2)));
float mipLevel = 1 + Mathf.Ceil(Mathf.Log(cocLimit, 2));
GetMipMapDimensions(fullresCoC, (int)mipLevel, out var mipMapWidth, out var mipMapHeight);
cmd.SetComputeVectorParam(cs, HDShaderIDs._Params, new Vector4(sampleCount, cocLimit, 0.0f, 0.0f));
cmd.SetComputeVectorParam(cs, HDShaderIDs._Params2, new Vector4(mipLevel, mipMapWidth, mipMapHeight, 0.0f));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

#pragma kernel KMainCoCPyramid

CBUFFER_START(cb0)
float4 _Params;
CBUFFER_END

#define NumMips _Params.x

RW_TEXTURE2D_X(float, _InputTexture);

RW_TEXTURE2D_X(float, _OutputMip1);
Expand Down Expand Up @@ -52,6 +58,9 @@ void KMainCoCPyramid(uint3 dispatchThreadId : SV_DispatchThreadID, uint groupInd

_OutputMip1[COORD_TEXTURE2D_X(dispatchThreadId.xy)] = color;

if (NumMips <= 1.0)
return;

GroupMemoryBarrierWithGroupSync();

// Second mip - checks that X and Y are even
Expand All @@ -66,6 +75,9 @@ void KMainCoCPyramid(uint3 dispatchThreadId : SV_DispatchThreadID, uint groupInd
_OutputMip2[COORD_TEXTURE2D_X(dispatchThreadId.xy / 2u)] = color;
}

if (NumMips <= 2.0)
return;

GroupMemoryBarrierWithGroupSync();

// Third mip - checks that X and Y are multiples of four
Expand All @@ -79,6 +91,9 @@ void KMainCoCPyramid(uint3 dispatchThreadId : SV_DispatchThreadID, uint groupInd
_OutputMip3[COORD_TEXTURE2D_X(dispatchThreadId.xy / 4u)] = color;
}

if (NumMips <= 3.0)
return;

GroupMemoryBarrierWithGroupSync();

// Fourth mip - checks that X and Y are multiples of 8
Expand All @@ -92,6 +107,9 @@ void KMainCoCPyramid(uint3 dispatchThreadId : SV_DispatchThreadID, uint groupInd
_OutputMip4[COORD_TEXTURE2D_X(dispatchThreadId.xy / 8u)] = color;
}

if (NumMips <= 4.0)
return;

GroupMemoryBarrierWithGroupSync();

// Fifth mip - checks that X and Y are multiples of 16
Expand All @@ -104,6 +122,9 @@ void KMainCoCPyramid(uint3 dispatchThreadId : SV_DispatchThreadID, uint groupInd
_OutputMip5[COORD_TEXTURE2D_X(dispatchThreadId.xy / 16u)] = color;
}

if (NumMips <= 5.0)
return;

// Last mip - only one thread
if (groupIndex == 0)
{
Expand Down