using UnityEngine.Scripting.APIUpdating;
namespace UnityEngine.Rendering.Universal
{
///
/// The queue type for the objects to render.
///
[MovedFrom(true, "UnityEngine.Experimental.Rendering.Universal")]
public enum RenderQueueType
{
///
/// Use this for opaque objects.
///
Opaque,
///
/// Use this for transparent objects.
///
Transparent,
}
///
/// The class for the render objects renderer feature.
///
[ExcludeFromPreset]
[MovedFrom(true, "UnityEngine.Experimental.Rendering.Universal")]
[Tooltip("Render Objects simplifies the injection of additional render passes by exposing a selection of commonly used settings.")]
[URPHelpURL("renderer-features/renderer-feature-render-objects")]
public class RenderObjects : ScriptableRendererFeature
{
///
/// Settings class used for the render objects renderer feature.
///
[System.Serializable]
public class RenderObjectsSettings
{
///
/// The profiler tag used with the pass.
///
public string passTag = "RenderObjectsFeature";
///
/// Controls when the render pass executes.
///
public RenderPassEvent Event = RenderPassEvent.AfterRenderingOpaques;
///
/// The filter settings for the pass.
///
public FilterSettings filterSettings = new FilterSettings();
///
/// The override material to use.
///
public Material overrideMaterial = null;
///
/// The pass index to use with the override material.
///
public int overrideMaterialPassIndex = 0;
///
/// The override shader to use.
///
public Shader overrideShader = null;
///
/// The pass index to use with the override shader.
///
public int overrideShaderPassIndex = 0;
///
/// Options to select which type of override mode should be used.
///
public enum OverrideMaterialMode
{
///
/// Use this to not override.
///
None,
///
/// Use this to use an override material.
///
Material,
///
/// Use this to use an override shader.
///
Shader
};
///
/// The selected override mode.
///
public OverrideMaterialMode overrideMode = OverrideMaterialMode.Material; //default to Material as this was previously the only option
///
/// Sets whether it should override depth or not.
///
public bool overrideDepthState = false;
///
/// The depth comparison function to use.
///
public CompareFunction depthCompareFunction = CompareFunction.LessEqual;
///
/// Sets whether it should write to depth or not.
///
public bool enableWrite = true;
///
/// The stencil settings to use.
///
public StencilStateData stencilSettings = new StencilStateData();
///
/// The camera settings to use.
///
public CustomCameraSettings cameraSettings = new CustomCameraSettings();
}
///
/// The filter settings used.
///
[System.Serializable]
public class FilterSettings
{
// TODO: expose opaque, transparent, all ranges as drop down
///
/// The queue type for the objects to render.
///
public RenderQueueType RenderQueueType;
///
/// The layer mask to use.
///
public LayerMask LayerMask;
///
/// The passes to render.
///
public string[] PassNames;
///
/// The constructor for the filter settings.
///
public FilterSettings()
{
RenderQueueType = RenderQueueType.Opaque;
LayerMask = 0;
}
}
///
/// The settings for custom cameras values.
///
[System.Serializable]
public class CustomCameraSettings
{
///
/// Used to mark whether camera values should be changed or not.
///
public bool overrideCamera = false;
///
/// Should the values be reverted after rendering the objects?
///
public bool restoreCamera = true;
///
/// Changes the camera offset.
///
public Vector4 offset;
///
/// Changes the camera field of view.
///
public float cameraFieldOfView = 60.0f;
}
///
/// The settings used for the Render Objects renderer feature.
///
public RenderObjectsSettings settings = new RenderObjectsSettings();
RenderObjectsPass renderObjectsPass;
///
public override void Create()
{
FilterSettings filter = settings.filterSettings;
// Render Objects pass doesn't support events before rendering prepasses.
// The camera is not setup before this point and all rendering is monoscopic.
// Events before BeforeRenderingPrepasses should be used for input texture passes (shadow map, LUT, etc) that doesn't depend on the camera.
// These events are filtering in the UI, but we still should prevent users from changing it from code or
// by changing the serialized data.
if (settings.Event < RenderPassEvent.BeforeRenderingPrePasses)
settings.Event = RenderPassEvent.BeforeRenderingPrePasses;
renderObjectsPass = new RenderObjectsPass(settings.passTag, settings.Event, filter.PassNames,
filter.RenderQueueType, filter.LayerMask, settings.cameraSettings);
switch (settings.overrideMode)
{
case RenderObjectsSettings.OverrideMaterialMode.None:
renderObjectsPass.overrideMaterial = null;
renderObjectsPass.overrideShader = null;
break;
case RenderObjectsSettings.OverrideMaterialMode.Material:
renderObjectsPass.overrideMaterial = settings.overrideMaterial;
renderObjectsPass.overrideMaterialPassIndex = settings.overrideMaterialPassIndex;
renderObjectsPass.overrideShader = null;
break;
case RenderObjectsSettings.OverrideMaterialMode.Shader:
renderObjectsPass.overrideMaterial = null;
renderObjectsPass.overrideShader = settings.overrideShader;
renderObjectsPass.overrideShaderPassIndex = settings.overrideShaderPassIndex;
break;
}
if (settings.overrideDepthState)
renderObjectsPass.SetDepthState(settings.enableWrite, settings.depthCompareFunction);
if (settings.stencilSettings.overrideStencilState)
renderObjectsPass.SetStencilState(settings.stencilSettings.stencilReference,
settings.stencilSettings.stencilCompareFunction, settings.stencilSettings.passOperation,
settings.stencilSettings.failOperation, settings.stencilSettings.zFailOperation);
}
///
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
if (renderingData.cameraData.cameraType == CameraType.Preview
|| UniversalRenderer.IsOffscreenDepthTexture(ref renderingData.cameraData))
return;
renderer.EnqueuePass(renderObjectsPass);
}
internal override bool SupportsNativeRenderPass()
{
return true;
}
}
}