sleal-unity
4 年前
当前提交
515a1a83
共有 34 个文件被更改,包括 357 次插入 和 318 次删除
-
3com.unity.perception/Editor/GroundTruth/InstanceSegmentationPassEditor.cs
-
2com.unity.perception/Runtime/GroundTruth/IGroundTruthGenerator.cs
-
57com.unity.perception/Runtime/GroundTruth/LabeledObjectsManager.cs
-
2com.unity.perception/Runtime/GroundTruth/PerceptionUpdater.cs
-
11com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
-
2com.unity.perception/Runtime/GroundTruth/CustomPasses/GroundTruthCrossPipelinePass.cs.meta
-
2com.unity.perception/Runtime/GroundTruth/CustomPasses/SemanticSegmentationCrossPipelinePass.cs.meta
-
2com.unity.perception/Runtime/GroundTruth/CustomPasses/SemanticSegmentationPass.cs.meta
-
6com.unity.perception/Runtime/GroundTruth/CustomPasses/LensDistortionCrossPipelinePass.cs
-
5com.unity.perception/Runtime/GroundTruth/CustomPasses/LensDistortionPass.cs
-
10com.unity.perception/Runtime/GroundTruth/CustomPasses/GroundTruthPass.cs
-
3com.unity.perception/Runtime/GroundTruth/CustomPasses.meta
-
120com.unity.perception/Runtime/GroundTruth/CustomPasses/GroundTruthCrossPipelinePass.cs
-
3com.unity.perception/Runtime/GroundTruth/CustomPasses/GroundTruthPass.cs.meta
-
78com.unity.perception/Runtime/GroundTruth/CustomPasses/InstanceSegmentationCrossPipelinePass.cs
-
3com.unity.perception/Runtime/GroundTruth/CustomPasses/InstanceSegmentationCrossPipelinePass.cs.meta
-
83com.unity.perception/Runtime/GroundTruth/CustomPasses/SemanticSegmentationCrossPipelinePass.cs
-
11com.unity.perception/Runtime/GroundTruth/GroundTruthPass.cs.meta
-
11com.unity.perception/Runtime/GroundTruth/InstanceSegmentationCrossPipelinePass.cs.meta
-
78com.unity.perception/Runtime/GroundTruth/InstanceSegmentationCrossPipelinePass.cs
-
79com.unity.perception/Runtime/GroundTruth/SemanticSegmentationCrossPipelinePass.cs
-
104com.unity.perception/Runtime/GroundTruth/GroundTruthCrossPipelinePass.cs
-
0/com.unity.perception/Runtime/GroundTruth/CustomPasses/GroundTruthCrossPipelinePass.cs.meta
-
0/com.unity.perception/Runtime/GroundTruth/CustomPasses/InstanceSegmentationPass.cs
-
0/com.unity.perception/Runtime/GroundTruth/CustomPasses/InstanceSegmentationPass.cs.meta
-
0/com.unity.perception/Runtime/GroundTruth/CustomPasses/SemanticSegmentationCrossPipelinePass.cs.meta
-
0/com.unity.perception/Runtime/GroundTruth/CustomPasses/SemanticSegmentationPass.cs
-
0/com.unity.perception/Runtime/GroundTruth/CustomPasses/SemanticSegmentationPass.cs.meta
-
0/com.unity.perception/Runtime/GroundTruth/CustomPasses/LensDistortionCrossPipelinePass.cs
-
0/com.unity.perception/Runtime/GroundTruth/CustomPasses/LensDistortionCrossPipelinePass.cs.meta
-
0/com.unity.perception/Runtime/GroundTruth/CustomPasses/LensDistortionPass.cs
-
0/com.unity.perception/Runtime/GroundTruth/CustomPasses/LensDistortionPass.cs.meta
-
0/com.unity.perception/Runtime/GroundTruth/CustomPasses/GroundTruthPass.cs
|
|||
fileFormatVersion: 2 |
|||
guid: 36c50bc1fa70491eaa8ffd85c55187d0 |
|||
timeCreated: 1615074717 |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
public abstract class GroundTruthCrossPipelinePass : IGroundTruthGenerator |
|||
{ |
|||
public Camera targetCamera; |
|||
|
|||
bool m_IsActivated; |
|||
|
|||
protected GroundTruthCrossPipelinePass(Camera targetCamera) |
|||
{ |
|||
this.targetCamera = targetCamera; |
|||
} |
|||
|
|||
public virtual void Setup() |
|||
{ |
|||
if (targetCamera == null) |
|||
throw new InvalidOperationException("targetCamera may not be null"); |
|||
|
|||
// If we are forced to activate here we will get zeroes in the first frame.
|
|||
EnsureActivated(); |
|||
} |
|||
|
|||
public void Execute( |
|||
ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult) |
|||
{ |
|||
// CustomPasses are executed for each camera. We only want to run for the target camera
|
|||
if (camera != targetCamera) |
|||
return; |
|||
|
|||
ExecutePass(renderContext, cmd, camera, cullingResult); |
|||
} |
|||
|
|||
protected abstract void ExecutePass( |
|||
ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult); |
|||
|
|||
public void EnsureActivated() |
|||
{ |
|||
if (!m_IsActivated) |
|||
{ |
|||
LabeledObjectsManager.singleton.Activate(this); |
|||
m_IsActivated = true; |
|||
} |
|||
} |
|||
|
|||
public void Cleanup() |
|||
{ |
|||
LabeledObjectsManager.singleton.Deactivate(this); |
|||
} |
|||
|
|||
protected RendererListDesc CreateRendererListDesc( |
|||
Camera camera, |
|||
CullingResults cullingResult, |
|||
string overrideMaterialPassName, |
|||
int overrideMaterialPassIndex, |
|||
Material overrideMaterial, |
|||
LayerMask layerMask) |
|||
{ |
|||
var shaderPasses = new[] |
|||
{ |
|||
new ShaderTagId("Forward"), // HD Lit shader
|
|||
new ShaderTagId("ForwardOnly"), // HD Unlit shader
|
|||
new ShaderTagId("SRPDefaultUnlit"), // Cross SRP Unlit shader
|
|||
new ShaderTagId("UniversalForward"), // URP Forward
|
|||
new ShaderTagId("LightweightForward"), // LWRP Forward
|
|||
new ShaderTagId(overrideMaterialPassName), // The override material shader
|
|||
}; |
|||
|
|||
var stateBlock = new RenderStateBlock(0) |
|||
{ |
|||
depthState = new DepthState(true, CompareFunction.LessEqual), |
|||
}; |
|||
|
|||
var result = new RendererListDesc(shaderPasses, cullingResult, camera) |
|||
{ |
|||
rendererConfiguration = PerObjectData.None, |
|||
renderQueueRange = new RenderQueueRange { lowerBound = 0, upperBound = 5000 }, |
|||
sortingCriteria = SortingCriteria.CommonOpaque, |
|||
excludeObjectMotionVectors = false, |
|||
overrideMaterial = overrideMaterial, |
|||
overrideMaterialPassIndex = overrideMaterialPassIndex, |
|||
stateBlock = stateBlock, |
|||
layerMask = layerMask, |
|||
}; |
|||
return result; |
|||
} |
|||
|
|||
protected static void DrawRendererList( |
|||
ScriptableRenderContext renderContext, CommandBuffer cmd, RendererList rendererList) |
|||
{ |
|||
if (!rendererList.isValid) |
|||
throw new ArgumentException("Invalid renderer list provided to DrawRendererList"); |
|||
|
|||
// This is done here because DrawRenderers API lives outside command buffers so we need to call this before
|
|||
// doing any DrawRenders or things will be executed out of order
|
|||
renderContext.ExecuteCommandBuffer(cmd); |
|||
cmd.Clear(); |
|||
|
|||
if (rendererList.stateBlock == null) |
|||
renderContext.DrawRenderers( |
|||
rendererList.cullingResult, ref rendererList.drawSettings, ref rendererList.filteringSettings); |
|||
else |
|||
{ |
|||
var renderStateBlock = rendererList.stateBlock.Value; |
|||
renderContext.DrawRenderers( |
|||
rendererList.cullingResult, |
|||
ref rendererList.drawSettings, |
|||
ref rendererList.filteringSettings, |
|||
ref renderStateBlock); |
|||
} |
|||
} |
|||
|
|||
public abstract void SetupMaterialProperties( |
|||
MaterialPropertyBlock mpb, Renderer meshRenderer, Labeling labeling, uint instanceId); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: eb908f4c6443439287819c85e91cfea0 |
|||
timeCreated: 1615084059 |
|
|||
using System; |
|||
using Unity.Profiling; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
class InstanceSegmentationCrossPipelinePass : GroundTruthCrossPipelinePass |
|||
{ |
|||
static readonly int k_SegmentationIdProperty = Shader.PropertyToID("_SegmentationId"); |
|||
const string k_SegmentationPassShaderName = "Perception/InstanceSegmentation"; |
|||
|
|||
static ProfilerMarker s_ExecuteMarker = new ProfilerMarker("SegmentationPass_Execute"); |
|||
|
|||
/// <summary>
|
|||
/// The LayerMask to apply when rendering objects.
|
|||
/// </summary>
|
|||
LayerMask m_LayerMask = -1; |
|||
|
|||
Shader m_SegmentationShader; |
|||
Material m_OverrideMaterial; |
|||
|
|||
/// <summary>
|
|||
/// Create a new <see cref="InstanceSegmentationCrossPipelinePass"/> referencing the given
|
|||
/// </summary>
|
|||
/// <param name="targetCamera"></param>
|
|||
/// <exception cref="ArgumentNullException"></exception>
|
|||
public InstanceSegmentationCrossPipelinePass(Camera targetCamera) |
|||
: base(targetCamera) |
|||
{ |
|||
if (targetCamera == null) |
|||
throw new ArgumentNullException(nameof(targetCamera)); |
|||
|
|||
//Activating in the constructor allows us to get correct labeling in the first frame.
|
|||
EnsureActivated(); |
|||
} |
|||
|
|||
public override void Setup() |
|||
{ |
|||
base.Setup(); |
|||
m_SegmentationShader = Shader.Find(k_SegmentationPassShaderName); |
|||
var shaderVariantCollection = new ShaderVariantCollection(); |
|||
shaderVariantCollection.Add( |
|||
new ShaderVariantCollection.ShaderVariant(m_SegmentationShader, PassType.ScriptableRenderPipeline)); |
|||
shaderVariantCollection.WarmUp(); |
|||
|
|||
m_OverrideMaterial = new Material(m_SegmentationShader); |
|||
} |
|||
|
|||
protected override void ExecutePass( |
|||
ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult) |
|||
{ |
|||
using (s_ExecuteMarker.Auto()) |
|||
{ |
|||
// Render all objects to our target RenderTexture using `m_OverrideMaterial` to use our shader
|
|||
cmd.ClearRenderTarget(true, true, Color.black); |
|||
var result = CreateRendererListDesc( |
|||
camera, cullingResult, "FirstPass", 0, m_OverrideMaterial, m_LayerMask); |
|||
|
|||
DrawRendererList(renderContext, cmd, RendererList.Create(result)); |
|||
} |
|||
} |
|||
|
|||
public override void SetupMaterialProperties( |
|||
MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId) |
|||
{ |
|||
var found = InstanceIdToColorMapping.TryGetColorFromInstanceId(instanceId, out var color); |
|||
if (!found) |
|||
Debug.LogError($"Could not get a unique color for {instanceId}"); |
|||
|
|||
mpb.SetVector(k_SegmentationIdProperty, (Color)color); |
|||
#if PERCEPTION_DEBUG
|
|||
Debug.Log($"Assigning id. Frame {Time.frameCount} id {id}"); |
|||
#endif
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 421bd5b3d054425d89dfc7c37e8b7575 |
|||
timeCreated: 1615074762 |
|
|||
using System; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
/// <summary>
|
|||
/// Custom Pass which renders labeled images where each object labeled with a Labeling component is drawn with the
|
|||
/// value specified by the given LabelingConfiguration.
|
|||
/// </summary>
|
|||
class SemanticSegmentationCrossPipelinePass : GroundTruthCrossPipelinePass |
|||
{ |
|||
const string k_ShaderName = "Perception/SemanticSegmentation"; |
|||
static readonly int k_LabelingId = Shader.PropertyToID("LabelingId"); |
|||
|
|||
static int s_LastFrameExecuted = -1; |
|||
|
|||
SemanticSegmentationLabelConfig m_LabelConfig; |
|||
|
|||
// NOTICE: Serialize the shader so that the shader asset is included in player builds when the SemanticSegmentationPass is used.
|
|||
// Currently commented out and shaders moved to Resources folder due to serialization crashes when it is enabled.
|
|||
// See https://fogbugz.unity3d.com/f/cases/1187378/
|
|||
// [SerializeField]
|
|||
Shader m_ClassLabelingShader; |
|||
Material m_OverrideMaterial; |
|||
|
|||
public SemanticSegmentationCrossPipelinePass( |
|||
Camera targetCamera, SemanticSegmentationLabelConfig labelConfig) : base(targetCamera) |
|||
{ |
|||
m_LabelConfig = labelConfig; |
|||
} |
|||
|
|||
public override void Setup() |
|||
{ |
|||
base.Setup(); |
|||
m_ClassLabelingShader = Shader.Find(k_ShaderName); |
|||
|
|||
var shaderVariantCollection = new ShaderVariantCollection(); |
|||
|
|||
if (shaderVariantCollection != null) |
|||
{ |
|||
shaderVariantCollection.Add( |
|||
new ShaderVariantCollection.ShaderVariant(m_ClassLabelingShader, PassType.ScriptableRenderPipeline)); |
|||
} |
|||
|
|||
m_OverrideMaterial = new Material(m_ClassLabelingShader); |
|||
|
|||
shaderVariantCollection.WarmUp(); |
|||
} |
|||
|
|||
protected override void ExecutePass( |
|||
ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult) |
|||
{ |
|||
if (s_LastFrameExecuted == Time.frameCount) |
|||
return; |
|||
|
|||
s_LastFrameExecuted = Time.frameCount; |
|||
var renderList = CreateRendererListDesc(camera, cullingResult, "FirstPass", 0, m_OverrideMaterial, -1); |
|||
cmd.ClearRenderTarget(true, true, Color.black); |
|||
DrawRendererList(renderContext, cmd, RendererList.Create(renderList)); |
|||
} |
|||
|
|||
public override void SetupMaterialProperties( |
|||
MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId) |
|||
{ |
|||
var entry = new SemanticSegmentationLabelEntry(); |
|||
var found = false; |
|||
foreach (var l in m_LabelConfig.labelEntries) |
|||
{ |
|||
if (labeling.labels.Contains(l.label)) |
|||
{ |
|||
entry = l; |
|||
found = true; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
// Set the labeling ID so that it can be accessed in ClassSemanticSegmentationPass.shader
|
|||
if (found) |
|||
mpb.SetVector(k_LabelingId, entry.color); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0d7678390ae7b4844ad760a9e39dfd7d |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: b575537c5b92d6949bb233707280a614 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.Profiling; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
class InstanceSegmentationCrossPipelinePass : GroundTruthCrossPipelinePass |
|||
{ |
|||
static readonly int k_SegmentationIdProperty = Shader.PropertyToID("_SegmentationId"); |
|||
const string k_SegmentationPassShaderName = "Perception/InstanceSegmentation"; |
|||
|
|||
static ProfilerMarker s_ExecuteMarker = new ProfilerMarker("SegmentationPass_Execute"); |
|||
|
|||
/// <summary>
|
|||
/// The LayerMask to apply when rendering objects.
|
|||
/// </summary>
|
|||
public LayerMask layerMask = -1; |
|||
|
|||
Shader m_SegmentationShader; |
|||
Material m_OverrideMaterial; |
|||
|
|||
/// <summary>
|
|||
/// Create a new <see cref="InstanceSegmentationCrossPipelinePass"/> referencing the given
|
|||
/// </summary>
|
|||
/// <param name="targetCamera"></param>
|
|||
/// <exception cref="ArgumentNullException"></exception>
|
|||
public InstanceSegmentationCrossPipelinePass(Camera targetCamera) |
|||
: base(targetCamera) |
|||
{ |
|||
if (targetCamera == null) |
|||
throw new ArgumentNullException(nameof(targetCamera)); |
|||
|
|||
//Activating in the constructor allows us to get correct labeling in the first frame.
|
|||
EnsureActivated(); |
|||
} |
|||
|
|||
public override void Setup() |
|||
{ |
|||
base.Setup(); |
|||
m_SegmentationShader = Shader.Find(k_SegmentationPassShaderName); |
|||
var shaderVariantCollection = new ShaderVariantCollection(); |
|||
shaderVariantCollection.Add(new ShaderVariantCollection.ShaderVariant(m_SegmentationShader, PassType.ScriptableRenderPipeline)); |
|||
shaderVariantCollection.WarmUp(); |
|||
|
|||
m_OverrideMaterial = new Material(m_SegmentationShader); |
|||
} |
|||
|
|||
//Render all objects to our target RenderTexture using `overrideMaterial` to use our shader
|
|||
protected override void ExecutePass(ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult) |
|||
{ |
|||
using (s_ExecuteMarker.Auto()) |
|||
{ |
|||
cmd.ClearRenderTarget(true, true, Color.black); |
|||
var result = CreateRendererListDesc(camera, cullingResult, "FirstPass", 0, m_OverrideMaterial, layerMask); |
|||
|
|||
DrawRendererList(renderContext, cmd, RendererList.Create(result)); |
|||
} |
|||
} |
|||
|
|||
public override void SetupMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId) |
|||
{ |
|||
var found = InstanceIdToColorMapping.TryGetColorFromInstanceId(instanceId, out var color); |
|||
|
|||
if (!found) |
|||
{ |
|||
Debug.LogError($"Could not get a unique color for {instanceId}"); |
|||
} |
|||
|
|||
mpb.SetVector(k_SegmentationIdProperty, (Color)color); |
|||
#if PERCEPTION_DEBUG
|
|||
Debug.Log($"Assigning id. Frame {Time.frameCount} id {id}"); |
|||
#endif
|
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
/// <summary>
|
|||
/// Custom Pass which renders labeled images where each object labeled with a Labeling component is drawn with the
|
|||
/// value specified by the given LabelingConfiguration.
|
|||
/// </summary>
|
|||
class SemanticSegmentationCrossPipelinePass : GroundTruthCrossPipelinePass |
|||
{ |
|||
const string k_ShaderName = "Perception/SemanticSegmentation"; |
|||
static readonly int k_LabelingId = Shader.PropertyToID("LabelingId"); |
|||
|
|||
static int s_LastFrameExecuted = -1; |
|||
|
|||
SemanticSegmentationLabelConfig m_LabelConfig; |
|||
|
|||
//Serialize the shader so that the shader asset is included in player builds when the SemanticSegmentationPass is used.
|
|||
//Currently commented out and shaders moved to Resources folder due to serialization crashes when it is enabled.
|
|||
//See https://fogbugz.unity3d.com/f/cases/1187378/
|
|||
//[SerializeField]
|
|||
Shader m_ClassLabelingShader; |
|||
Material m_OverrideMaterial; |
|||
|
|||
public SemanticSegmentationCrossPipelinePass(Camera targetCamera, SemanticSegmentationLabelConfig labelConfig) : base(targetCamera) |
|||
{ |
|||
this.m_LabelConfig = labelConfig; |
|||
} |
|||
|
|||
public override void Setup() |
|||
{ |
|||
base.Setup(); |
|||
m_ClassLabelingShader = Shader.Find(k_ShaderName); |
|||
|
|||
var shaderVariantCollection = new ShaderVariantCollection(); |
|||
|
|||
if (shaderVariantCollection != null) |
|||
{ |
|||
shaderVariantCollection.Add(new ShaderVariantCollection.ShaderVariant(m_ClassLabelingShader, PassType.ScriptableRenderPipeline)); |
|||
} |
|||
|
|||
m_OverrideMaterial = new Material(m_ClassLabelingShader); |
|||
|
|||
shaderVariantCollection.WarmUp(); |
|||
} |
|||
|
|||
protected override void ExecutePass(ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult) |
|||
{ |
|||
if (s_LastFrameExecuted == Time.frameCount) |
|||
return; |
|||
|
|||
s_LastFrameExecuted = Time.frameCount; |
|||
var renderList = CreateRendererListDesc(camera, cullingResult, "FirstPass", 0, m_OverrideMaterial, -1); |
|||
cmd.ClearRenderTarget(true, true, Color.black); |
|||
DrawRendererList(renderContext, cmd, RendererList.Create(renderList)); |
|||
} |
|||
|
|||
public override void SetupMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId) |
|||
{ |
|||
var entry = new SemanticSegmentationLabelEntry(); |
|||
bool found = false; |
|||
foreach (var l in m_LabelConfig.labelEntries) |
|||
{ |
|||
if (labeling.labels.Contains(l.label)) |
|||
{ |
|||
entry = l; |
|||
found = true; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
//Set the labeling ID so that it can be accessed in ClassSemanticSegmentationPass.shader
|
|||
if (found) |
|||
mpb.SetVector(k_LabelingId, entry.color); |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
abstract class GroundTruthCrossPipelinePass : IGroundTruthGenerator |
|||
{ |
|||
public Camera targetCamera; |
|||
|
|||
bool m_IsActivated; |
|||
|
|||
protected GroundTruthCrossPipelinePass(Camera targetCamera) |
|||
{ |
|||
this.targetCamera = targetCamera; |
|||
} |
|||
|
|||
public virtual void Setup() |
|||
{ |
|||
if (targetCamera == null) |
|||
throw new InvalidOperationException("targetCamera may not be null"); |
|||
|
|||
// If we are forced to activate here we will get zeroes in the first frame.
|
|||
EnsureActivated(); |
|||
} |
|||
|
|||
public void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult) |
|||
{ |
|||
// CustomPasses are executed for each camera. We only want to run for the target camera
|
|||
if (camera != targetCamera) |
|||
return; |
|||
|
|||
ExecutePass(renderContext, cmd, camera, cullingResult); |
|||
} |
|||
|
|||
protected abstract void ExecutePass(ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult); |
|||
|
|||
public void EnsureActivated() |
|||
{ |
|||
if (!m_IsActivated) |
|||
{ |
|||
LabeledObjectsManager.singleton.Activate(this); |
|||
m_IsActivated = true; |
|||
} |
|||
} |
|||
|
|||
public void Cleanup() |
|||
{ |
|||
LabeledObjectsManager.singleton.Deactivate(this); |
|||
} |
|||
|
|||
protected RendererListDesc CreateRendererListDesc(Camera camera, CullingResults cullingResult, string overrideMaterialPassName, int overrideMaterialPassIndex, Material overrideMaterial, LayerMask layerMask /*, PerObjectData perObjectData*/) |
|||
{ |
|||
var shaderPasses = new[] |
|||
{ |
|||
new ShaderTagId("Forward"), // HD Lit shader
|
|||
new ShaderTagId("ForwardOnly"), // HD Unlit shader
|
|||
new ShaderTagId("SRPDefaultUnlit"), // Cross SRP Unlit shader
|
|||
new ShaderTagId("UniversalForward"), // URP Forward
|
|||
new ShaderTagId("LightweightForward"), // LWRP Forward
|
|||
new ShaderTagId(overrideMaterialPassName), // The override material shader
|
|||
}; |
|||
|
|||
var stateBlock = new RenderStateBlock(0) |
|||
{ |
|||
depthState = new DepthState(true, CompareFunction.LessEqual), |
|||
}; |
|||
|
|||
var result = new RendererListDesc(shaderPasses, cullingResult, camera) |
|||
{ |
|||
rendererConfiguration = PerObjectData.None, |
|||
renderQueueRange = new RenderQueueRange { lowerBound = 0, upperBound = 5000 }, |
|||
sortingCriteria = SortingCriteria.CommonOpaque, |
|||
excludeObjectMotionVectors = false, |
|||
overrideMaterial = overrideMaterial, |
|||
overrideMaterialPassIndex = overrideMaterialPassIndex, |
|||
stateBlock = stateBlock, |
|||
layerMask = layerMask, |
|||
}; |
|||
return result; |
|||
} |
|||
|
|||
public static void DrawRendererList(ScriptableRenderContext renderContext, CommandBuffer cmd, RendererList rendererList) |
|||
{ |
|||
if (!rendererList.isValid) |
|||
throw new ArgumentException("Invalid renderer list provided to DrawRendererList"); |
|||
|
|||
// This is done here because DrawRenderers API lives outside command buffers so we need to make call this before doing any DrawRenders or things will be executed out of order
|
|||
renderContext.ExecuteCommandBuffer(cmd); |
|||
cmd.Clear(); |
|||
|
|||
if (rendererList.stateBlock == null) |
|||
renderContext.DrawRenderers(rendererList.cullingResult, ref rendererList.drawSettings, ref rendererList.filteringSettings); |
|||
else |
|||
{ |
|||
var renderStateBlock = rendererList.stateBlock.Value; |
|||
renderContext.DrawRenderers(rendererList.cullingResult, ref rendererList.drawSettings, ref rendererList.filteringSettings, ref renderStateBlock); |
|||
} |
|||
} |
|||
|
|||
public abstract void SetupMaterialProperties(MaterialPropertyBlock mpb, Renderer meshRenderer, Labeling labeling, uint instanceId); |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue