Skip to content
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.universal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed wrong shader / properties assignement to materials created from 3DsMax 2021 Physical Material. (case 1293576)
- Normalized the view direction in Shader Graph to be consistent across Scriptable Render Pieplines.
- Fixed material upgrader to run in batch mode [case 1305402]
- Fixed gizmos drawing in game view. [case 1302504](https://issuetracker.unity3d.com/issues/urp-handles-with-set-ztest-do-not-respect-depth-sorting-in-the-game-view)
- Fixed an issue in shaderGraph target where the ShaderPass.hlsl was being included after SHADERPASS was defined
- Fixed an issue where Particle Lit shader had an incorrect fallback shader [case 1312459]
- Fixed an issue with backbuffer MSAA on Vulkan desktop platforms.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class CopyDepthPass : ScriptableRenderPass
private RenderTargetHandle source { get; set; }
private RenderTargetHandle destination { get; set; }
internal bool AllocateRT { get; set; }
internal int MssaSamples { get; set; }
Material m_CopyDepthMaterial;
public CopyDepthPass(RenderPassEvent evt, Material copyDepthMaterial)
{
Expand All @@ -35,6 +36,7 @@ public void Setup(RenderTargetHandle source, RenderTargetHandle destination)
this.source = source;
this.destination = destination;
this.AllocateRT = !destination.HasInternalRenderTargetId();
this.MssaSamples = -1;
}

public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
Expand Down Expand Up @@ -62,8 +64,15 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
CommandBuffer cmd = CommandBufferPool.Get();
using (new ProfilingScope(cmd, ProfilingSampler.Get(URPProfileId.CopyDepth)))
{
RenderTextureDescriptor descriptor = renderingData.cameraData.cameraTargetDescriptor;
int cameraSamples = descriptor.msaaSamples;
int cameraSamples = 0;

if (MssaSamples == -1)
{
RenderTextureDescriptor descriptor = renderingData.cameraData.cameraTargetDescriptor;
cameraSamples = descriptor.msaaSamples;
}
else
cameraSamples = MssaSamples;

CameraData cameraData = renderingData.cameraData;

Expand Down Expand Up @@ -129,7 +138,10 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
// scaleBias.y = scale
// scaleBias.z = bias
// scaleBias.w = unused
float flipSign = (cameraData.IsCameraProjectionMatrixFlipped()) ? -1.0f : 1.0f;
// In game view final target acts as back buffer were target is not flipped
bool isGameViewFinalTarget = (cameraData.cameraType == CameraType.Game && destination == RenderTargetHandle.CameraTarget);
bool yflip = (cameraData.IsCameraProjectionMatrixFlipped()) && !isGameViewFinalTarget;
float flipSign = yflip ? -1.0f : 1.0f;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not super happy about this, open for suggestions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried as well a little bit about this one. It would be better if we would fix the cameraData.IsCameraProjectionMatrixFlipped() instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have bool yflip = (renderingToTexture && !isGameViewFinalTarget) && SystemInfo.graphicsUVStartsAtTop;

which is same as (renderingToTexture && SystemInfo.graphicsUVStartsAtTop) && !isGameViewFinalTarget

and renderingToTexture && SystemInfo.GraphicsUVStartsAtTop is same as IsCameraProjectMatrixFlipped

so it could be rewritten as bool yflip = cameraData.IsCameraProjectionMatrixFlipped() && !isGameViewRenderTarget ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Vector4 scaleBiasRt = (flipSign < 0.0f)
? new Vector4(flipSign, 1.0f, -1.0f, 1.0f)
: new Vector4(flipSign, 0.0f, 1.0f, 1.0f);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ private static class Profiling
public static readonly ProfilingSampler clearRenderingState = new ProfilingSampler($"{k_Name}.{nameof(ClearRenderingState)}");
public static readonly ProfilingSampler internalStartRendering = new ProfilingSampler($"{k_Name}.{nameof(InternalStartRendering)}");
public static readonly ProfilingSampler internalFinishRendering = new ProfilingSampler($"{k_Name}.{nameof(InternalFinishRendering)}");
public static readonly ProfilingSampler drawGizmos = new ProfilingSampler($"{nameof(DrawGizmos)}");

public static class RenderBlock
{
Expand Down Expand Up @@ -1005,8 +1006,20 @@ static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier[] colorAtt
void DrawGizmos(ScriptableRenderContext context, Camera camera, GizmoSubset gizmoSubset)
{
#if UNITY_EDITOR
if (UnityEditor.Handles.ShouldRenderGizmos())
if (!UnityEditor.Handles.ShouldRenderGizmos())
return;

CommandBuffer cmd = CommandBufferPool.Get();
using (new ProfilingScope(cmd, Profiling.drawGizmos))
{
context.ExecuteCommandBuffer(cmd);
cmd.Clear();

context.DrawGizmos(camera, gizmoSubset);
}

context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
#endif
}

Expand Down
20 changes: 14 additions & 6 deletions com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static class Profiling
CopyDepthPass m_XRCopyDepthPass;
#endif
#if UNITY_EDITOR
SceneViewDepthCopyPass m_SceneViewDepthCopyPass;
CopyDepthPass m_FinalDepthCopyPass;
#endif

RenderTargetHandle m_ActiveCameraColorAttachment;
Expand Down Expand Up @@ -184,7 +184,7 @@ public UniversalRenderer(UniversalRendererData data) : base(data)
m_FinalBlitPass = new FinalBlitPass(RenderPassEvent.AfterRendering + 1, m_BlitMaterial);

#if UNITY_EDITOR
m_SceneViewDepthCopyPass = new SceneViewDepthCopyPass(RenderPassEvent.AfterRendering + 9, m_CopyDepthMaterial);
m_FinalDepthCopyPass = new CopyDepthPass(RenderPassEvent.AfterRendering + 9, m_CopyDepthMaterial);
#endif

// RenderTexture format depends on camera and pipeline (HDR, non HDR, etc)
Expand Down Expand Up @@ -304,6 +304,12 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
bool isSceneViewCamera = cameraData.isSceneViewCamera;
bool requiresDepthTexture = cameraData.requiresDepthTexture || renderPassInputs.requiresDepthTexture || this.actualRenderingMode == RenderingMode.Deferred;

#if UNITY_EDITOR
bool isGizmosEnabled = UnityEditor.Handles.ShouldRenderGizmos();
#else
bool isGizmosEnabled = false;
#endif

bool mainLightShadows = m_MainLightShadowCasterPass.Setup(ref renderingData);
bool additionalLightShadows = m_AdditionalLightsShadowCasterPass.Setup(ref renderingData);
bool transparentsNeedSettingsPass = m_TransparentSettingsPass.Setup(ref renderingData);
Expand All @@ -314,6 +320,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
// - Render passes require it
bool requiresDepthPrepass = requiresDepthTexture && !CanCopyDepth(ref renderingData.cameraData);
requiresDepthPrepass |= isSceneViewCamera;
requiresDepthPrepass |= isGizmosEnabled;
requiresDepthPrepass |= isPreviewCamera;
requiresDepthPrepass |= renderPassInputs.requiresDepthPrepass;
requiresDepthPrepass |= renderPassInputs.requiresNormalsTexture;
Expand All @@ -329,7 +336,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re

// The copying of depth should normally happen after rendering opaques.
// But if we only require it for post processing or the scene camera then we do it after rendering transparent objects
m_CopyDepthPass.renderPassEvent = (!requiresDepthTexture && (applyPostProcessing || isSceneViewCamera)) ? RenderPassEvent.AfterRenderingTransparents : RenderPassEvent.AfterRenderingOpaques;
m_CopyDepthPass.renderPassEvent = (!requiresDepthTexture && (applyPostProcessing || isSceneViewCamera || isGizmosEnabled)) ? RenderPassEvent.AfterRenderingTransparents : RenderPassEvent.AfterRenderingOpaques;
createColorTexture |= RequiresIntermediateColorTexture(ref cameraData);
createColorTexture |= renderPassInputs.requiresColorTexture;
createColorTexture &= !isPreviewCamera;
Expand Down Expand Up @@ -584,12 +591,13 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
}

#if UNITY_EDITOR
if (isSceneViewCamera)
if (isSceneViewCamera && isGizmosEnabled)
{
// Scene view camera should always resolve target (not stacked)
Assertions.Assert.IsTrue(lastCameraInTheStack, "Editor camera must resolve target upon finish rendering.");
m_SceneViewDepthCopyPass.Setup(m_DepthTexture);
EnqueuePass(m_SceneViewDepthCopyPass);
m_FinalDepthCopyPass.Setup(m_DepthTexture, RenderTargetHandle.CameraTarget);
m_FinalDepthCopyPass.MssaSamples = 0;
EnqueuePass(m_FinalDepthCopyPass);
}
#endif
}
Expand Down