Skip to content

[HDRP] Fix error in Depth Of Field near radius blur calculation #3131

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 3 commits into from
Jan 15, 2021
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 @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed issue with compositor related custom passes still active after disabling the compositor (case 1305330)
- Fixed some render texture leaks.
- Fixed regression in Wizard that not fix runtime ressource anymore (case 1287627)
- Fixed error in Depth Of Field near radius blur calculation (case 1306228).

### Changed
- Change the source value for the ray tracing frame index iterator from m_FrameCount to the camera frame count (case 1301356).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,10 @@ TextureHandle DepthOfFieldPass(RenderGraph renderGraph, HDCamera hdCamera, Textu
passData.fullresCoC = builder.CreateTransientTexture(new TextureDesc(Vector2.one, true, true)
{ colorFormat = k_CoCFormat, enableRandomWrite = true, name = "Full res CoC" });

int passCount = Mathf.CeilToInt((passData.parameters.nearMaxBlur + 2f) / 4f);
GetDoFResolutionScale(passData.parameters, out float unused, out float resolutionScale);
float actualNearMaxBlur = passData.parameters.nearMaxBlur * resolutionScale;
int passCount = Mathf.CeilToInt((actualNearMaxBlur + 2f) / 4f);

passData.dilationPingPongRT = TextureHandle.nullHandle;
if (passCount > 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,12 @@ DepthOfFieldParameters PrepareDoFParameters(HDCamera camera)
return parameters;
}

static void GetDoFResolutionScale(in DepthOfFieldParameters dofParameters, out float scale, out float resolutionScale)
{
scale = 1f / (float)dofParameters.resolution;
resolutionScale = (dofParameters.camera.actualHeight / 1080f) * (scale * 2f);
}

//
// Reference used:
// "A Lens and Aperture Camera Model for Synthetic Image Generation" [Potmesil81]
Expand Down Expand Up @@ -1551,14 +1557,13 @@ static void DoDepthOfField(in DepthOfFieldParameters dofParameters, CommandBuffe
float anamorphism = dofParameters.physicalCameraAnamorphism / 4f;
float barrelClipping = dofParameters.physicalCameraBarrelClipping / 3f;

float scale = 1f / (float)dofParameters.resolution;
GetDoFResolutionScale(dofParameters, out float scale, out float resolutionScale);
var screenScale = new Vector2(scale, scale);
int targetWidth = Mathf.RoundToInt(dofParameters.camera.actualWidth * scale);
int targetHeight = Mathf.RoundToInt(dofParameters.camera.actualHeight * scale);

cmd.SetGlobalVector(HDShaderIDs._TargetScale, new Vector4((float)dofParameters.resolution, scale, 0f, 0f));

float resolutionScale = (dofParameters.camera.actualHeight / 1080f) * (scale * 2f);
int farSamples = dofParameters.farSampleCount;
int nearSamples = dofParameters.nearSampleCount;

Expand Down