Skip to content

[2021.2][RenderPass] Depth, Normals, Decals fixes #6354

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 12 commits into from
Feb 18, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@
#define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2)
#define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2)

#if defined(SHADER_API_MOBILE)
#if defined(UNITY_FRAMEBUFFER_FETCH_AVAILABLE)
#define PLATFORM_SUPPORTS_NATIVE_RENDERPASS
#endif
1 change: 1 addition & 0 deletions com.unity.render-pipelines.universal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed a regression where filtering the scene view yielded incorrect visual results [case 1360233](https://issuetracker.unity3d.com/product/unity/issues/guid/1360233)
- VFX: Incorrect Decal rendering when rendescale is different than one [case 1343674](https://issuetracker.unity3d.com/product/unity/issues/guid/1343674/)
- Fixed decal compilation issue on mac.
- Fixed several Native RenderPass issues regarding input attachments, DepthOnly pass, Decals.
- Fixed incorrect lighting attenuation on Editor when build target is a mobile platform [case 1387142]

## [12.1.3] - 2021-11-17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal class DecalGBufferRenderPass : ScriptableRenderPass
private DecalDrawGBufferSystem m_DrawSystem;
private DecalScreenSpaceSettings m_Settings;
private DeferredLights m_DeferredLights;
private RenderTargetIdentifier[] m_GbufferAttachments;

public DecalGBufferRenderPass(DecalScreenSpaceSettings settings, DecalDrawGBufferSystem drawSystem)
{
Expand All @@ -41,7 +42,19 @@ internal void Setup(DeferredLights deferredLights)

public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
ConfigureTarget(m_DeferredLights.GbufferAttachmentIdentifiers, m_DeferredLights.DepthAttachmentIdentifier);
if (m_DeferredLights != null && m_DeferredLights.UseRenderPass)
{
if (m_GbufferAttachments == null)
m_GbufferAttachments = new RenderTargetIdentifier[]
{
m_DeferredLights.GbufferAttachmentIdentifiers[0], m_DeferredLights.GbufferAttachmentIdentifiers[1],
m_DeferredLights.GbufferAttachmentIdentifiers[2], m_DeferredLights.GbufferAttachmentIdentifiers[3]
};
}
else
m_GbufferAttachments = m_DeferredLights.GbufferAttachmentIdentifiers;

ConfigureTarget(m_GbufferAttachments, m_DeferredLights.DepthAttachmentIdentifier);
}

public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ internal bool AccurateGbufferNormals
// Output lighting result.
internal RenderTargetHandle[] GbufferAttachments { get; set; }
internal RenderTargetIdentifier[] DeferredInputAttachments { get; set; }
internal bool[] DeferredInputIsTransient { get; set; }
// Input depth texture, also bound as read-only RT
internal RenderTargetHandle DepthAttachment { get; set; }
//
Expand Down Expand Up @@ -824,6 +825,10 @@ public void Setup(ref RenderingData renderingData,
this.GbufferAttachmentIdentifiers[0], this.GbufferAttachmentIdentifiers[1],
this.GbufferAttachmentIdentifiers[2], this.GbufferAttachmentIdentifiers[4]
};
this.DeferredInputIsTransient = new bool[4]
{
true, true, true, false
};
}
this.DepthAttachmentIdentifier = depthAttachment.Identifier();
#if ENABLE_VR && ENABLE_XR_MODULE
Expand Down
34 changes: 29 additions & 5 deletions com.unity.render-pipelines.universal/Runtime/NativeRenderPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public partial class ScriptableRenderer
};
AttachmentDescriptor m_ActiveDepthAttachmentDescriptor;

bool[] m_IsActiveColorAttachmentTransient = new bool[]
{
false, false, false, false, false, false, false, false
};

internal RenderBufferStoreAction[] m_FinalColorStoreAction = new RenderBufferStoreAction[]
{
RenderBufferStoreAction.Store, RenderBufferStoreAction.Store, RenderBufferStoreAction.Store, RenderBufferStoreAction.Store,
Expand Down Expand Up @@ -200,6 +205,7 @@ internal void SetNativeRenderPassMRTAttachmentList(ScriptableRenderPass renderPa
UpdateFinalStoreActions(currentMergeablePasses, cameraData);

int currentAttachmentIdx = 0;
bool hasInput = false;
foreach (var passIdx in currentMergeablePasses)
{
if (passIdx == -1)
Expand Down Expand Up @@ -248,7 +254,10 @@ internal void SetNativeRenderPassMRTAttachmentList(ScriptableRenderPass renderPa
}

if (PassHasInputAttachments(pass))
{
hasInput = true;
SetupInputAttachmentIndices(pass);
}

// TODO: this is redundant and is being setup for each attachment. Needs to be done only once per mergeable pass list (we need to make sure mergeable passes use the same depth!)
m_ActiveDepthAttachmentDescriptor = new AttachmentDescriptor(SystemInfo.GetGraphicsFormat(DefaultFormat.DepthStencil));
Expand All @@ -260,6 +269,8 @@ internal void SetNativeRenderPassMRTAttachmentList(ScriptableRenderPass renderPa
if (m_UseOptimizedStoreActions)
m_ActiveDepthAttachmentDescriptor.storeAction = m_FinalDepthStoreAction;
}
if (hasInput)
SetupTransientInputAttachments(m_RenderPassesAttachmentCount[currentPassHash]);
}
}

Expand Down Expand Up @@ -504,6 +515,7 @@ internal void ExecuteNativeRenderPass(ScriptableRenderContext context, Scriptabl
for (int i = 0; i < m_ActiveColorAttachmentDescriptors.Length; ++i)
{
m_ActiveColorAttachmentDescriptors[i] = RenderingUtils.emptyAttachment;
m_IsActiveColorAttachmentTransient[i] = false;
}

m_ActiveDepthAttachmentDescriptor = RenderingUtils.emptyAttachment;
Expand All @@ -523,11 +535,23 @@ internal void SetupInputAttachmentIndices(ScriptableRenderPass pass)
continue;
}

// Assume input attachment has to be transient as ScriptableRenderPass currently has only setters for StoreAction
// We also change the target of the descriptor for it to be initialized engine-side as a transient resource.
m_ActiveColorAttachmentDescriptors[pass.m_InputAttachmentIndices[i]].loadAction = RenderBufferLoadAction.DontCare;
m_ActiveColorAttachmentDescriptors[pass.m_InputAttachmentIndices[i]].storeAction = RenderBufferStoreAction.DontCare;
m_ActiveColorAttachmentDescriptors[pass.m_InputAttachmentIndices[i]].loadStoreTarget = BuiltinRenderTextureType.None;
// Only update it as long as it has default value - if it was changed once, we assume it'll be memoryless in the whole RenderPass
if (!m_IsActiveColorAttachmentTransient[pass.m_InputAttachmentIndices[i]])
m_IsActiveColorAttachmentTransient[pass.m_InputAttachmentIndices[i]] = pass.IsInputAttachmentTransient(i);
}
}

internal void SetupTransientInputAttachments(int attachmentCount)
{
for (int i = 0; i < attachmentCount; ++i)
{
if (!m_IsActiveColorAttachmentTransient[i])
continue;

m_ActiveColorAttachmentDescriptors[i].loadAction = RenderBufferLoadAction.DontCare;
m_ActiveColorAttachmentDescriptors[i].storeAction = RenderBufferStoreAction.DontCare;
// We change the target of the descriptor for it to be initialized engine-side as a transient resource.
m_ActiveColorAttachmentDescriptors[i].loadStoreTarget = BuiltinRenderTextureType.None;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override void Configure(CommandBuffer cmd, RenderTextureDescriptor camera
RenderTargetIdentifier lightingAttachmentId = m_DeferredLights.GbufferAttachmentIdentifiers[m_DeferredLights.GBufferLightingIndex];
RenderTargetIdentifier depthAttachmentId = m_DeferredLights.DepthAttachmentIdentifier;
if (m_DeferredLights.UseRenderPass)
ConfigureInputAttachments(m_DeferredLights.DeferredInputAttachments);
ConfigureInputAttachments(m_DeferredLights.DeferredInputAttachments, m_DeferredLights.DeferredInputIsTransient);

// TODO: change to m_DeferredLights.GetGBufferFormat(m_DeferredLights.GBufferLightingIndex) when it's not GraphicsFormat.None
// TODO: Cannot currently bind depth texture as read-only!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public DepthOnlyPass(RenderPassEvent evt, RenderQueueRange renderQueueRange, Lay
base.profilingSampler = new ProfilingSampler(nameof(DepthOnlyPass));
m_FilteringSettings = new FilteringSettings(renderQueueRange, layerMask);
renderPassEvent = evt;
useNativeRenderPass = false;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ public override void Configure(CommandBuffer cmd, RenderTextureDescriptor camera
// Normal buffer may have already been created if there was a depthNormal prepass before.
// DepthNormal prepass is needed for forward-only materials when SSAO is generated between gbuffer and deferred lighting pass.
if (i == m_DeferredLights.GBufferNormalSmoothnessIndex && m_DeferredLights.HasNormalPrepass)
{
if (m_DeferredLights.UseRenderPass)
m_DeferredLights.DeferredInputIsTransient[i] = false;
continue;
}

// No need to setup temporaryRTs if we are using input attachments as they will be Memoryless
if (m_DeferredLights.UseRenderPass && i != m_DeferredLights.GBufferShadowMask && i != m_DeferredLights.GBufferRenderingLayers)
if (m_DeferredLights.UseRenderPass && i != m_DeferredLights.GBufferShadowMask && i != m_DeferredLights.GBufferRenderingLayers && (i != m_DeferredLights.GbufferDepthIndex && !m_DeferredLights.HasDepthPrepass))
continue;

RenderTextureDescriptor gbufferSlice = cameraTextureDescriptor;
Expand Down Expand Up @@ -124,9 +128,7 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
RenderingUtils.RenderObjectsWithError(context, ref renderingData.cullResults, camera, m_FilteringSettings, SortingCriteria.None);

// If any sub-system needs camera normal texture, make it available.
// Input attachments will only be used when this is not needed so safe to skip in that case
if (!m_DeferredLights.UseRenderPass)
gbufferCommands.SetGlobalTexture(s_CameraNormalsTextureID, m_DeferredLights.GbufferAttachmentIdentifiers[m_DeferredLights.GBufferNormalSmoothnessIndex]);
gbufferCommands.SetGlobalTexture(s_CameraNormalsTextureID, m_DeferredLights.GbufferAttachmentIdentifiers[m_DeferredLights.GBufferNormalSmoothnessIndex]);
}

context.ExecuteCommandBuffer(gbufferCommands);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ public Color clearColor
internal GraphicsFormat[] renderTargetFormat { get; set; }
RenderTargetIdentifier[] m_ColorAttachments = new RenderTargetIdentifier[] { BuiltinRenderTextureType.CameraTarget };
internal RenderTargetIdentifier[] m_InputAttachments = new RenderTargetIdentifier[8];
internal bool[] m_InputAttachmentIsTransient = new bool[8];
RenderTargetIdentifier m_DepthAttachment = BuiltinRenderTextureType.CameraTarget;
ScriptableRenderPassInput m_Input = ScriptableRenderPassInput.None;
ClearFlag m_ClearFlag = ClearFlag.None;
Expand All @@ -245,6 +246,7 @@ public ScriptableRenderPass()
renderPassEvent = RenderPassEvent.AfterRenderingOpaques;
m_ColorAttachments = new RenderTargetIdentifier[] { BuiltinRenderTextureType.CameraTarget, 0, 0, 0, 0, 0, 0, 0 };
m_InputAttachments = new RenderTargetIdentifier[] { -1, -1, -1, -1, -1, -1, -1, -1 };
m_InputAttachmentIsTransient = new bool[] { false, false, false, false, false, false, false, false };
m_DepthAttachment = BuiltinRenderTextureType.CameraTarget;
m_ColorStoreActions = new RenderBufferStoreAction[] { RenderBufferStoreAction.Store, 0, 0, 0, 0, 0, 0, 0 };
m_DepthStoreAction = RenderBufferStoreAction.Store;
Expand Down Expand Up @@ -314,16 +316,32 @@ public void ConfigureDepthStoreAction(RenderBufferStoreAction storeAction)
m_OverriddenDepthStoreAction = true;
}

internal void ConfigureInputAttachments(RenderTargetIdentifier input)
internal void ConfigureInputAttachments(RenderTargetIdentifier input, bool isTransient = false)
{
m_InputAttachments[0] = input;
m_InputAttachmentIsTransient[0] = isTransient;
}

internal void ConfigureInputAttachments(RenderTargetIdentifier[] inputs)
{
m_InputAttachments = inputs;
}

internal void ConfigureInputAttachments(RenderTargetIdentifier[] inputs, bool[] isTransient)
{
ConfigureInputAttachments(inputs);
m_InputAttachmentIsTransient = isTransient;
}

internal void SetInputAttachmentTransient(int idx, bool isTransient)
{
m_InputAttachmentIsTransient[idx] = isTransient;
}

internal bool IsInputAttachmentTransient(int idx)
{
return m_InputAttachmentIsTransient[idx];
}
/// <summary>
/// Configures render targets for this render pass. Call this instead of CommandBuffer.SetRenderTarget.
/// This method should be called inside Configure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,10 @@ private void RecreateSystemsIfNeeded(ScriptableRenderer renderer, in CameraData
m_ForwardEmissivePass = new DecalForwardEmissivePass(m_DecalDrawForwardEmissiveSystem);

if (universalRenderer.actualRenderingMode == RenderingMode.Deferred)
{
m_DBufferRenderPass.deferredLights = universalRenderer.deferredLights;
m_DBufferRenderPass.deferredLights.DisableFramebufferFetchInput();
}
break;
}

Expand Down Expand Up @@ -479,6 +482,10 @@ public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingD
}
}

internal override bool SupportsNativeRenderPass()
{
return m_Technique == DecalTechnique.GBuffer || m_Technique == DecalTechnique.ScreenSpace;
}
protected override void Dispose(bool disposing)
{
CoreUtils.Destroy(m_CopyDepthMaterial);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,14 @@ protected void AddRenderPasses(ref RenderingData renderingData)
{
using var profScope = new ProfilingScope(null, Profiling.addRenderPasses);

// Disable Native RenderPass for any passes that were directly injected prior to our passes and renderer features
int count = activeRenderPassQueue.Count;
for (int i = 0; i < count; i++)
{
if (activeRenderPassQueue[i] != null)
activeRenderPassQueue[i].useNativeRenderPass = false;
}

// Add render passes from custom renderer features
for (int i = 0; i < rendererFeatures.Count; ++i)
{
Expand All @@ -868,7 +876,7 @@ protected void AddRenderPasses(ref RenderingData renderingData)
}

// Remove any null render pass that might have been added by user by mistake
int count = activeRenderPassQueue.Count;
count = activeRenderPassQueue.Count;
for (int i = count - 1; i >= 0; i--)
{
if (activeRenderPassQueue[i] == null)
Expand Down