Skip to content

Fix MSAA resolve when there is no motion vectors #1

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
Apr 14, 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 @@ -525,6 +525,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fix reflection hierarchy for CARPAINT in AxF.
- Fix precise fresnel for delta lights for SVBRDF in AxF.
- Fixed the debug exposure mode for display sky reflection and debug view baked lighting
- Fixed MSAA depth resolve when there is no motion vectors

### Changed
- Color buffer pyramid is not allocated anymore if neither refraction nor distortion are enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public void InitSharedBuffers(GBufferManager gbufferManager, RenderPipelineSetti
// Create the required resolve materials
m_DepthResolveMaterial = CoreUtils.CreateEngineMaterial(resources.shaders.depthValuesPS);
m_ColorResolveMaterial = CoreUtils.CreateEngineMaterial(resources.shaders.colorResolvePS);

CoreUtils.SetKeyword(m_DepthResolveMaterial, "_HAS_MOTION_VECTORS", m_MotionVectorsSupport);
}

AllocateCoarseStencilBuffer(RTHandles.maxWidth, RTHandles.maxHeight, TextureXR.slices);
Expand Down Expand Up @@ -342,18 +344,30 @@ public void ResolveSharedRT(CommandBuffer cmd, HDCamera hdCamera)
Debug.Assert(m_MSAASupported);
using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.ResolveMSAADepth)))
{
// Grab the RTIs and set the output render targets
m_RTIDs3[0] = m_CameraDepthValuesBuffer.nameID;
m_RTIDs3[1] = m_NormalRT.nameID;
m_RTIDs3[2] = m_MotionVectorsRT.nameID;
CoreUtils.SetRenderTarget(cmd, m_RTIDs3, m_CameraDepthStencilBuffer);

// Set the input textures
if (m_MotionVectorsSupport)
{
// Grab the RTIs and set the output render targets
m_RTIDs3[0] = m_CameraDepthValuesBuffer.nameID;
m_RTIDs3[1] = m_NormalRT.nameID;
m_RTIDs3[2] = m_MotionVectorsRT.nameID;
CoreUtils.SetRenderTarget(cmd, m_RTIDs3, m_CameraDepthStencilBuffer);

// Set the motion vector input texture
Shader.SetGlobalTexture(HDShaderIDs._MotionVectorTextureMS, m_MotionVectorsMSAART);
}
else
{
// Grab the RTIs and set the output render targets
m_RTIDs2[0] = m_CameraDepthValuesBuffer.nameID;
m_RTIDs2[1] = m_NormalRT.nameID;
CoreUtils.SetRenderTarget(cmd, m_RTIDs2, m_CameraDepthStencilBuffer);
}

// Set the depth and normal input textures
Shader.SetGlobalTexture(HDShaderIDs._NormalTextureMS, m_NormalMSAART);
Shader.SetGlobalTexture(HDShaderIDs._DepthTextureMS, m_DepthAsColorMSAART);
Shader.SetGlobalTexture(HDShaderIDs._MotionVectorTextureMS, m_MotionVectorsMSAART);

// Resolve the depth and normal buffers
// Resolve the buffers
cmd.DrawProcedural(Matrix4x4.identity, m_DepthResolveMaterial, SampleCountToPassIndex(m_MSAASamples), MeshTopology.Triangles, 3, 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ Shader "Hidden/HDRP/DepthValues"
HLSLINCLUDE
#pragma target 4.5
#pragma only_renderers d3d11 playstation xboxone vulkan metal switch
#pragma multi_compile _ _HAS_MOTION_VECTORS

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
// #pragma enable_d3d11_debug_symbols

// Target multisampling textures
TEXTURE2D_X_MSAA(float, _DepthTextureMS);
TEXTURE2D_X_MSAA(float4, _NormalTextureMS);
#ifdef _HAS_MOTION_VECTORS
TEXTURE2D_X_MSAA(float2, _MotionVectorTextureMS);
#endif

struct Attributes
{
Expand All @@ -29,7 +33,9 @@ Shader "Hidden/HDRP/DepthValues"
{
float4 depthValues : SV_Target0;
float4 normal : SV_Target1;
#ifdef _HAS_MOTION_VECTORS
float2 motionVectors : SV_Target2;
#endif
float actualDepth : SV_Depth;
};

Expand All @@ -51,7 +57,9 @@ Shader "Hidden/HDRP/DepthValues"
float depthVal = LOAD_TEXTURE2D_X_MSAA(_DepthTextureMS, pixelCoords, 0).x;
fragO.depthValues = float4(depthVal, depthVal, depthVal, 0.0f);
fragO.normal = LOAD_TEXTURE2D_X_MSAA(_NormalTextureMS, pixelCoords, 0);
#ifdef _HAS_MOTION_VECTORS
fragO.motionVectors = LOAD_TEXTURE2D_X_MSAA(_MotionVectorTextureMS, pixelCoords, 0);
#endif
fragO.actualDepth = fragO.depthValues.x;
return fragO;
}
Expand All @@ -77,8 +85,10 @@ Shader "Hidden/HDRP/DepthValues"
fragO.depthValues.z *= 0.5;
fragO.actualDepth = fragO.depthValues.x;
fragO.normal = LOAD_TEXTURE2D_X_MSAA(_NormalTextureMS, pixelCoords, 0);
#ifdef _HAS_MOTION_VECTORS
// We pick the closest sample to camera, not really a great solution, but resolving motion vectors is ill defined.
fragO.motionVectors = LOAD_TEXTURE2D_X_MSAA(_MotionVectorTextureMS, pixelCoords, closestSample);
#endif
return fragO;
}

Expand All @@ -103,8 +113,10 @@ Shader "Hidden/HDRP/DepthValues"
fragO.depthValues.z *= 0.25;
fragO.actualDepth = fragO.depthValues.x;
fragO.normal = LOAD_TEXTURE2D_X_MSAA(_NormalTextureMS, pixelCoords, 0);
#ifdef _HAS_MOTION_VECTORS
// We pick the closest sample to camera, not really a great solution, but resolving motion vectors is ill defined.
fragO.motionVectors = LOAD_TEXTURE2D_X_MSAA(_MotionVectorTextureMS, pixelCoords, closestSample);
#endif
return fragO;
}

Expand All @@ -129,8 +141,10 @@ Shader "Hidden/HDRP/DepthValues"
fragO.depthValues.z *= 0.125;
fragO.actualDepth = fragO.depthValues.x;
fragO.normal = LOAD_TEXTURE2D_X_MSAA(_NormalTextureMS, pixelCoords, 0);
#ifdef _HAS_MOTION_VECTORS
// We pick the closest sample to camera, not really a great solution, but resolving motion vectors is ill defined.
fragO.motionVectors = LOAD_TEXTURE2D_X_MSAA(_MotionVectorTextureMS, pixelCoords, closestSample);
#endif
return fragO;
}
ENDHLSL
Expand Down