using System;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering
{
// This is a temporary structure that will help transition to render graph
// Plan is to define this correctly on the C++ side and expose it to C# later.
///
/// Structure holding RendererList information used to draw renderers.
///
[Obsolete("Use the updated RendererList API which is defined in the UnityEngine.Rendering.RendererUtils namespace.")]
public struct RendererList
{
static readonly ShaderTagId s_EmptyName = new ShaderTagId("");
///
/// Default null renderer list.
///
public static readonly RendererList nullRendererList = new RendererList();
///
/// True if the renderer list is valid.
///
public bool isValid { get; private set; }
///
/// CullingResults associated with the renderer list.
///
public CullingResults cullingResult;
///
/// DrawingSettings associated with the renderer list.
///
public DrawingSettings drawSettings;
///
/// FilteringSettings associated with the renderer list.
///
public FilteringSettings filteringSettings;
///
/// Optional RenderStateBlock associated with the renderer list.
///
public RenderStateBlock? stateBlock;
///
/// Creates a new renderer list.
///
/// Parameters for renderer list creation.
/// A new renderer list.
public static RendererList Create(in RendererListDesc desc)
{
RendererList newRenderList = new RendererList();
// At this point the RendererList is invalid and will be caught when using it.
// It's fine because to simplify setup code you might not always have a valid desc. The important part is to catch it if used.
if (!desc.IsValid())
return newRenderList;
var sortingSettings = new SortingSettings(desc.camera)
{
criteria = desc.sortingCriteria
};
var drawSettings = new DrawingSettings(s_EmptyName, sortingSettings)
{
perObjectData = desc.rendererConfiguration
};
if (desc.passName != ShaderTagId.none)
{
Debug.Assert(desc.passNames == null);
drawSettings.SetShaderPassName(0, desc.passName);
}
else
{
for (int i = 0; i < desc.passNames.Length; ++i)
{
drawSettings.SetShaderPassName(i, desc.passNames[i]);
}
}
if (desc.overrideMaterial != null)
{
drawSettings.overrideMaterial = desc.overrideMaterial;
drawSettings.overrideMaterialPassIndex = desc.overrideMaterialPassIndex;
}
var filterSettings = new FilteringSettings(desc.renderQueueRange, desc.layerMask)
{
excludeMotionVectorObjects = desc.excludeObjectMotionVectors
};
newRenderList.isValid = true;
newRenderList.cullingResult = desc.cullingResult;
newRenderList.drawSettings = drawSettings;
newRenderList.filteringSettings = filterSettings;
newRenderList.stateBlock = desc.stateBlock;
return newRenderList;
}
}
///
/// Renderer list creation descriptor.
///
[Obsolete("Use the updated RendererList API which is defined in the UnityEngine.Rendering.RendererUtils namespace.")]
public struct RendererListDesc
{
///
/// SortingCriteria for this renderer list.
///
public SortingCriteria sortingCriteria;
///
/// PerObjectData configuration for this renderer list.
///
public PerObjectData rendererConfiguration;
///
/// RenderQueueRange of this renderer list.
///
public RenderQueueRange renderQueueRange;
///
/// Optional RenderStateBlock for this renderer list.
///
public RenderStateBlock? stateBlock;
///
/// Override material for this renderer list.
///
public Material overrideMaterial;
///
/// Exclude object with motion from this renderer list.
///
public bool excludeObjectMotionVectors;
///
/// Rendering layer mask used for filtering this renderer list.
///
public int layerMask;
///
/// Pass index for the override material.
///
public int overrideMaterialPassIndex;
// Mandatory parameters passed through constructors
internal CullingResults cullingResult { get; private set; }
internal Camera camera { get; set; }
internal ShaderTagId passName { get; private set; }
internal ShaderTagId[] passNames { get; private set; }
///
/// RendererListDesc constructor
///
/// Pass name used for this renderer list.
/// Culling result used to create the renderer list.
/// Camera used to determine sorting parameters.
public RendererListDesc(ShaderTagId passName, CullingResults cullingResult, Camera camera)
: this()
{
this.passName = passName;
this.passNames = null;
this.cullingResult = cullingResult;
this.camera = camera;
this.layerMask = -1;
this.overrideMaterialPassIndex = 0;
}
///
/// RendererListDesc constructor
///
/// List of pass names used for this renderer list.
/// Culling result used to create the renderer list.
/// Camera used to determine sorting parameters.
public RendererListDesc(ShaderTagId[] passNames, CullingResults cullingResult, Camera camera)
: this()
{
this.passNames = passNames;
this.passName = ShaderTagId.none;
this.cullingResult = cullingResult;
this.camera = camera;
this.layerMask = -1;
this.overrideMaterialPassIndex = 0;
}
///
/// Returns true if the descriptor is valid.
///
/// True if the descriptor is valid.
public bool IsValid()
{
if (camera == null || (passName == ShaderTagId.none && (passNames == null || passNames.Length == 0)))
return false;
return true;
}
}
}