Skip to content

[7.x.x Backport] isSceneCamera changed to property, isPreviewCamera and cameraType added plus two bugfixes for 1240723 & 1204376 #265

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
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
3 changes: 3 additions & 0 deletions com.unity.render-pipelines.universal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- The number of maximum visible lights is now set to 32 if the platform is mobile or if the graphics API is OpenGLCore, otherwise it is set to 256.
- Optimized the 2D Renderer to skip rendering into certain internal buffers when not necessary.
- Setting the renderingData.cameraData.isSceneCamera is now marked as obsolete and replaced by renderingData.cameraData.cameraType.

### Fixed
- Fixed an issue with shadows not appearing on terrains when no cascades were selected [case 1226530](https://issuetracker.unity3d.com/issues/urp-no-shadows-on-terrain-when-cascades-is-set-to-no-cascades-in-render-pipeline-asset-settings)
Expand All @@ -31,6 +32,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed issues with performance when importing fbx files
- Fixed issues with NullReferenceException happening with URP shaders
- Fixed an issue where the emission value in particle shaders would not update in the editor without entering playmode.
- Fixed an issue where grid lines were being drawn on top of opaque objects in the preview window [case 1240723](https://issuetracker.unity3d.com/issues/urp-grid-is-rendered-in-front-of-the-model-in-the-inspector-animation-preview-window-when-depth-or-opaque-texture-is-enabled)
- Fixed an issue where objects in the preview window were being affected by layer mask settings in the default renderer [case 1204376](https://issuetracker.unity3d.com/issues/urp-prefab-preview-is-blank-when-a-custom-forward-renderer-data-and-default-layer-mask-is-mixed-are-used)

## [7.3.0] - 2020-03-11

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
EnqueuePass(m_FinalBlitPass);
}
}

public override void SetupCullingParameters(ref ScriptableCullingParameters cullingParameters, ref CameraData cameraData)
{
cullingParameters.cullingOptions = CullingOptions.None;
Expand Down
20 changes: 12 additions & 8 deletions com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
#endif

bool isSceneViewCamera = cameraData.isSceneViewCamera;
bool isPreviewCamera = cameraData.isPreviewCamera;
bool requiresDepthTexture = cameraData.requiresDepthTexture;
bool isStereoEnabled = cameraData.isStereoEnabled;

Expand All @@ -172,10 +173,11 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
bool transparentsNeedSettingsPass = m_TransparentSettingsPass.Setup(ref renderingData);

// Depth prepass is generated in the following cases:
// - Scene view camera always requires a depth texture. We do a depth pre-pass to simplify it and it shouldn't matter much for editor.
// - If game or offscreen camera requires it we check if we can copy the depth from the rendering opaques pass and use that instead.
bool requiresDepthPrepass = isSceneViewCamera;
requiresDepthPrepass |= (requiresDepthTexture && !CanCopyDepth(ref renderingData.cameraData));
// - Scene or preview cameras always require a depth texture. We do a depth pre-pass to simplify it and it shouldn't matter much for editor.
bool requiresDepthPrepass = requiresDepthTexture && !CanCopyDepth(ref renderingData.cameraData);
requiresDepthPrepass |= isSceneViewCamera;
requiresDepthPrepass |= isPreviewCamera;

// 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
Expand All @@ -190,8 +192,9 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
#if ENABLE_VR && ENABLE_VR_MODULE
isRunningHololens = UniversalRenderPipeline.IsRunningHololens(camera);
#endif
bool createColorTexture = RequiresIntermediateColorTexture(ref cameraData) ||
(rendererFeatures.Count != 0 && !isRunningHololens);
bool createColorTexture = RequiresIntermediateColorTexture(ref cameraData);
createColorTexture |= (rendererFeatures.Count != 0 && !isRunningHololens);
createColorTexture &= !isPreviewCamera;

// If camera requires depth and there's no depth pre-pass we create a depth texture that can be read later by effect requiring it.
bool createDepthTexture = cameraData.requiresDepthTexture && !requiresDepthPrepass;
Expand Down Expand Up @@ -414,7 +417,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
}

#if UNITY_EDITOR
if (renderingData.cameraData.isSceneViewCamera)
if (isSceneViewCamera)
{
// Scene view camera should always resolve target (not stacked)
Assertions.Assert.IsTrue(lastCameraInTheStack, "Editor camera must resolve target upon finish rendering.");
Expand Down Expand Up @@ -532,13 +535,14 @@ bool RequiresIntermediateColorTexture(ref CameraData cameraData)
if (cameraData.renderType == CameraRenderType.Base && !cameraData.resolveFinalTarget)
return true;

bool isSceneViewCamera = cameraData.isSceneViewCamera;
var cameraTargetDescriptor = cameraData.cameraTargetDescriptor;
int msaaSamples = cameraTargetDescriptor.msaaSamples;
bool isStereoEnabled = cameraData.isStereoEnabled;
bool isScaledRender = !Mathf.Approximately(cameraData.renderScale, 1.0f) && !cameraData.isStereoEnabled;
bool isCompatibleBackbufferTextureDimension = cameraTargetDescriptor.dimension == TextureDimension.Tex2D;
bool requiresExplicitMsaaResolve = msaaSamples > 1 && !SystemInfo.supportsMultisampleAutoResolve;
bool isOffscreenRender = cameraData.targetTexture != null && !cameraData.isSceneViewCamera;
bool isOffscreenRender = cameraData.targetTexture != null && !isSceneViewCamera;
bool isCapturing = cameraData.captureActions != null;

#if ENABLE_VR && ENABLE_VR_MODULE
Expand All @@ -550,7 +554,7 @@ bool RequiresIntermediateColorTexture(ref CameraData cameraData)
if (isOffscreenRender)
return requiresBlitForOffscreenCamera;

return requiresBlitForOffscreenCamera || cameraData.isSceneViewCamera || isScaledRender || cameraData.isHdrEnabled ||
return requiresBlitForOffscreenCamera || isSceneViewCamera || isScaledRender || cameraData.isHdrEnabled ||
!isCompatibleBackbufferTextureDimension || !cameraData.isDefaultViewport || isCapturing ||
(Display.main.requiresBlitToBackbuffer && !isStereoEnabled);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public DrawObjectsPass(string profilerTag, bool opaque, RenderPassEvent evt, Ren
m_ShaderTagIdList.Add(new ShaderTagId("LightweightForward"));
m_ShaderTagIdList.Add(new ShaderTagId("SRPDefaultUnlit"));
renderPassEvent = evt;

m_FilteringSettings = new FilteringSettings(renderQueueRange, layerMask);
m_RenderStateBlock = new RenderStateBlock(RenderStateMask.Nothing);
m_IsOpaque = opaque;
Expand All @@ -49,10 +50,20 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
Camera camera = renderingData.cameraData.camera;
var sortFlags = (m_IsOpaque) ? renderingData.cameraData.defaultOpaqueSortFlags : SortingCriteria.CommonTransparent;
var drawSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, sortFlags);
context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref m_FilteringSettings, ref m_RenderStateBlock);
var filterSettings = m_FilteringSettings;

#if UNITY_EDITOR
// When rendering the preview camera, we want the layer mask to be forced to Everything
if (renderingData.cameraData.isPreviewCamera)
{
filterSettings.layerMask = -1;
}
#endif

context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref filterSettings, ref m_RenderStateBlock);

// Render objects that did not match any shader pass with error shader
RenderingUtils.RenderObjectsWithError(context, ref renderingData.cullResults, camera, m_FilteringSettings, SortingCriteria.None);
RenderingUtils.RenderObjectsWithError(context, ref renderingData.cullResults, camera, filterSettings, SortingCriteria.None);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
RenderTargetIdentifier cameraTarget = (cameraData.targetTexture != null) ? new RenderTargetIdentifier(cameraData.targetTexture) : BuiltinRenderTextureType.CameraTarget;

bool requiresSRGBConvertion = Display.main.requiresSrgbBlitToBackbuffer;
bool isSceneViewCamera = cameraData.isSceneViewCamera;

// For stereo case, eye texture always want color data in sRGB space.
// If eye texture color format is linear, we do explicit sRGB convertion
Expand All @@ -64,7 +65,7 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
// The blit will be reworked for stereo along the XRSDK work.
Material blitMaterial = (cameraData.isStereoEnabled) ? null : m_BlitMaterial;
cmd.SetGlobalTexture("_BlitTex", m_Source.Identifier());
if (cameraData.isStereoEnabled || cameraData.isSceneViewCamera || cameraData.isDefaultViewport)
if (cameraData.isStereoEnabled || isSceneViewCamera || cameraData.isDefaultViewport)
{
// This set render target is necessary so we change the LOAD state to DontCare.
cmd.SetRenderTarget(BuiltinRenderTextureType.CameraTarget,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ void Render(CommandBuffer cmd, ref RenderingData renderingData)
bool tempTarget2Used = false;
int source = m_Source.id;
int destination = -1;
bool isSceneViewCamera = cameraData.isSceneViewCamera;

// Utilities to simplify intermediate target management
int GetSource() => source;
Expand All @@ -257,7 +258,7 @@ int GetDestination()
// Avoid using m_Source.id as new destination, it may come with a depth buffer that we don't want, may have MSAA that we don't want etc
cmd.GetTemporaryRT(ShaderConstants._TempTarget2, GetStereoCompatibleDescriptor(), FilterMode.Bilinear);
destination = ShaderConstants._TempTarget2;
tempTarget2Used = true;
tempTarget2Used = true;
}

return destination;
Expand Down Expand Up @@ -291,7 +292,7 @@ int GetDestination()
}

// Depth of Field
if (m_DepthOfField.IsActive() && !cameraData.isSceneViewCamera)
if (m_DepthOfField.IsActive() && !isSceneViewCamera)
{
var markerName = m_DepthOfField.mode.value == DepthOfFieldMode.Gaussian
? URPProfileId.GaussianDepthOfField
Expand All @@ -305,7 +306,7 @@ int GetDestination()
}

// Motion blur
if (m_MotionBlur.IsActive() && !cameraData.isSceneViewCamera)
if (m_MotionBlur.IsActive() && !isSceneViewCamera)
{
using (new ProfilingScope(cmd, ProfilingSampler.Get(URPProfileId.MotionBlur)))
{
Expand All @@ -316,7 +317,7 @@ int GetDestination()

// Panini projection is done as a fullscreen pass after all depth-based effects are done
// and before bloom kicks in
if (m_PaniniProjection.IsActive() && !cameraData.isSceneViewCamera)
if (m_PaniniProjection.IsActive() && !isSceneViewCamera)
{
using (new ProfilingScope(cmd, ProfilingSampler.Get(URPProfileId.PaniniProjection)))
{
Expand All @@ -340,7 +341,7 @@ int GetDestination()
}

// Setup other effects constants
SetupLensDistortion(m_Materials.uber, cameraData.isSceneViewCamera);
SetupLensDistortion(m_Materials.uber, isSceneViewCamera);
SetupChromaticAberration(m_Materials.uber);
SetupVignette(m_Materials.uber);
SetupColorGrading(cmd, ref renderingData, m_Materials.uber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ static void RenderSingleCamera(ScriptableRenderContext context, CameraData camer
return;

ScriptableRenderer.current = renderer;
bool isSceneViewCamera = cameraData.isSceneViewCamera;

ProfilingSampler sampler = (asset.debugLevel >= PipelineDebugLevel.Profiling) ? new ProfilingSampler(camera.name): _CameraProfilingSampler;
CommandBuffer cmd = CommandBufferPool.Get(sampler.name);
Expand All @@ -263,7 +264,7 @@ static void RenderSingleCamera(ScriptableRenderContext context, CameraData camer

#if UNITY_EDITOR
// Emit scene view UI
if (cameraData.isSceneViewCamera)
if (isSceneViewCamera)
{
ScriptableRenderContext.EmitWorldGeometryForSceneView(camera);
}
Expand Down Expand Up @@ -523,14 +524,14 @@ static void InitializeStackedCameraData(Camera baseCamera, UniversalAdditionalCa
var settings = asset;
cameraData.targetTexture = baseCamera.targetTexture;
cameraData.isStereoEnabled = IsStereoEnabled(baseCamera);
cameraData.isSceneViewCamera = baseCamera.cameraType == CameraType.SceneView;

cameraData.cameraType = baseCamera.cameraType;
cameraData.numberOfXRPasses = 1;
cameraData.isXRMultipass = false;

bool isSceneViewCamera = cameraData.isSceneViewCamera;

#if ENABLE_VR && ENABLE_VR_MODULE
if (cameraData.isStereoEnabled && !cameraData.isSceneViewCamera &&
!CanXRSDKUseSinglePass(baseCamera) && XR.XRSettings.stereoRenderingMode == XR.XRSettings.StereoRenderingMode.MultiPass)
if (cameraData.isStereoEnabled && !isSceneViewCamera && !CanXRSDKUseSinglePass(baseCamera) && XR.XRSettings.stereoRenderingMode == XR.XRSettings.StereoRenderingMode.MultiPass)
{
cameraData.numberOfXRPasses = 2;
cameraData.isXRMultipass = true;
Expand All @@ -540,7 +541,7 @@ static void InitializeStackedCameraData(Camera baseCamera, UniversalAdditionalCa
///////////////////////////////////////////////////////////////////
// Environment and Post-processing settings /
///////////////////////////////////////////////////////////////////
if (cameraData.isSceneViewCamera)
if (isSceneViewCamera)
{
cameraData.volumeLayerMask = 1; // "Default"
cameraData.volumeTrigger = null;
Expand Down Expand Up @@ -618,10 +619,10 @@ static void InitializeAdditionalCameraData(Camera camera, UniversalAdditionalCam

bool anyShadowsEnabled = settings.supportsMainLightShadows || settings.supportsAdditionalLightShadows;
cameraData.maxShadowDistance = Mathf.Min(settings.shadowDistance, camera.farClipPlane);
cameraData.maxShadowDistance = (anyShadowsEnabled && cameraData.maxShadowDistance >= camera.nearClipPlane) ?
cameraData.maxShadowDistance : 0.0f;
cameraData.maxShadowDistance = (anyShadowsEnabled && cameraData.maxShadowDistance >= camera.nearClipPlane) ? cameraData.maxShadowDistance : 0.0f;

if (cameraData.isSceneViewCamera)
bool isSceneViewCamera = cameraData.isSceneViewCamera;
if (isSceneViewCamera)
{
cameraData.renderType = CameraRenderType.Base;
cameraData.clearDepth = true;
Expand Down Expand Up @@ -678,7 +679,7 @@ static void InitializeAdditionalCameraData(Camera camera, UniversalAdditionalCam
bool depthRequiredForPostFX = CheckPostProcessForDepth(cameraData);
#endif

cameraData.requiresDepthTexture |= cameraData.isSceneViewCamera || depthRequiredForPostFX;
cameraData.requiresDepthTexture |= isSceneViewCamera || depthRequiredForPostFX;
cameraData.resolveFinalTarget = resolveFinalTarget;

Matrix4x4 projectionMatrix = camera.projectionMatrix;
Expand Down Expand Up @@ -740,8 +741,6 @@ static void InitializeRenderingData(UniversalRenderPipelineAsset settings, ref C
InitializePostProcessingData(settings, out renderingData.postProcessingData);
renderingData.supportsDynamicBatching = settings.supportsDynamicBatching;
renderingData.perObjectData = GetPerObjectLightFlags(renderingData.lightData.additionalLightsCount);

bool isOffscreenCamera = cameraData.targetTexture != null && !cameraData.isSceneViewCamera;
renderingData.postProcessingEnabled = anyPostProcessingEnabled;
#pragma warning disable // avoid warning because killAlphaInFinalBlit has attribute Obsolete
renderingData.killAlphaInFinalBlit = false;
Expand Down
Loading