Skip to content

Fix order of render targets in shaderpass forward #6091

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
Nov 8, 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 @@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed outdated documentation about recursie ray tracing effects support (case 1374904).
- Fixed Shadow Matte not appearing in ray tracing effects (case 1364005).
- Fixed Crash issue when adding an area light on its own.
- Fixed rendertarget ColorMask in Forward with virtual texturing and transparent motion vectors.

### Changed
- Use RayTracingAccelerationStructure.CullInstances to filter Renderers and populate the acceleration structure with ray tracing instances for improved CPU performance on the main thread.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,8 @@ public static class Uniforms
{ RenderState.Cull(Cull.Front) },
{ RenderState.ZWrite(Uniforms.zWrite) },
{ RenderState.ZTest(Uniforms.zTestTransparent) },
{ RenderState.ColorMask("ColorMask [_ColorMaskTransparentVel] 1") },
{ RenderState.ColorMask("ColorMask [_ColorMaskTransparentVelOne] 1") },
{ RenderState.ColorMask("ColorMask [_ColorMaskTransparentVelTwo] 2") },
};


Expand Down Expand Up @@ -793,7 +794,8 @@ public static class Uniforms
{ RenderState.Cull(Uniforms.cullModeForward) },
{ RenderState.ZWrite(Uniforms.zWrite) },
{ RenderState.ZTest(Uniforms.zTestDepthEqualForOpaque) },
{ RenderState.ColorMask("ColorMask [_ColorMaskTransparentVel] 1") },
{ RenderState.ColorMask("ColorMask [_ColorMaskTransparentVelOne] 1") },
{ RenderState.ColorMask("ColorMask [_ColorMaskTransparentVelTwo] 2") },
{ RenderState.Stencil(new StencilDescriptor()
{
WriteMask = Uniforms.stencilWriteMask,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ Shader "HDRP/AxF"
ZTest [_ZTestDepthEqualForOpaque]
ZWrite [_ZWrite]
Cull [_CullModeForward]
ColorMask [_ColorMaskTransparentVel] 1
ColorMask [_ColorMaskTransparentVelOne] 1
ColorMask [_ColorMaskTransparentVelTwo] 2

HLSLPROGRAM

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,8 @@ Shader "HDRP/Lit"
Blend [_SrcBlend] [_DstBlend], [_AlphaSrcBlend] [_AlphaDstBlend]
ZWrite [_ZWrite]
Cull Front
ColorMask [_ColorMaskTransparentVel] 1
ColorMask [_ColorMaskTransparentVelOne] 1
ColorMask [_ColorMaskTransparentVelTwo] 2
ZTest [_ZTestTransparent]

HLSLPROGRAM
Expand Down Expand Up @@ -833,7 +834,10 @@ Shader "HDRP/Lit"
ZTest [_ZTestDepthEqualForOpaque]
ZWrite [_ZWrite]
Cull [_CullModeForward]
ColorMask [_ColorMaskTransparentVel] 1
// Not possible to control the render target with a variable
// Depending on virtual texturing, motion vector buffer can be bound on either SV_Target1 or SV_Target2
ColorMask [_ColorMaskTransparentVelOne] 1
ColorMask [_ColorMaskTransparentVelTwo] 2

HLSLPROGRAM

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,8 @@ Shader "HDRP/LitTessellation"
Blend [_SrcBlend] [_DstBlend], [_AlphaSrcBlend] [_AlphaDstBlend]
ZWrite [_ZWrite]
Cull Front
ColorMask[_ColorMaskTransparentVel] 1
ColorMask [_ColorMaskTransparentVelOne] 1
ColorMask [_ColorMaskTransparentVelTwo] 2
ZTest[_ZTestTransparent]

HLSLPROGRAM
Expand Down Expand Up @@ -866,7 +867,8 @@ Shader "HDRP/LitTessellation"
ZTest [_ZTestDepthEqualForOpaque]
ZWrite [_ZWrite]
Cull [_CullModeForward]
ColorMask[_ColorMaskTransparentVel] 1
ColorMask [_ColorMaskTransparentVelOne] 1
ColorMask [_ColorMaskTransparentVelTwo] 2

HLSLPROGRAM

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,7 @@ void DecodeFromSSSBuffer(uint2 positionSS, out SSSData sssData)
DecodeFromSSSBuffer(sssBuffer, positionSS, sssData);
}

// OUTPUT_SSSBUFFER start from SV_Target2 as SV_Target0 and SV_Target1 are used for lighting buffer, shifts to SV_Target3 if VT is enabled
#ifdef UNITY_VIRTUAL_TEXTURING
#define OUTPUT_SSSBUFFER(NAME) out SSSBufferType0 MERGE_NAME(NAME, 0) : SV_Target3
#else
#define OUTPUT_SSSBUFFER(NAME) out SSSBufferType0 MERGE_NAME(NAME, 0) : SV_Target2
#endif
#define OUTPUT_SSSBUFFER(NAME) out SSSBufferType0 MERGE_NAME(NAME, 0)

#define ENCODE_INTO_SSSBUFFER(SURFACE_DATA, UNPOSITIONSS, NAME) EncodeIntoSSSBuffer(ConvertSurfaceDataToSSSData(SURFACE_DATA), UNPOSITIONSS, MERGE_NAME(NAME, 0))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public partial class HDRenderPipeline
internal bool m_ShouldOverrideColorBufferFormat = false;
GraphicsFormat m_AOVGraphicsFormat = GraphicsFormat.None;

// Property used for transparent motion vector color mask - depends on presence of virtual texturing or not
int colorMaskTransparentVel;
int colorMaskAdditionalTarget;

void RecordRenderGraph(RenderRequest renderRequest,
AOVRequestData aovRequest,
List<RTHandle> aovBuffers,
Expand Down Expand Up @@ -674,6 +678,7 @@ class ForwardTransparentPassData : ForwardPassData
{
public bool decalsEnabled;
public bool renderMotionVecForTransparent;
public int colorMaskTransparentVel;
public TextureHandle transparentSSRLighting;
public TextureHandle volumetricLighting;
public TextureHandle depthPyramidTexture;
Expand Down Expand Up @@ -1005,6 +1010,7 @@ void RenderForwardTransparent(RenderGraph renderGraph,
// decal datas count is 0 if no decals affect transparency
passData.decalsEnabled = (hdCamera.frameSettings.IsEnabled(FrameSettingsField.Decals)) && (DecalSystem.m_DecalDatasCount > 0);
passData.renderMotionVecForTransparent = NeedMotionVectorForTransparent(hdCamera.frameSettings);
passData.colorMaskTransparentVel = colorMaskTransparentVel;
passData.volumetricLighting = builder.ReadTexture(volumetricLighting);
passData.transparentSSRLighting = builder.ReadTexture(ssrLighting);
passData.depthPyramidTexture = builder.ReadTexture(prepassOutput.depthPyramidTexture); // We need to bind this for transparent materials doing stuff like soft particles etc.
Expand Down Expand Up @@ -1046,7 +1052,7 @@ void RenderForwardTransparent(RenderGraph renderGraph,
(ForwardTransparentPassData data, RenderGraphContext context) =>
{
// Bind all global data/parameters for transparent forward pass
context.cmd.SetGlobalInt(HDShaderIDs._ColorMaskTransparentVel, data.renderMotionVecForTransparent ? (int)ColorWriteMask.All : 0);
context.cmd.SetGlobalInt(data.colorMaskTransparentVel, data.renderMotionVecForTransparent ? (int)ColorWriteMask.All : 0);
if (data.decalsEnabled)
DecalSystem.instance.SetAtlas(context.cmd); // for clustered decals

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ public HDRenderPipeline(HDRenderPipelineAsset asset)
}

VirtualTexturing.Streaming.SetGPUCacheSettings(gpuCacheSettings);

colorMaskTransparentVel = HDShaderIDs._ColorMaskTransparentVelTwo;
colorMaskAdditionalTarget = HDShaderIDs._ColorMaskTransparentVelOne;
#else
colorMaskTransparentVel = HDShaderIDs._ColorMaskTransparentVelOne;
colorMaskAdditionalTarget = HDShaderIDs._ColorMaskTransparentVelTwo;
#endif

// Initial state of the RTHandle system.
Expand Down Expand Up @@ -869,7 +875,8 @@ void UpdateGlobalConstantBuffers(HDCamera hdCamera, CommandBuffer cmd)
UpdateShaderVariablesRaytracingCB(hdCamera, cmd);

// This one is not in a constant buffer because it's only used as a parameter for some shader's render states. It's not actually used inside shader code.
cmd.SetGlobalInt(HDShaderIDs._ColorMaskTransparentVel, (int)ColorWriteMask.All);
cmd.SetGlobalInt(colorMaskTransparentVel, (int)ColorWriteMask.All);
cmd.SetGlobalInt(colorMaskAdditionalTarget, (int)ColorWriteMask.All);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ static class HDShaderIDs
public static readonly int _SrcBlend = Shader.PropertyToID("_SrcBlend");
public static readonly int _DstBlend = Shader.PropertyToID("_DstBlend");

public static readonly int _ColorMaskTransparentVel = Shader.PropertyToID("_ColorMaskTransparentVel");
public static readonly int _ColorMaskTransparentVelOne = Shader.PropertyToID("_ColorMaskTransparentVelOne");
public static readonly int _ColorMaskTransparentVelTwo = Shader.PropertyToID("_ColorMaskTransparentVelTwo");
public static readonly int _DecalColorMask0 = Shader.PropertyToID(HDMaterialProperties.kDecalColorMask0);
public static readonly int _DecalColorMask1 = Shader.PropertyToID(HDMaterialProperties.kDecalColorMask1);
public static readonly int _DecalColorMask2 = Shader.PropertyToID(HDMaterialProperties.kDecalColorMask2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,32 +77,35 @@ PackedVaryingsToPS VertTesselation(VaryingsToDS input)
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplayMaterial.hlsl"

#ifdef UNITY_VIRTUAL_TEXTURING
#define VT_BUFFER_TARGET SV_Target1
#define EXTRA_BUFFER_TARGET SV_Target2
#ifdef OUTPUT_SPLIT_LIGHTING
#define DIFFUSE_LIGHTING_TARGET SV_Target2
#define SSS_BUFFER_TARGET SV_Target3
#elif defined(_WRITE_TRANSPARENT_MOTION_VECTOR)
#define MOTION_VECTOR_TARGET SV_Target2
#endif
#else
#define EXTRA_BUFFER_TARGET SV_Target1
#ifdef OUTPUT_SPLIT_LIGHTING
#define DIFFUSE_LIGHTING_TARGET SV_Target1
#define SSS_BUFFER_TARGET SV_Target2
#elif defined(_WRITE_TRANSPARENT_MOTION_VECTOR)
#define MOTION_VECTOR_TARGET SV_Target1
#endif
#endif

void Frag(PackedVaryingsToPS packedInput,
#ifdef OUTPUT_SPLIT_LIGHTING
out float4 outColor : SV_Target0, // outSpecularLighting
#ifdef UNITY_VIRTUAL_TEXTURING
out float4 outVTFeedback : VT_BUFFER_TARGET,
#endif
out float4 outDiffuseLighting : EXTRA_BUFFER_TARGET,
OUTPUT_SSSBUFFER(outSSSBuffer)
#else
out float4 outColor : SV_Target0
#ifdef UNITY_VIRTUAL_TEXTURING
,out float4 outVTFeedback : VT_BUFFER_TARGET
#endif
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
, out float4 outMotionVec : EXTRA_BUFFER_TARGET
#endif // _WRITE_TRANSPARENT_MOTION_VECTOR
#endif // OUTPUT_SPLIT_LIGHTING
#ifdef _DEPTHOFFSET_ON
, out float outputDepth : DEPTH_OFFSET_SEMANTIC
#endif
void Frag(PackedVaryingsToPS packedInput
, out float4 outColor : SV_Target0 // outSpecularLighting when outputting split lighting
#ifdef UNITY_VIRTUAL_TEXTURING
, out float4 outVTFeedback : SV_Target1
#endif
#ifdef OUTPUT_SPLIT_LIGHTING
, out float4 outDiffuseLighting : DIFFUSE_LIGHTING_TARGET
, OUTPUT_SSSBUFFER(outSSSBuffer) : SSS_BUFFER_TARGET
#elif defined(_WRITE_TRANSPARENT_MOTION_VECTOR)
, out float4 outMotionVec : MOTION_VECTOR_TARGET
#endif
#ifdef _DEPTHOFFSET_ON
, out float outputDepth : DEPTH_OFFSET_SEMANTIC
#endif
)
{
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
Expand Down