Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -506,6 +506,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fix for issue that prevented scene from being completely saved when baked reflection probes are present and lighting is set to auto generate.
- Fixed drag area width at left of Light's intensity field in Inspector.
- Fixed light type resolution when performing a reset on HDAdditionalLightData (case 1220931)
- 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