diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index aa9cf0009b3..89da7211913 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Added support for user-selected upscaling filters. Current options are automatic, bilinear, and nearest-neighbor. - Added batch mode support for the converters. +- Depth Texture setting for Overlay Camera. +- Render Objects now has an option to only run on certain camera types using a camera type mask. ### Changed - Re-added the menu button to be able to convert selected materials. diff --git a/com.unity.render-pipelines.universal/Documentation~/urp-renderer-feature.md b/com.unity.render-pipelines.universal/Documentation~/urp-renderer-feature.md index 3d44fc4373a..e43fd76cef4 100644 --- a/com.unity.render-pipelines.universal/Documentation~/urp-renderer-feature.md +++ b/com.unity.render-pipelines.universal/Documentation~/urp-renderer-feature.md @@ -21,6 +21,7 @@ See also: [How to use the Render Objects Renderer Feature](renderer-features/how | **Filters** | Settings that let you configure which objects this Renderer Feature renders. | | Queue | Select whether the feature renders opaque or transparent objects. | | Layer Mask | The Renderer Feature renders objects from layers you select in this property. | +| Camera Type Mask | Choose for which types of cameras the feature should run. | | **Pass Names** | If a Pass in a shader has the `LightMode` Pass Tag, this Renderer Feature processes only the shaders where the value of the `LightMode` Pass Tag equals one of the values in the Pass Names property. | | **Overrides** | Settings in this section let you configure overrides for certain properties when rendering with this Renderer Feature. | | Material | When rendering an object, Unity replaces the Material assigned to it with this Material. | diff --git a/com.unity.render-pipelines.universal/Editor/RendererFeatures/RenderObjectsPassFeatureEditor.cs b/com.unity.render-pipelines.universal/Editor/RendererFeatures/RenderObjectsPassFeatureEditor.cs index 5705901c28f..98fe8eea33a 100644 --- a/com.unity.render-pipelines.universal/Editor/RendererFeatures/RenderObjectsPassFeatureEditor.cs +++ b/com.unity.render-pipelines.universal/Editor/RendererFeatures/RenderObjectsPassFeatureEditor.cs @@ -15,6 +15,7 @@ internal class Styles { public static float defaultLineSpace = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; public static GUIContent callback = new GUIContent("Event", "Choose at which point this render pass is executed in the frame."); + public static GUIContent cameraTypeMask = new GUIContent("Camera Type Mask", "Only run the feature for cameras that match the given layer mask."); //Headers public static GUIContent filtersHeader = new GUIContent("Filters", "Settings that control which objects should be rendered."); @@ -51,6 +52,7 @@ internal class Styles // Serialized Properties private SerializedProperty m_Callback; + private SerializedProperty m_CameraTypeMask; private SerializedProperty m_PassTag; //Filter props private SerializedProperty m_FilterSettings; @@ -99,6 +101,7 @@ private void Init(SerializedProperty property) m_Callback = property.FindPropertyRelative("Event"); + m_CameraTypeMask = property.FindPropertyRelative("cameraTypeMask"); m_PassTag = property.FindPropertyRelative("passTag"); //Filter props @@ -154,6 +157,10 @@ public override void OnGUI(Rect rect, SerializedProperty property, GUIContent la m_Callback.intValue = selectedValue; rect.y += Styles.defaultLineSpace; + // Camera type mask + EditorGUI.PropertyField(rect, m_CameraTypeMask, Styles.cameraTypeMask); + rect.y += Styles.defaultLineSpace; + DoFilters(ref rect); m_RenderFoldout.value = EditorGUI.Foldout(rect, m_RenderFoldout.value, Styles.renderHeader, true); diff --git a/com.unity.render-pipelines.universal/Runtime/CameraTypeMask.cs b/com.unity.render-pipelines.universal/Runtime/CameraTypeMask.cs new file mode 100644 index 00000000000..82f0323b7fd --- /dev/null +++ b/com.unity.render-pipelines.universal/Runtime/CameraTypeMask.cs @@ -0,0 +1,56 @@ +using System; + +namespace UnityEngine.Experimental.Rendering.Universal +{ + /// + /// Specifies a set of camera types. + /// + [Flags] + [Serializable] + public enum CameraTypeMask + { + /// + /// Used to indicate a regular in-game camera. + /// + Game = 1 << 0, + /// + /// Used to indicate that a camera is used for rendering the Scene View in the Editor. + /// + SceneView = 1 << 1, + /// + /// Used to indicate a camera that is used for rendering previews in the Editor. + /// + Preview = 1 << 2, + /// + /// Used to indicate that a camera is used for rendering VR (in edit mode) in the Editor. + /// + VR = 1 << 3, + /// + /// Used to indicate a camera that is used for rendering reflection probes. + /// + Reflection = 1 << 4, + } + + static class CameraTypeMaskUtility + { + public static CameraTypeMask ToMask(this CameraType cameraType) + { + return cameraType switch + { + CameraType.Game => CameraTypeMask.Game, + CameraType.SceneView => CameraTypeMask.SceneView, + CameraType.Preview => CameraTypeMask.Preview, + CameraType.VR => CameraTypeMask.VR, + CameraType.Reflection => CameraTypeMask.Reflection, + _ => throw new ArgumentOutOfRangeException(nameof(cameraType), cameraType, "Unknown camera type") + }; + } + + public static bool Contains(this CameraTypeMask cameraTypeMask, CameraType cameraType) + { + return (cameraType.ToMask() & cameraTypeMask) != 0; + } + + public static CameraTypeMask allTypes => CameraTypeMask.Game | CameraTypeMask.SceneView | CameraTypeMask.Preview | CameraTypeMask.VR | CameraTypeMask.Reflection; + } +} diff --git a/com.unity.render-pipelines.universal/Runtime/CameraTypeMask.cs.meta b/com.unity.render-pipelines.universal/Runtime/CameraTypeMask.cs.meta new file mode 100644 index 00000000000..f5a9d9c19e9 --- /dev/null +++ b/com.unity.render-pipelines.universal/Runtime/CameraTypeMask.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a04f895465dde1842a6bfcbd3fd7ccc2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/RenderObjectsPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/RenderObjectsPass.cs index fe31806a579..97f488524e5 100644 --- a/com.unity.render-pipelines.universal/Runtime/Passes/RenderObjectsPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/Passes/RenderObjectsPass.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using UnityEngine.Rendering.Universal; using UnityEngine.Rendering; -using UnityEngine.Scripting.APIUpdating; namespace UnityEngine.Experimental.Rendering.Universal { @@ -15,6 +14,7 @@ public class RenderObjectsPass : ScriptableRenderPass public Material overrideMaterial { get; set; } public int overrideMaterialPassIndex { get; set; } + public CameraTypeMask cameraTypeMask { get; set; } = CameraTypeMaskUtility.allTypes; List m_ShaderTagIdList = new List(); @@ -79,6 +79,11 @@ internal RenderObjectsPass(URPProfileId profileId, RenderPassEvent renderPassEve public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { + if (!cameraTypeMask.Contains(renderingData.cameraData.cameraType)) + { + return; + } + SortingCriteria sortingCriteria = (renderQueueType == RenderQueueType.Transparent) ? SortingCriteria.CommonTransparent : renderingData.cameraData.defaultOpaqueSortFlags; diff --git a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/RenderObjects.cs b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/RenderObjects.cs index 068a768b5d7..e156dcb0905 100644 --- a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/RenderObjects.cs +++ b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/RenderObjects.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System; using UnityEngine.Rendering.Universal; using UnityEngine.Rendering; @@ -20,6 +20,7 @@ public class RenderObjectsSettings { public string passTag = "RenderObjectsFeature"; public RenderPassEvent Event = RenderPassEvent.AfterRenderingOpaques; + public CameraTypeMask cameraTypeMask = CameraTypeMaskUtility.allTypes; public FilterSettings filterSettings = new FilterSettings(); @@ -78,6 +79,8 @@ public override void Create() renderObjectsPass = new RenderObjectsPass(settings.passTag, settings.Event, filter.PassNames, filter.RenderQueueType, filter.LayerMask, settings.cameraSettings); + renderObjectsPass.cameraTypeMask = settings.cameraTypeMask; + renderObjectsPass.overrideMaterial = settings.overrideMaterial; renderObjectsPass.overrideMaterialPassIndex = settings.overrideMaterialPassIndex;