Skip to content

Add camera type mask to Render Objects #5938

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions com.unity.render-pipelines.universal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
56 changes: 56 additions & 0 deletions com.unity.render-pipelines.universal/Runtime/CameraTypeMask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;

namespace UnityEngine.Experimental.Rendering.Universal
{
/// <summary>
/// Specifies a set of camera types.
/// </summary>
[Flags]
[Serializable]
public enum CameraTypeMask
{
/// <summary>
/// Used to indicate a regular in-game camera.
/// </summary>
Game = 1 << 0,
/// <summary>
/// Used to indicate that a camera is used for rendering the Scene View in the Editor.
/// </summary>
SceneView = 1 << 1,
/// <summary>
/// Used to indicate a camera that is used for rendering previews in the Editor.
/// </summary>
Preview = 1 << 2,
/// <summary>
/// Used to indicate that a camera is used for rendering VR (in edit mode) in the Editor.
/// </summary>
VR = 1 << 3,
/// <summary>
/// Used to indicate a camera that is used for rendering reflection probes.
/// </summary>
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;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using UnityEngine.Rendering.Universal;
using UnityEngine.Rendering;
using UnityEngine.Scripting.APIUpdating;

namespace UnityEngine.Experimental.Rendering.Universal
{
Expand All @@ -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<ShaderTagId> m_ShaderTagIdList = new List<ShaderTagId>();

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System;
using UnityEngine.Rendering.Universal;
using UnityEngine.Rendering;

Expand All @@ -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();

Expand Down Expand Up @@ -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;

Expand Down