Skip to content

Fix accumulation on DX11 #1987

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 4 commits into from
Oct 3, 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 @@ -120,6 +120,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed the Ray-Tracing related Debug Display not working in render graph mode.
- Fix nan in pbr sky
- Fixed Light skin not properly applied on the LookDev when switching from Dark Skin (case 1278802)
- Fixed accumulation on DX11

### 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 @@ -69,7 +69,7 @@ public class FrameManager : MonoBehaviour
{
RenderPipelineManager.beginFrameRendering -= PrepareSubFrameCallBack;
HDRenderPipeline renderPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
renderPipeline.EndRecording();
renderPipeline?.EndRecording();
m_Recording = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

#pragma kernel KMain

#pragma multi_compile _ INPUT_FROM_RADIANCE_TEXTURE

// Inputs
#ifdef INPUT_FROM_RADIANCE_TEXTURE
TEXTURE2D_X(_RadianceTexture);
#endif

float4 _AccumulationWeights;
int _AccumulationNeedsExposure;
uint _AccumulationFrameIndex;
Expand Down Expand Up @@ -55,8 +60,12 @@ void KMain(uint3 dispatchThreadId : SV_DispatchThreadID)
_CameraColorTextureRW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(_AccumulatedFrameTexture[COORD_TEXTURE2D_X(currentPixelCoord)].xyz * exposureMultiplier, 1.0);
}
else
{
{
#ifdef INPUT_FROM_RADIANCE_TEXTURE
float4 color = _RadianceTexture[COORD_TEXTURE2D_X(dispatchThreadId.xy)];
#else
float4 color = _CameraColorTextureRW[COORD_TEXTURE2D_X(dispatchThreadId.xy)];
#endif

if (sampleCount++)
color.xyz = (_AccumulatedFrameTexture[COORD_TEXTURE2D_X(currentPixelCoord)].xyz * _AccumulationWeights.y + _AccumulationWeights.x * color.xyz) * _AccumulationWeights.z;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ struct RenderAccumulationParameters
public HDCamera hdCamera;
}

RenderAccumulationParameters PrepareRenderAccumulationParameters(HDCamera hdCamera, bool needExposure)
RenderAccumulationParameters PrepareRenderAccumulationParameters(HDCamera hdCamera, bool needExposure, bool inputFromRadianceTexture)
{
var parameters = new RenderAccumulationParameters();

Expand All @@ -301,6 +301,11 @@ RenderAccumulationParameters PrepareRenderAccumulationParameters(HDCamera hdCame
parameters.needExposure = needExposure;
parameters.hdCamera = hdCamera;

parameters.accumulationCS.shaderKeywords = null;
if (inputFromRadianceTexture)
{
parameters.accumulationCS.EnableKeyword("INPUT_FROM_RADIANCE_TEXTURE");
}
return parameters;
}

Expand All @@ -310,7 +315,8 @@ void RenderAccumulation(HDCamera hdCamera, RTHandle inputTexture, RTHandle outpu
RTHandle history = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.PathTracing)
?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.PathTracing, PathTracingHistoryBufferAllocatorFunction, 1);

var parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure);
bool inputFromRadianceTexture = !inputTexture.Equals(outputTexture);
var parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure, inputFromRadianceTexture);
RenderAccumulation(parameters, inputTexture, outputTexture, history, cmd);
}

Expand All @@ -332,7 +338,10 @@ static void RenderAccumulation(in RenderAccumulationParameters parameters, RTHan
cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationNumSamples, (int)parameters.subFrameManager.subFrameCount);
cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._AccumulatedFrameTexture, historyTexture);
cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._CameraColorTextureRW, outputTexture);
cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._RadianceTexture, inputTexture);
if (!inputTexture.Equals(outputTexture))
{
cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._RadianceTexture, inputTexture);
}
cmd.SetComputeVectorParam(accumulationShader, HDShaderIDs._AccumulationWeights, frameWeights);
cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationNeedsExposure, parameters.needExposure ? 1 : 0);
cmd.DispatchCompute(accumulationShader, parameters.accumulationKernel, (parameters.hdCamera.actualWidth + 7) / 8, (parameters.hdCamera.actualHeight + 7) / 8, parameters.hdCamera.viewCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,8 @@ void RenderAccumulation(RenderGraph renderGraph, HDCamera hdCamera, TextureHandl
TextureHandle history = renderGraph.ImportTexture(hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.PathTracing)
?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.PathTracing, PathTracingHistoryBufferAllocatorFunction, 1));

passData.parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure);
bool inputFromRadianceTexture = !inputTexture.Equals(outputTexture);
passData.parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure, inputFromRadianceTexture);
passData.input = builder.ReadTexture(inputTexture);
passData.output = builder.WriteTexture(outputTexture);
passData.history = builder.WriteTexture(history);
Expand Down