Skip to content

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

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 13 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -54,6 +54,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- DepthOnlyPass, CopyDepthPass and CopyColorPass now use OnCameraSetup() instead of Configure() to set up their passes before executing as they only need to get their rendertextures once per camera instead of once per eye.
- Updated shaders to be compatible with Microsoft's DXC.
- Mesh GPU Instancing option is now hidden from the particles system renderer as this feature is not supported by URP.
- renderingData.cameraData.isSceneCamera is now marked as obsolete and replaced by renderingData.cameraData.cameraType.

### Fixed
- Fixed an issue where linear to sRGB conversion occurred twice on certain Android devices.
Expand Down Expand Up @@ -172,6 +173,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed issue on Nintendo Switch where maximum number of visible lights in C# code did not match maximum number in shader code.
- Fixed OpenGL ES 3.0 support for URP ShaderGraph. [case 1230890](https://issuetracker.unity3d.com/issues/urptemplate-gles3-android-custom-shader-fails-to-compile-on-adreno-306-gpu)
- Fixed an issue where multi edit camera properties didn't work. [case 1230080](https://issuetracker.unity3d.com/issues/urp-certain-settings-are-not-applied-to-all-cameras-when-multi-editing-in-the-inspector)
- 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.1.1] - 2019-09-05
### Upgrade Guide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public void GetTransparencySortingMode(Camera camera, ref SortingSettings sortin

public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{

bool isSceneViewCamera = renderingData.cameraData.cameraType == CameraType.SceneView;
bool isLitView = true;

#if UNITY_EDITOR
if (renderingData.cameraData.isSceneViewCamera)
if (isSceneViewCamera)
isLitView = UnityEditor.SceneView.currentDrawingSceneView.sceneLighting;

if (renderingData.cameraData.camera.cameraType == CameraType.Preview)
Expand Down
5 changes: 3 additions & 2 deletions com.unity.render-pipelines.universal/Runtime/2D/Renderer2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
PixelPerfectCamera ppc;
cameraData.camera.TryGetComponent<PixelPerfectCamera>(out ppc);

bool isSceneViewCamera = cameraData.cameraType == CameraType.SceneView;
Vector2Int ppcOffscreenRTSize = ppc != null ? ppc.offscreenRTSize : Vector2Int.zero;
bool ppcUsesOffscreenRT = ppcOffscreenRTSize != Vector2Int.zero;
bool postProcessEnabled = renderingData.cameraData.postProcessEnabled;
bool useOffscreenColorTexture =
ppcUsesOffscreenRT || postProcessEnabled || cameraData.isHdrEnabled || cameraData.isSceneViewCamera || !cameraData.isDefaultViewport || !m_UseDepthStencilBuffer;
ppcUsesOffscreenRT || postProcessEnabled || cameraData.isHdrEnabled || isSceneViewCamera || !cameraData.isDefaultViewport || !m_UseDepthStencilBuffer;

// Pixel Perfect Camera may request a different RT size than camera VP size.
// In that case we need to modify cameraTargetDescriptor here so that all the passes would use the same size.
Expand Down Expand Up @@ -150,7 +151,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
18 changes: 11 additions & 7 deletions com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re

// We generate color LUT in the base camera only. This allows us to not break render pass execution for overlay cameras.
bool generateColorGradingLUT = anyPostProcessing && cameraData.renderType == CameraRenderType.Base;
bool isSceneViewCamera = cameraData.isSceneViewCamera;
bool isSceneViewCamera = cameraData.cameraType == CameraType.SceneView;
bool isPreviewCamera = cameraData.cameraType == CameraType.Preview;
bool requiresDepthTexture = cameraData.requiresDepthTexture;
bool isStereoEnabled = cameraData.isStereoEnabled;

Expand All @@ -155,10 +156,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 @@ -170,6 +172,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
requiresDepthPrepass = true;

bool createColorTexture = RequiresIntermediateColorTexture(ref cameraData);
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 @@ -337,7 +340,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 @@ -459,13 +462,14 @@ bool RequiresIntermediateColorTexture(ref CameraData cameraData)
if (cameraData.renderType == CameraRenderType.Base && !cameraData.resolveFinalTarget)
return true;

bool isSceneViewCamera = cameraData.cameraType == CameraType.SceneView;
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 @@ -477,7 +481,7 @@ bool RequiresIntermediateColorTexture(ref CameraData cameraData)
if (isOffscreenRender)
return requiresBlitForOffscreenCamera;

return requiresBlitForOffscreenCamera || cameraData.isSceneViewCamera || isScaledRender || cameraData.isHdrEnabled ||
return requiresBlitForOffscreenCamera || isSceneViewCamera || isScaledRender || cameraData.isHdrEnabled ||
!isCompatibleBackbufferTextureDimension || isCapturing || (Display.main.requiresBlitToBackbuffer && !isStereoEnabled);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public DrawObjectsPass(string profilerTag, bool opaque, RenderPassEvent evt, Ren
m_ShaderTagIdList.Add(new ShaderTagId("UniversalForward"));
m_ShaderTagIdList.Add(new ShaderTagId("LightweightForward"));
renderPassEvent = evt;

m_FilteringSettings = new FilteringSettings(renderQueueRange, layerMask);
m_RenderStateBlock = new RenderStateBlock(RenderStateMask.Nothing);
m_IsOpaque = opaque;
Expand Down Expand Up @@ -56,10 +57,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.cameraType == CameraType.Preview)
{
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.cameraType == CameraType.SceneView;

// 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 @@ -247,6 +247,7 @@ void Render(CommandBuffer cmd, ref RenderingData renderingData)
bool tempTarget2Used = false;
int source = m_Source.id;
int destination = -1;
bool isSceneViewCamera = cameraData.cameraType == CameraType.SceneView;

// Utilities to simplify intermediate target management
int GetSource() => source;
Expand All @@ -264,7 +265,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 @@ -298,7 +299,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 @@ -312,7 +313,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 @@ -323,7 +324,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 @@ -347,7 +348,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 @@ -207,6 +207,7 @@ static void RenderSingleCamera(ScriptableRenderContext context, CameraData camer
return;

ScriptableRenderer.current = renderer;
bool isSceneViewCamera = cameraData.cameraType == CameraType.SceneView;

ProfilingSampler sampler = (asset.debugLevel >= PipelineDebugLevel.Profiling) ? new ProfilingSampler(camera.name): _CameraProfilingSampler;
CommandBuffer cmd = CommandBufferPool.Get(sampler.name);
Expand All @@ -220,7 +221,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 @@ -433,13 +434,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.cameraType == CameraType.SceneView;

#if ENABLE_VR && ENABLE_VR_MODULE
if (cameraData.isStereoEnabled && !cameraData.isSceneViewCamera && XR.XRSettings.stereoRenderingMode == XR.XRSettings.StereoRenderingMode.MultiPass)
if (cameraData.isStereoEnabled && !isSceneViewCamera && XR.XRSettings.stereoRenderingMode == XR.XRSettings.StereoRenderingMode.MultiPass)
{
cameraData.numberOfXRPasses = 2;
cameraData.isXRMultipass = true;
Expand All @@ -449,7 +451,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 @@ -526,10 +528,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.cameraType == CameraType.SceneView;
if (isSceneViewCamera)
{
cameraData.renderType = CameraRenderType.Base;
cameraData.clearDepth = true;
Expand Down Expand Up @@ -570,7 +572,7 @@ static void InitializeAdditionalCameraData(Camera camera, UniversalAdditionalCam
// Disables post if GLes2
cameraData.postProcessEnabled &= SystemInfo.graphicsDeviceType != GraphicsDeviceType.OpenGLES2;

cameraData.requiresDepthTexture |= cameraData.isSceneViewCamera || CheckPostProcessForDepth(cameraData);
cameraData.requiresDepthTexture |= isSceneViewCamera || CheckPostProcessForDepth(cameraData);
cameraData.resolveFinalTarget = resolveFinalTarget;

Matrix4x4 projectionMatrix = camera.projectionMatrix;
Expand Down Expand Up @@ -632,8 +634,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;
}

Expand Down
Loading