Skip to content

Fixed an issue with the frame count management for the volumetric fog (case 1299251). #2947

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 32 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
259c344
[HDRP] Fix coat normal space (#2888)
alelievr Dec 15, 2020
e5e7c25
Merge branch 'master' into hd/bugfix
sebastienlagarde Dec 15, 2020
b68ce13
Avoid issues causing faulty transitions in shadows (resulting in no s…
FrancescoC-unity Dec 15, 2020
9cf8ac1
Merge branch 'master' into hd/bugfix
sebastienlagarde Dec 15, 2020
53096ec
Fixed invalid loop length for probe baking (case 1289680) (#2830)
fredericv-unity3d Dec 15, 2020
7339d48
Fix volumetric fog with XR single-pass (#2823)
fabien-unity Dec 15, 2020
85f8877
[HDRP] Fix rendering issues for the first frame (#2836)
pmavridis Dec 15, 2020
2653b9c
Update 5001_Fog_FogFallback.png
sebastienlagarde Dec 15, 2020
95eb52e
Revert "Update 5001_Fog_FogFallback.png"
sebastienlagarde Dec 15, 2020
33e6948
Update 5001_Fog_FogFallback.unity
sebastienlagarde Dec 15, 2020
fcd7472
Fix AOV API for render graph (#2909)
pmavridis Dec 16, 2020
94f3898
Fix a small discrepancy in the marker placement in light intensity sl…
pmavridis Dec 17, 2020
7767a31
Merge branch 'master' into hd/bugfix
sebastienlagarde Dec 17, 2020
fb1ec50
Update CHANGELOG.md
sebastienlagarde Dec 17, 2020
abb5bb5
Fix issue with VT spewing errors when transparent and opaque are disa…
FrancescoC-unity Dec 17, 2020
6a47be7
Fixed a bug in the sphere-aabb light cluster (case 1294767). (#2920)
anisunity Dec 17, 2020
4b1ac9c
Move EndCameraRendering callback out of the profiling scope (#2917)
adrien-de-tocqueville Dec 17, 2020
980307b
Fixed baked light being included into the ray tracing light cluster (…
anisunity Dec 17, 2020
f738893
Handle all enums the same way for UI (#2913)
adrien-de-tocqueville Dec 17, 2020
a20e885
Changed the message when the graphics device doesn't support ray trac…
anisunity Dec 17, 2020
2784ac6
[HDRP] Fix default blocks for Hair and Eye shader graphs (#2919)
alelievr Dec 17, 2020
b42cae6
Init scene camera debug framesettings (#2931)
adrien-de-tocqueville Dec 17, 2020
2064794
Fixed using the wrong method to define if a light should be included …
anisunity Dec 17, 2020
2fccfa9
[HDRP] Change the behavior of custom passes when the volume is disabl…
alelievr Dec 17, 2020
4befd38
Fixed display of LOD Bias and maximum level in frame settings when us…
JulienIgnace-Unity Dec 17, 2020
1d8d6c5
Fixed an issue when trying to open a look dev env library when Look D…
JulienIgnace-Unity Dec 17, 2020
f0ae90b
Enable Reflector for Spotlight by default
sebastienlagarde Dec 17, 2020
c4ea601
- Fixed shader graph not supporting indirectdxr multibounce (case 129…
anisunity Dec 17, 2020
7276431
Fixed the planar depth texture not being properly created and rendere…
anisunity Dec 18, 2020
53e40c6
Fixed an issue with the frame count management for the volumetric fog…
anisunity Dec 18, 2020
c671ebb
Merge branch 'hd/bugfix' into HDRP/fix-volumetric-framecount
sebastienlagarde Dec 21, 2020
817f588
Update CHANGELOG.md
sebastienlagarde Dec 21, 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
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 @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed computation of geometric normal in path tracing (case 1293029).
- Fixed issues with path-traced volumetric scattering (cases 1295222, 1295234).
- Fixed the default background color for previews to use the original color.
- Fixed an issue with the frame count management for the volumetric fog (case 1299251).

### Changed
- Removed the material pass probe volumes evaluation mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ static internal void SafeDestroy(ref RenderTexture rt)
}
}

static uint VolumetricFrameIndex(HDCamera hdCamera)
{
// Here we do modulo 14 because we need the enable to detect a change every frame, but the accumulation is done on 7 frames (7x2=14)
return hdCamera.GetCameraFrameCount() % 14;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we have any constant value somewhere with this 7 ? Afraid to have hardcoded value hidden in a function like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now, no when the thing is accumulation frame index is computed its explicitely written frameIndex % 7

}

static internal Vector3Int ComputeVolumetricViewportSize(HDCamera hdCamera, ref float voxelSize)
{
var controller = hdCamera.volumeStack.GetComponent<Fog>();
Expand Down Expand Up @@ -356,7 +362,7 @@ static internal void ReinitializeVolumetricBufferParams(HDCamera hdCamera)

// This function relies on being called once per camera per frame.
// The results are undefined otherwise.
static internal void UpdateVolumetricBufferParams(HDCamera hdCamera, int frameIndex)
static internal void UpdateVolumetricBufferParams(HDCamera hdCamera)
{
if (!Fog.IsVolumetricFogEnabled(hdCamera))
return;
Expand All @@ -366,6 +372,7 @@ static internal void UpdateVolumetricBufferParams(HDCamera hdCamera, int frameIn

var currentParams = ComputeVolumetricBufferParameters(hdCamera);

int frameIndex = (int)VolumetricFrameIndex(hdCamera);
var currIdx = (frameIndex + 0) & 1;
var prevIdx = (frameIndex + 1) & 1;

Expand Down Expand Up @@ -419,7 +426,7 @@ struct GenerateMaxZParameters
}


GenerateMaxZParameters PrepareGenerateMaxZParameters(HDCamera hdCamera, HDUtils.PackedMipChainInfo depthMipInfo, int frameIndex)
GenerateMaxZParameters PrepareGenerateMaxZParameters(HDCamera hdCamera, HDUtils.PackedMipChainInfo depthMipInfo)
{
var parameters = new GenerateMaxZParameters();
parameters.generateMaxZCS = defaultResources.shaders.maxZCS;
Expand All @@ -436,6 +443,7 @@ GenerateMaxZParameters PrepareGenerateMaxZParameters(HDCamera hdCamera, HDUtils.
parameters.minDepthMipOffset.x = depthMipInfo.mipLevelOffsets[4].x;
parameters.minDepthMipOffset.y = depthMipInfo.mipLevelOffsets[4].y;

int frameIndex = (int)VolumetricFrameIndex(hdCamera);
var currIdx = frameIndex & 1;
var currentParams = hdCamera.vBufferParams[currIdx];

Expand Down Expand Up @@ -549,7 +557,7 @@ static internal void DestroyVolumetricHistoryBuffers(HDCamera hdCamera)

// Must be called AFTER UpdateVolumetricBufferParams.
static readonly string[] volumetricHistoryBufferNames = new string[2] { "VBufferHistory0", "VBufferHistory1" };
static internal void ResizeVolumetricHistoryBuffers(HDCamera hdCamera, int frameIndex)
static internal void ResizeVolumetricHistoryBuffers(HDCamera hdCamera)
{
if (!hdCamera.IsVolumetricReprojectionEnabled())
return;
Expand All @@ -558,6 +566,7 @@ static internal void ResizeVolumetricHistoryBuffers(HDCamera hdCamera, int frame
Debug.Assert(hdCamera.vBufferParams.Length == 2);
Debug.Assert(hdCamera.volumetricHistoryBuffers != null);

int frameIndex = (int)VolumetricFrameIndex(hdCamera);
var currIdx = (frameIndex + 0) & 1;
var prevIdx = (frameIndex + 1) & 1;

Expand Down Expand Up @@ -627,7 +636,7 @@ internal void DestroyVolumetricLightingBuffers()
}

// Must be called AFTER UpdateVolumetricBufferParams.
internal void ResizeVolumetricLightingBuffers(HDCamera hdCamera, int frameIndex)
internal void ResizeVolumetricLightingBuffers(HDCamera hdCamera)
{
if (!Fog.IsVolumetricFogEnabled(hdCamera))
return;
Expand All @@ -643,6 +652,7 @@ internal void ResizeVolumetricLightingBuffers(HDCamera hdCamera, int frameIndex)
CreateVolumetricLightingBuffers();
}

int frameIndex = (int)VolumetricFrameIndex(hdCamera);
var currIdx = (frameIndex + 0) & 1;
var prevIdx = (frameIndex + 1) & 1;

Expand Down Expand Up @@ -819,11 +829,12 @@ unsafe void SetPreconvolvedAmbientLightProbe(ref ShaderVariablesVolumetric cb, H
cb._AmbientProbeCoeffs[i * 4 + j] = m_PackedCoeffs[i][j];
}

unsafe void UpdateShaderVariableslVolumetrics(ref ShaderVariablesVolumetric cb, HDCamera hdCamera, in Vector4 resolution, int frameIndex)
unsafe void UpdateShaderVariableslVolumetrics(ref ShaderVariablesVolumetric cb, HDCamera hdCamera, in Vector4 resolution)
{
var fog = hdCamera.volumeStack.GetComponent<Fog>();
var vFoV = hdCamera.camera.GetGateFittedFieldOfView() * Mathf.Deg2Rad;
var gpuAspect = HDUtils.ProjectionMatrixAspect(hdCamera.mainViewConstants.projMatrix);
int frameIndex = (int)VolumetricFrameIndex(hdCamera);

// Compose the matrix which allows us to compute the world space view direction.
hdCamera.GetPixelCoordToViewDirWS(resolution, gpuAspect, ref m_PixelCoordToViewDirWS);
Expand Down Expand Up @@ -886,10 +897,11 @@ unsafe void UpdateShaderVariableslVolumetrics(ref ShaderVariablesVolumetric cb,
cb._NumTileBigTileY = (uint)GetNumTileBigTileY(hdCamera);
}

VolumeVoxelizationParameters PrepareVolumeVoxelizationParameters(HDCamera hdCamera, int frameIndex)
VolumeVoxelizationParameters PrepareVolumeVoxelizationParameters(HDCamera hdCamera)
{
var parameters = new VolumeVoxelizationParameters();

int frameIndex = (int)VolumetricFrameIndex(hdCamera);
var currIdx = (frameIndex + 0) & 1;
var prevIdx = (frameIndex + 1) & 1;

Expand All @@ -912,7 +924,7 @@ VolumeVoxelizationParameters PrepareVolumeVoxelizationParameters(HDCamera hdCame
parameters.volumeAtlas = CoreUtils.blackVolumeTexture;
}

UpdateShaderVariableslVolumetrics(ref m_ShaderVariablesVolumetricCB, hdCamera, parameters.resolution, frameIndex);
UpdateShaderVariableslVolumetrics(ref m_ShaderVariablesVolumetricCB, hdCamera, parameters.resolution);
parameters.volumetricCB = m_ShaderVariablesVolumetricCB;
parameters.lightListCB = m_ShaderVariablesLightListCB;

Expand Down Expand Up @@ -992,10 +1004,11 @@ struct VolumetricLightingParameters
public ShaderVariablesLightList lightListCB;
}

VolumetricLightingParameters PrepareVolumetricLightingParameters(HDCamera hdCamera, int frameIndex)
VolumetricLightingParameters PrepareVolumetricLightingParameters(HDCamera hdCamera)
{
var parameters = new VolumetricLightingParameters();

int frameIndex = (int)VolumetricFrameIndex(hdCamera);
var currIdx = (frameIndex + 0) & 1;
var prevIdx = (frameIndex + 1) & 1;

Expand Down Expand Up @@ -1032,7 +1045,7 @@ VolumetricLightingParameters PrepareVolumetricLightingParameters(HDCamera hdCame
parameters.filterVolume = ((int)fog.denoisingMode.value & (int)FogDenoisingMode.Gaussian) != 0;
parameters.sliceCount = (int)(cvp.z);

UpdateShaderVariableslVolumetrics(ref m_ShaderVariablesVolumetricCB, hdCamera, parameters.resolution, frameIndex);
UpdateShaderVariableslVolumetrics(ref m_ShaderVariablesVolumetricCB, hdCamera, parameters.resolution);
parameters.volumetricCB = m_ShaderVariablesVolumetricCB;
parameters.lightListCB = m_ShaderVariablesLightListCB;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp,
isFirstFrame = false;
cameraFrameCount++;

HDRenderPipeline.UpdateVolumetricBufferParams(this, hdrp.GetFrameCount());
HDRenderPipeline.ResizeVolumetricHistoryBuffers(this, hdrp.GetFrameCount());
HDRenderPipeline.UpdateVolumetricBufferParams(this);
HDRenderPipeline.ResizeVolumetricHistoryBuffers(this);
}

/// <summary>Set the RTHandle scale to the actual camera size (can be scaled)</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,16 +600,15 @@ TextureHandle VolumeVoxelizationPass(RenderGraph renderGraph,
HDCamera hdCamera,
ComputeBuffer visibleVolumeBoundsBuffer,
ComputeBuffer visibleVolumeDataBuffer,
ComputeBufferHandle bigTileLightList,
int frameIndex)
ComputeBufferHandle bigTileLightList)
{
if (Fog.IsVolumetricFogEnabled(hdCamera))
{
using (var builder = renderGraph.AddRenderPass<VolumeVoxelizationPassData>("Volume Voxelization", out var passData))
{
builder.EnableAsyncCompute(hdCamera.frameSettings.VolumeVoxelizationRunsAsync());

passData.parameters = PrepareVolumeVoxelizationParameters(hdCamera, frameIndex);
passData.parameters = PrepareVolumeVoxelizationParameters(hdCamera);
passData.visibleVolumeBoundsBuffer = visibleVolumeBoundsBuffer;
passData.visibleVolumeDataBuffer = visibleVolumeDataBuffer;
if (passData.parameters.tiledLighting)
Expand Down Expand Up @@ -657,7 +656,7 @@ TextureHandle GenerateMaxZPass(RenderGraph renderGraph, HDCamera hdCamera, Textu

using (var builder = renderGraph.AddRenderPass<GenerateMaxZMaskPassData>("Generate Max Z Mask for Volumetric", out var passData))
{
passData.parameters = PrepareGenerateMaxZParameters(hdCamera, depthMipInfo, frameIndex);
passData.parameters = PrepareGenerateMaxZParameters(hdCamera, depthMipInfo);
passData.depthTexture = builder.ReadTexture(depthTexture);
passData.maxZ8xBuffer = builder.ReadTexture(renderGraph.ImportTexture(m_MaxZMask8x));
passData.maxZ8xBuffer = builder.WriteTexture(passData.maxZ8xBuffer);
Expand Down Expand Up @@ -691,11 +690,12 @@ class VolumetricLightingPassData
public ComputeBufferHandle bigTileLightListBuffer;
}

TextureHandle VolumetricLightingPass(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthTexture, TextureHandle densityBuffer, TextureHandle maxZBuffer, ComputeBufferHandle bigTileLightListBuffer, ShadowResult shadowResult, int frameIndex)
TextureHandle VolumetricLightingPass(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthTexture, TextureHandle densityBuffer, TextureHandle maxZBuffer, ComputeBufferHandle bigTileLightListBuffer, ShadowResult shadowResult)
{
if (Fog.IsVolumetricFogEnabled(hdCamera))
{
var parameters = PrepareVolumetricLightingParameters(hdCamera, frameIndex);
// Evaluate the parameters
var parameters = PrepareVolumetricLightingParameters(hdCamera);

using (var builder = renderGraph.AddRenderPass<VolumetricLightingPassData>("Volumetric Lighting", out var passData))
{
Expand All @@ -717,6 +717,7 @@ TextureHandle VolumetricLightingPass(RenderGraph renderGraph, HDCamera hdCamera,

if (passData.parameters.enableReprojection)
{
int frameIndex = (int)VolumetricFrameIndex(hdCamera);
var currIdx = (frameIndex + 0) & 1;
var prevIdx = (frameIndex + 1) & 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void ExecuteWithRenderGraph(RenderRequest renderRequest,

lightingBuffers.contactShadowsBuffer = RenderContactShadows(m_RenderGraph, hdCamera, msaa ? prepassOutput.depthValuesMSAA : prepassOutput.depthPyramidTexture, gpuLightListOutput, GetDepthBufferMipChainInfo().mipLevelOffsets[1].y);

var volumetricDensityBuffer = VolumeVoxelizationPass(m_RenderGraph, hdCamera, m_VisibleVolumeBoundsBuffer, m_VisibleVolumeDataBuffer, gpuLightListOutput.bigTileLightList, m_FrameCount);
var volumetricDensityBuffer = VolumeVoxelizationPass(m_RenderGraph, hdCamera, m_VisibleVolumeBoundsBuffer, m_VisibleVolumeDataBuffer, gpuLightListOutput.bigTileLightList);

RenderShadows(m_RenderGraph, hdCamera, cullingResults, ref shadowResult);

Expand Down Expand Up @@ -146,7 +146,7 @@ void ExecuteWithRenderGraph(RenderRequest renderRequest,

var maxZMask = GenerateMaxZPass(m_RenderGraph, hdCamera, prepassOutput.depthPyramidTexture, m_DepthBufferMipChainInfo, m_FrameCount);

var volumetricLighting = VolumetricLightingPass(m_RenderGraph, hdCamera, prepassOutput.depthPyramidTexture, volumetricDensityBuffer, maxZMask, gpuLightListOutput.bigTileLightList, shadowResult, m_FrameCount);
var volumetricLighting = VolumetricLightingPass(m_RenderGraph, hdCamera, prepassOutput.depthPyramidTexture, volumetricDensityBuffer, maxZMask, gpuLightListOutput.bigTileLightList, shadowResult);

var deferredLightingOutput = RenderDeferredLighting(m_RenderGraph, hdCamera, colorBuffer, prepassOutput.depthBuffer, prepassOutput.depthPyramidTexture, lightingBuffers, prepassOutput.gbuffer, shadowResult, gpuLightListOutput);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2299,7 +2299,7 @@ out ScriptableCullingParameters cullingParams

// From this point, we should only use frame settings from the camera
hdCamera.Update(currentFrameSettings, this, m_MSAASamples, xrPass);
ResizeVolumetricLightingBuffers(hdCamera, GetFrameCount()); // Safe to update the Volumetric Lighting System now
ResizeVolumetricLightingBuffers(hdCamera); // Safe to update the Volumetric Lighting System now

// Custom Render requires a proper HDCamera, so we return after the HDCamera was setup
if (additionalCameraData != null && additionalCameraData.hasCustomRender)
Expand Down