浏览代码

moved and cleaned render passes

/main
sleal-unity 4 年前
当前提交
3715567c
共有 48 个文件被更改,包括 432 次插入159 次删除
  1. 73
      com.unity.perception/Runtime/GroundTruth/GroundTruthRendererFeature.cs
  2. 4
      com.unity.perception/Runtime/GroundTruth/IGroundTruthGenerator.cs
  3. 5
      com.unity.perception/Runtime/GroundTruth/LabeledObjectsManager.cs
  4. 25
      com.unity.perception/Runtime/GroundTruth/Labelers/SemanticSegmentationLabeler.cs
  5. 24
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera_InstanceSegmentation.cs
  6. 2
      com.unity.perception/Runtime/GroundTruth/PerceptionUpdater.cs
  7. 11
      com.unity.perception/Runtime/GroundTruth/RenderTextureReader.cs
  8. 12
      com.unity.perception/Runtime/GroundTruth/RenderedObjectInfo.cs
  9. 2
      com.unity.perception/Runtime/GroundTruth/RenderedObjectInfoGenerator.cs
  10. 29
      com.unity.perception/Runtime/GroundTruth/SimulationState.cs
  11. 4
      com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs
  12. 18
      com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs
  13. 2
      com.unity.perception/package.json
  14. 4
      com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/InstanceSegmentationPass.cs
  15. 5
      com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/SemanticSegmentationPass.cs
  16. 2
      com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/SemanticSegmentationCrossPipelinePass.cs.meta
  17. 2
      com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/SemanticSegmentationPass.cs.meta
  18. 3
      com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses.meta
  19. 11
      com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/InstanceSegmentationCrossPipelinePass.cs.meta
  20. 191
      com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/LensDistortionCrossPipelinePass.cs
  21. 3
      com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/LensDistortionCrossPipelinePass.cs.meta
  22. 3
      com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses.meta
  23. 3
      com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/GroundTruthPass.cs.meta
  24. 48
      com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/LensDistortionPass.cs
  25. 3
      com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses.meta
  26. 31
      com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/InstanceSegmentationUrpPass.cs
  27. 3
      com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/InstanceSegmentationUrpPass.cs.meta
  28. 31
      com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/LensDistortionUrpPass.cs
  29. 3
      com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/LensDistortionUrpPass.cs.meta
  30. 31
      com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/SemanticSegmentationUrpPass.cs
  31. 3
      com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/SemanticSegmentationUrpPass.cs.meta
  32. 0
      /com.unity.perception/Runtime/GroundTruth/RenderPasses.meta
  33. 0
      /com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/GroundTruthCrossPipelinePass.cs
  34. 0
      /com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/InstanceSegmentationCrossPipelinePass.cs
  35. 0
      /com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/SemanticSegmentationCrossPipelinePass.cs
  36. 0
      /com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/InstanceSegmentationPass.cs
  37. 0
      /com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/InstanceSegmentationPass.cs.meta
  38. 0
      /com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/LensDistortionPass.cs.meta
  39. 0
      /com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/SemanticSegmentationPass.cs
  40. 0
      /com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/GroundTruthCrossPipelinePass.cs.meta
  41. 0
      /com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/GroundTruthPass.cs
  42. 0
      /com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/SemanticSegmentationCrossPipelinePass.cs.meta
  43. 0
      /com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/SemanticSegmentationPass.cs.meta

73
com.unity.perception/Runtime/GroundTruth/GroundTruthRendererFeature.cs


using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
class InstanceSegmentationUrpPass : ScriptableRenderPass
{
InstanceSegmentationCrossPipelinePass m_InstanceSegmentationPass;
public InstanceSegmentationUrpPass(Camera camera, RenderTexture targetTexture)
{
m_InstanceSegmentationPass = new InstanceSegmentationCrossPipelinePass(camera);
ConfigureTarget(targetTexture, targetTexture.depthBuffer);
m_InstanceSegmentationPass.Setup();
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var commandBuffer = CommandBufferPool.Get(nameof(InstanceSegmentationUrpPass));
m_InstanceSegmentationPass.Execute(context, commandBuffer, renderingData.cameraData.camera, renderingData.cullResults);
CommandBufferPool.Release(commandBuffer);
}
public void Cleanup()
{
m_InstanceSegmentationPass.Cleanup();
}
}
class SemanticSegmentationUrpPass : ScriptableRenderPass
{
public SemanticSegmentationCrossPipelinePass m_SemanticSegmentationCrossPipelinePass;
public SemanticSegmentationUrpPass(Camera camera, RenderTexture targetTexture, SemanticSegmentationLabelConfig labelConfig)
{
m_SemanticSegmentationCrossPipelinePass = new SemanticSegmentationCrossPipelinePass(camera, labelConfig);
ConfigureTarget(targetTexture, targetTexture.depthBuffer);
m_SemanticSegmentationCrossPipelinePass.Setup();
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var commandBuffer = CommandBufferPool.Get(nameof(SemanticSegmentationUrpPass));
m_SemanticSegmentationCrossPipelinePass.Execute(context, commandBuffer, renderingData.cameraData.camera, renderingData.cullResults);
CommandBufferPool.Release(commandBuffer);
}
public void Cleanup()
{
m_SemanticSegmentationCrossPipelinePass.Cleanup();
}
}
class LensDistortionUrpPass : ScriptableRenderPass
{
public LensDistortionCrossPipelinePass m_LensDistortionCrossPipelinePass;
public LensDistortionUrpPass(Camera camera, RenderTexture targetTexture)
{
m_LensDistortionCrossPipelinePass = new LensDistortionCrossPipelinePass(camera, targetTexture);
ConfigureTarget(targetTexture, targetTexture.depthBuffer);
m_LensDistortionCrossPipelinePass.Setup();
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var commandBuffer = CommandBufferPool.Get(nameof(SemanticSegmentationUrpPass));
m_LensDistortionCrossPipelinePass.Execute(context, commandBuffer, renderingData.cameraData.camera, renderingData.cullResults);
CommandBufferPool.Release(commandBuffer);
}
public void Cleanup()
{
m_LensDistortionCrossPipelinePass.Cleanup();
}
}
public class GroundTruthRendererFeature : ScriptableRendererFeature
{
public override void Create() {}

4
com.unity.perception/Runtime/GroundTruth/IGroundTruthGenerator.cs


namespace UnityEngine.Perception.GroundTruth
{
/// <summary>
/// Interface for setting up Renderers for ground truth generation via <see cref="GroundTruthLabelSetupSystem"/>.
/// Interface for setting up Renderers for ground truth generation via <see cref="LabeledObjectsManager"/>.
/// Called by <see cref="GroundTruthLabelSetupSystem"/> when first registered or when a Labeling is created at runtime.
/// Called by <see cref="LabeledObjectsManager"/> when first registered or when a Labeling is created at runtime.
/// </summary>
/// <param name="mpb">The MaterialPropertyBlock for the given meshRenderer. Can be used to set properties for custom rendering.</param>
/// <param name="renderer">The Renderer under the given Labeling.</param>

5
com.unity.perception/Runtime/GroundTruth/LabeledObjectsManager.cs


namespace UnityEngine.Perception.GroundTruth
{
/// <summary>
///
/// Manages the registration of <see cref="Labeling"/> components
/// </summary>
public class LabeledObjectsManager
{

public IEnumerable<Labeling> registeredLabels => m_RegisteredLabels;
/// <summary>
/// Registers all pending labels. Called once per frame during LateUpdate by the PerceptionUpdater.
/// Registers all pending labels.
/// Called once per frame during LateUpdate by the <see cref="PerceptionUpdater"/>.
/// </summary>
public void RegisterPendingLabels()
{

25
com.unity.perception/Runtime/GroundTruth/Labelers/SemanticSegmentationLabeler.cs


using Unity.Simulation;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Profiling;
using UnityEngine.Rendering;
using UnityEngine.UI;
#if HDRP_PRESENT
using UnityEngine.Rendering.HighDefinition;

/// Labeler which generates a semantic segmentation image each frame. Each object is rendered to the semantic segmentation
/// image using the color associated with it based on the given <see cref="SemanticSegmentationLabelConfig"/>.
/// Semantic segmentation images are saved to the dataset in PNG format.
///
/// Only one SemanticSegmentationLabeler can render at once across all cameras.
/// </summary>
[Serializable]

{
get => "Generates a semantic segmentation image for each captured frame. Each object is rendered to the semantic segmentation image using the color associated with it based on this labeler's associated semantic segmentation label configuration. " +
"Semantic segmentation images are saved to the dataset in PNG format. " +
"Please note that only one " + this.GetType().Name + " can render at once across all cameras.";
"Please note that only one " + GetType().Name + " can render at once across all cameras.";
internal string m_SemanticSegmentationDirectory;
internal string semanticSegmentationDirectory;
/// <summary>
/// The id to associate with semantic segmentation annotations in the dataset.

AnnotationDefinition m_SemanticSegmentationAnnotationDefinition;
RenderTextureReader<Color32> m_SemanticSegmentationTextureReader;
internal bool m_fLensDistortionEnabled = false;
#if HDRP_PRESENT
#if HDRP_PRESENT
SemanticSegmentationPass m_SemanticSegmentationPass;
LensDistortionPass m_LensDistortionPass;
#elif URP_PRESENT

public SemanticSegmentationLabeler(SemanticSegmentationLabelConfig labelConfig, RenderTexture targetTextureOverride = null)
{
this.labelConfig = labelConfig;
this.m_TargetTextureOverride = targetTextureOverride;
m_TargetTextureOverride = targetTextureOverride;
}
[SuppressMessage("ReSharper", "InconsistentNaming")]

if (targetTexture.sRGB)
{
Debug.LogError("targetTexture supplied to SemanticSegmentationLabeler must be in Linear mode. Disabling labeler.");
this.enabled = false;
enabled = false;
}
var renderTextureDescriptor = new RenderTextureDescriptor(camWidth, camHeight, GraphicsFormat.R8G8B8A8_UNorm, 8);
targetTexture.descriptor = renderTextureDescriptor;

targetTexture.Create();
targetTexture.name = "Labeling";
m_SemanticSegmentationDirectory = k_SemanticSegmentationDirectory + Guid.NewGuid();
semanticSegmentationDirectory = k_SemanticSegmentationDirectory + Guid.NewGuid();
#if HDRP_PRESENT
var gameObject = perceptionCamera.gameObject;

name = "Lens Distortion Pass"
};
customPassVolume.customPasses.Add(m_LensDistortionPass);
m_fLensDistortionEnabled = true;
#elif URP_PRESENT
// Semantic Segmentation
m_SemanticSegmentationPass = new SemanticSegmentationUrpPass(myCamera, targetTexture, labelConfig);

m_LensDistortionPass = new LensDistortionUrpPass(myCamera, targetTexture);
perceptionCamera.AddScriptableRenderPass(m_LensDistortionPass);
m_fLensDistortionEnabled = true;
#endif
var specs = labelConfig.labelEntries.Select((l) => new SemanticSegmentationSpec()

if (!m_AsyncAnnotations.TryGetValue(frameCount, out var annotation))
return;
var datasetRelativePath = $"{m_SemanticSegmentationDirectory}/{k_SegmentationFilePrefix}{frameCount}.png";
var localPath = $"{Manager.Instance.GetDirectoryFor(m_SemanticSegmentationDirectory)}/{k_SegmentationFilePrefix}{frameCount}.png";
var datasetRelativePath = $"{semanticSegmentationDirectory}/{k_SegmentationFilePrefix}{frameCount}.png";
var localPath = $"{Manager.Instance.GetDirectoryFor(semanticSegmentationDirectory)}/{k_SegmentationFilePrefix}{frameCount}.png";
annotation.ReportFile(datasetRelativePath);

24
com.unity.perception/Runtime/GroundTruth/PerceptionCamera_InstanceSegmentation.cs


using System;
using System.Collections.Generic;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Rendering.Universal;
using UnityEngine.Rendering.Universal;
#endif
namespace UnityEngine.Perception.GroundTruth

RenderTexture m_InstanceSegmentationTexture;
RenderTextureReader<Color32> m_InstanceSegmentationReader;
internal bool m_fLensDistortionEnabled = false;
private float? m_LensDistortionIntensityOverride;
#if HDRP_PRESENT
float? m_LensDistortionIntensityOverride;
#if HDRP_PRESENT
#elif URP_PRESENT
#elif URP_PRESENT
#endif
#endif
m_LensDistortionPass.m_LensDistortionCrossPipelinePass.lensDistortionOverride = intensity;
m_LensDistortionPass.lensDistortionCrossPipelinePass.lensDistortionOverride = intensity;
}
#endif

};
m_LensDistortionPass.EnsureInit();
customPassVolume.customPasses.Add(m_LensDistortionPass);
m_fLensDistortionEnabled = true;
#elif URP_PRESENT
m_InstanceSegmentationPass = new InstanceSegmentationUrpPass(myCamera, m_InstanceSegmentationTexture);
AddScriptableRenderPass(m_InstanceSegmentationPass);

AddScriptableRenderPass(m_LensDistortionPass);
m_fLensDistortionEnabled = true;
m_LensDistortionPass.m_LensDistortionCrossPipelinePass.lensDistortionOverride =
m_LensDistortionPass.lensDistortionCrossPipelinePass.lensDistortionOverride =
m_LensDistortionIntensityOverride;
#endif

2
com.unity.perception/Runtime/GroundTruth/PerceptionUpdater.cs


{
var updaterObject = new GameObject("PerceptionUpdater");
updaterObject.AddComponent<PerceptionUpdater>();
// updaterObject.hideFlags = HideFlags.HideAndDontSave;
updaterObject.hideFlags = HideFlags.HideAndDontSave;
DontDestroyOnLoad(updaterObject);
}

11
com.unity.perception/Runtime/GroundTruth/RenderTextureReader.cs


/// <param name="imageReadCallback">The callback to call after reading the texture</param>
public RenderTextureReader(RenderTexture source, Camera cameraRenderingToSource, Action<int, NativeArray<T>, RenderTexture> imageReadCallback)
{
this.m_Source = source;
this.m_ImageReadCallback = imageReadCallback;
this.m_CameraRenderingToSource = cameraRenderingToSource;
m_Source = source;
m_ImageReadCallback = imageReadCallback;
m_CameraRenderingToSource = cameraRenderingToSource;
m_NextFrameToCapture = Time.frameCount;
RenderPipelineManager.endFrameRendering += OnEndFrameRendering;

if (!GraphicsUtilities.SupportsAsyncReadback())
{
RenderTexture.active = m_Source;
m_CpuTexture.ReadPixels(new Rect(
Vector2.zero,
new Vector2(m_Source.width, m_Source.height)),

m_ImageReadCallback(Time.frameCount, data, m_Source);
return;
}
else
{

12
com.unity.perception/Runtime/GroundTruth/RenderedObjectInfo.cs


using System;
// ReSharper disable NonReadonlyMemberInGetHashCode
/// Describes an instance of an object in an instance segmentation frame. Generated by <see cref="RenderedObjectInfoGenerator"/>.
/// Describes an instance of an object in an instance segmentation frame.
/// Generated by <see cref="RenderedObjectInfoGenerator"/>.
/// </summary>
public struct RenderedObjectInfo : IEquatable<RenderedObjectInfo>
{

/// <inheritdoc />
public override string ToString()
{
return $"{nameof(instanceId)}: {instanceId}, {nameof(boundingBox)}: {boundingBox}, {nameof(pixelCount)}: {pixelCount}, {nameof(instanceColor)}: {instanceColor}";
return $"{nameof(instanceId)}: {instanceId}, {nameof(boundingBox)}: {boundingBox}, " +
$"{nameof(pixelCount)}: {pixelCount}, {nameof(instanceColor)}: {instanceColor}";
return instanceId == other.instanceId && boundingBox.Equals(other.boundingBox) && pixelCount == other.pixelCount;
return instanceId == other.instanceId &&
boundingBox.Equals(other.boundingBox) &&
pixelCount == other.pixelCount;
}
/// <inheritdoc />

{
unchecked
{
// ReSharper disable NonReadonlyMemberInGetHashCode
var hashCode = (int)instanceId;
hashCode = (hashCode * 397) ^ boundingBox.GetHashCode();
hashCode = (hashCode * 397) ^ pixelCount;

2
com.unity.perception/Runtime/GroundTruth/RenderedObjectInfoGenerator.cs


public int left;
public int right;
}
[BurstCompile]
struct ComputeHistogramPerRowJob : IJob
{

instanceId = 0,
row = row + rowStart
};
for (var i = 0; i < rowSlice.Length; i++)
{
var packed = InstanceIdToColorMapping.GetPackedColorFromColor(rowSlice[i]);

29
com.unity.perception/Runtime/GroundTruth/SimulationState.cs


using UnityEngine;
using UnityEngine.Profiling;
// ReSharper disable NotAccessedField.Local
// ReSharper disable NonReadonlyMemberInGetHashCode
namespace UnityEngine.Perception.GroundTruth
{
partial class SimulationState

HashSet<Guid> m_Ids = new HashSet<Guid>();
Guid m_SequenceId = Guid.NewGuid();
//Always use the property SequenceTimeMs instead
// Always use the property SequenceTimeMs instead
int m_FrameCountLastUpdatedSequenceTime;
float m_SequenceTimeDoNotUse;
float m_UnscaledSequenceTimeDoNotUse;

string m_OutputDirectoryPath;
public const string latestOutputDirectoryKey = "latestOutputDirectory";
JsonSerializer m_AnnotationSerializer;
public bool IsRunning { get; private set; }
public string OutputDirectory

public SimulationState(string outputDirectory)
{
m_AnnotationSerializer = JsonSerializer.CreateDefault();
m_AnnotationSerializer.Converters.Add(new Vector3Converter());
m_AnnotationSerializer.Converters.Add(new QuaternionConverter());
PlayerPrefs.SetString(latestOutputDirectoryKey, Manager.Instance.GetDirectoryFor("",""));
PlayerPrefs.SetString(latestOutputDirectoryKey, Manager.Instance.GetDirectoryFor());
IsRunning = true;
}

Values = values;
}
// ReSharper disable NotAccessedField.Local
public readonly SensorHandle SensorHandle;
public readonly SensorHandle SensorHandle;
public readonly Guid CaptureId;
public readonly Annotation Annotation;
public readonly Guid SequenceId;

{
unchecked
{
// ReSharper disable NonReadonlyMemberInGetHashCode
var hashCode = (name != null ? StringComparer.InvariantCulture.GetHashCode(name) : 0);
hashCode = (hashCode * 397) ^ (description != null ? StringComparer.InvariantCulture.GetHashCode(description) : 0);
hashCode = (hashCode * 397) ^ (format != null ? StringComparer.InvariantCulture.GetHashCode(format) : 0);

m_ActiveSensors.Add(sensorHandle);
}
void CheckDatasetAllowed()
static void CheckDatasetAllowed()
{
if (!Application.isPlaying)
{

if (m_Ids.Count == 0)
return;
WritePendingCaptures(true, writeCapturesFromThisFrame: true);
WritePendingCaptures(true, true);
if (m_PendingCaptures.Count > 0)
Debug.LogError($"Simulation ended with pending annotations: {string.Join(", ", m_PendingCaptures.Select(c => $"id:{c.SensorHandle.Id} frame:{c.FrameCount}"))}");

foreach (var value in values)
jArray.Add(new JRaw(DatasetJsonUtility.ToJToken(value)));
ReportAsyncAnnotationResult<T>(asyncAnnotation, filename, jArray);
ReportAsyncAnnotationResult(asyncAnnotation, filename, jArray);
}
[SuppressMessage("ReSharper", "PossibleInvalidOperationException")]

}
}
ReportAsyncAnnotationResult<T>(asyncAnnotation, filename, jArray);
ReportAsyncAnnotationResult(asyncAnnotation, filename, jArray);
void ReportAsyncAnnotationResult<T>(AsyncAnnotation asyncAnnotation, string filename, JArray jArray)
void ReportAsyncAnnotationResult(AsyncAnnotation asyncAnnotation, string filename, JArray jArray)
int annotationIndex = -1;
var annotationIndex = -1;
foreach (var c in m_PendingCaptures)
{
if (c.Step == asyncAnnotation.Annotation.Step && c.SensorHandle == asyncAnnotation.Annotation.SensorHandle)

4
com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs


{
var capturesPath = Path.Combine(DatasetCapture.OutputDirectory, "captures_000.json");
var capturesJson = File.ReadAllText(capturesPath);
var imagePath = $"{semanticSegmentationLabeler.m_SemanticSegmentationDirectory}/{expectedImageFilename}";
var imagePath = $"{semanticSegmentationLabeler.semanticSegmentationDirectory}/{expectedImageFilename}";
StringAssert.Contains(imagePath, capturesJson);
}
else

var capturesPath = Path.Combine(DatasetCapture.OutputDirectory, "captures_000.json");
var capturesJson = File.ReadAllText(capturesPath);
var imagePath = $"{semanticSegmentationLabeler.m_SemanticSegmentationDirectory}/{expectedImageFilename}";
var imagePath = $"{semanticSegmentationLabeler.semanticSegmentationDirectory}/{expectedImageFilename}";
StringAssert.Contains(imagePath, capturesJson);
}

18
com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs


if (frameStart == null || frameStart > frameCount) return;
timesSegmentationImageReceived++;
CollectionAssert.AreEqual(Enumerable.Repeat(expectedPixelValue, data.Length), data);
for (var i = 0; i < data.Length; i++)
Assert.AreEqual(expectedPixelValue, data[i]);
}
switch (segmentationKind)

void OnSegmentationImageReceived(NativeArray<Color32> data)
{
timesSegmentationImageReceived++;
CollectionAssert.AreEqual(Enumerable.Repeat(expectedPixelValue, data.Length), data);
for (var i = 0; i < data.Length; i++)
Assert.AreEqual(expectedPixelValue, data[i]);
}
var cameraObject = SetupCameraSemanticSegmentation(a => OnSegmentationImageReceived(a.data), false);

void OnSegmentationImageReceived(NativeArray<Color32> data)
{
timesSegmentationImageReceived++;
CollectionAssert.AreEqual(Enumerable.Repeat(expectedPixelValue, data.Length), data);
for (var i = 0; i < data.Length; i++)
Assert.AreEqual(expectedPixelValue, data[i]);
}
var cameraObject = SetupCameraSemanticSegmentation(a => OnSegmentationImageReceived(a.data), showVisualizations);

try
{
CollectionAssert.AreEqual(Enumerable.Repeat(expectedLabelAtFrame[frameCount], data.Length), data);
for (var i = 0; i < data.Length; i++)
Assert.AreEqual(expectedLabelAtFrame[frameCount], data[i]);
}
// ReSharper disable once RedundantCatchClause

}
var cameraObject = segmentationKind == SegmentationKind.Instance ?
SetupCameraInstanceSegmentation(OnSegmentationImageReceived<Color32>) :
SetupCameraSemanticSegmentation((a) => OnSegmentationImageReceived<Color32>(a.frameCount, a.data, a.sourceTexture), false);
SetupCameraInstanceSegmentation(OnSegmentationImageReceived) :
SetupCameraSemanticSegmentation((a) => OnSegmentationImageReceived(a.frameCount, a.data, a.sourceTexture), false);
object expectedPixelValue = segmentationKind == SegmentationKind.Instance ? (object) k_InstanceSegmentationPixelValue : k_SemanticPixelValue;
var expectedPixelValue = segmentationKind == SegmentationKind.Instance ? (object) k_InstanceSegmentationPixelValue : k_SemanticPixelValue;
expectedLabelAtFrame = new Dictionary<int, object>
{

2
com.unity.perception/package.json


{
"dependencies": {
"com.unity.burst": "1.4.6",
"com.unity.collections": "0.15.0-preview.21",
"com.unity.collections": "0.9.0-preview.6",
"com.unity.nuget.newtonsoft-json": "1.1.2",
"com.unity.render-pipelines.core": "7.1.6",
"com.unity.simulation.capture": "0.0.10-preview.19",

4
com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/InstanceSegmentationPass.cs


#if HDRP_PRESENT
using System;
using JetBrains.Annotations;
using UnityEngine.Rendering.HighDefinition;

public Camera targetCamera;
[UsedImplicitly]
public InstanceSegmentationPass()
{}
public InstanceSegmentationPass() {}
protected override void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResult)
{

5
com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/SemanticSegmentationPass.cs


#if HDRP_PRESENT
using System;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;

m_SemanticSegmentationCrossPipelinePass = new SemanticSegmentationCrossPipelinePass(targetCamera, semanticSegmentationLabelConfig);
m_SemanticSegmentationCrossPipelinePass.EnsureActivated();
}
}
public SemanticSegmentationPass()
{
}
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)

2
com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/SemanticSegmentationCrossPipelinePass.cs.meta


fileFormatVersion: 2
guid: 8a3f9f9754caf9c41a31f452c1426a2a
guid: cce1552fd4183b64f983461e6e07a317
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/SemanticSegmentationPass.cs.meta


fileFormatVersion: 2
guid: 892ef4062d56ed24e95ef548b42be343
guid: 84b5f1182e5f64c49954fc264cd2e46f
MonoImporter:
externalObjects: {}
serializedVersion: 2

3
com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses.meta


fileFormatVersion: 2
guid: ab58b1700a9642998cb3a5971f6543d1
timeCreated: 1615157471

11
com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/InstanceSegmentationCrossPipelinePass.cs.meta


fileFormatVersion: 2
guid: 799b5ba08ee3e6d479c2aac3a89507f0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

191
com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/LensDistortionCrossPipelinePass.cs


using System;
using UnityEngine.Rendering;
#if HDRP_PRESENT
using UnityEngine.Rendering.HighDefinition;
#elif URP_PRESENT
using UnityEngine.Rendering.Universal;
#endif
#if HDRP_PRESENT || URP_PRESENT
namespace UnityEngine.Perception.GroundTruth
{
/// <summary>
/// Custom Pass which will apply a lens distortion (per the respective volume override in URP or HDRP, or
/// through a custom override directly through the pass) to an incoming mask / texture. The purpose of this
/// is to allow the same lens distortion being applied to the RGB image in the perception camera to be applied
/// to the respective ground truths generated.
/// </summary>
class LensDistortionCrossPipelinePass : GroundTruthCrossPipelinePass
{
const string k_ShaderName = "Perception/LensDistortion";
// 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_LensDistortionShader;
Material m_LensDistortionMaterial;
bool m_Initialized;
static readonly int k_DistortionParams1Id = Shader.PropertyToID("_Distortion_Params1");
static readonly int k_DistortionParams2Id = Shader.PropertyToID("_Distortion_Params2");
LensDistortion m_LensDistortion;
internal float? lensDistortionOverride = null; // Largely for testing, but could be useful otherwise
RenderTexture m_TargetTexture;
RenderTexture m_DistortedTexture;
public LensDistortionCrossPipelinePass(Camera targetCamera, RenderTexture targetTexture)
: base(targetCamera)
{
m_TargetTexture = targetTexture;
}
public override void Setup()
{
base.Setup();
m_LensDistortionShader = Shader.Find(k_ShaderName);
var shaderVariantCollection = new ShaderVariantCollection();
if (shaderVariantCollection != null)
shaderVariantCollection.Add(new ShaderVariantCollection.ShaderVariant(m_LensDistortionShader, PassType.ScriptableRenderPipeline));
m_LensDistortionMaterial = new Material(m_LensDistortionShader);
if (shaderVariantCollection != null)
shaderVariantCollection.WarmUp();
// Set up a new texture
if (m_DistortedTexture == null || m_DistortedTexture.width != Screen.width || m_DistortedTexture.height != Screen.height)
{
if (m_DistortedTexture != null)
m_DistortedTexture.Release();
m_DistortedTexture = new RenderTexture(Screen.width, Screen.height, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
m_DistortedTexture.enableRandomWrite = true;
m_DistortedTexture.filterMode = FilterMode.Point;
m_DistortedTexture.Create();
}
// Grab the lens distortion
#if HDRP_PRESENT
// Grab the Lens Distortion from Perception Camera stack
var hdCamera = HDCamera.GetOrCreate(targetCamera);
var stack = hdCamera.volumeStack;
m_LensDistortion = stack.GetComponent<LensDistortion>();
#elif URP_PRESENT
var stack = VolumeManager.instance.stack;
m_LensDistortion = stack.GetComponent<LensDistortion>();
#endif
m_Initialized = true;
}
protected override void ExecutePass(ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult)
{
if (m_Initialized == false)
return;
if (SetLensDistortionShaderParameters() == false)
return;
// Blit mayhem
cmd.Blit(m_TargetTexture, m_DistortedTexture, m_LensDistortionMaterial);
cmd.Blit(m_DistortedTexture, m_TargetTexture);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Clear();
}
public bool SetLensDistortionShaderParameters()
{
if (m_Initialized == false)
return false;
// This code is lifted from the SetupLensDistortion() function in
// https://github.com/Unity-Technologies/Graphics/blob/257b08bba6c11de0f894e42e811124247a522d3c/com.unity.render-pipelines.universal/Runtime/Passes/PostProcessPass.cs
// This is in UnityEngine.Rendering.Universal.Internal.PostProcessPass::SetupLensDistortion so it's
// unclear how to re-use this code
var intensity = 0.5f;
var scale = 1.0f;
var center = new Vector2(0.0f, 0.0f);
var mult = new Vector2(1.0f, 1.0f);
#if HDRP_PRESENT
if(m_LensDistortion == null)
return false;
#elif URP_PRESENT
if (targetCamera == null)
return false;
var additionalCameraData = targetCamera.GetUniversalAdditionalCameraData();
if (additionalCameraData.renderPostProcessing == false && lensDistortionOverride.HasValue == false)
return false;
if (m_LensDistortion.active == false)
return false;
#else
return false;
#endif
if (lensDistortionOverride.HasValue)
{
intensity = lensDistortionOverride.Value;
}
else if (m_LensDistortion != null)
{
// This is a bit finicky for URP - since Lens Distortion comes off the VolumeManager stack as active
// even if post processing is not enabled. An intensity of 0.0f is untenable, so the below checks
// ensures post processing hasn't been enabled but Lens Distortion actually overriden
if (m_LensDistortion.intensity.value != 0.0f)
{
intensity = m_LensDistortion.intensity.value;
center = m_LensDistortion.center.value * 2f - Vector2.one;
mult.x = Mathf.Max(m_LensDistortion.xMultiplier.value, 1e-4f);
mult.y = Mathf.Max(m_LensDistortion.yMultiplier.value, 1e-4f);
scale = 1.0f / m_LensDistortion.scale.value;
}
else
{
return false;
}
}
var amount = 1.6f * Mathf.Max(Mathf.Abs(intensity * 100.0f), 1.0f);
var theta = Mathf.Deg2Rad * Mathf.Min(160f, amount);
var sigma = 2.0f * Mathf.Tan(theta * 0.5f);
var p1 = new Vector4(
center.x,
center.y,
mult.x,
mult.y
);
var p2 = new Vector4(
intensity >= 0f ? theta : 1f / theta,
sigma,
scale,
intensity * 100.0f
);
// Set Shader Constants
m_LensDistortionMaterial.SetVector(k_DistortionParams1Id, p1);
m_LensDistortionMaterial.SetVector(k_DistortionParams2Id, p2);
return true;
}
public override void SetupMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId)
{
SetLensDistortionShaderParameters();
}
}
}
#endif // ! HDRP_PRESENT || URP_PRESENT

3
com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/LensDistortionCrossPipelinePass.cs.meta


fileFormatVersion: 2
guid: 91d542be380c442186b86e0816a0c0fb
timeCreated: 1615157478

3
com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses.meta


fileFormatVersion: 2
guid: 3e921ed47cbb4b4daee97efd288b537e
timeCreated: 1615157360

3
com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/GroundTruthPass.cs.meta


fileFormatVersion: 2
guid: fce7b38cf56d40358e555bb2403b23d0
timeCreated: 1615157376

48
com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/LensDistortionPass.cs


#if HDRP_PRESENT
using System;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
namespace UnityEngine.Perception.GroundTruth
{
/// <summary>
/// Custom Pass which renders labeled images where each object with a Labeling component is drawn with the value
/// specified by the given LabelingConfiguration.
/// </summary>
public class LensDistortionPass : CustomPass
{
public RenderTexture targetTexture;
public Camera targetCamera;
internal LensDistortionCrossPipelinePass lensDistortionCrossPipelinePass;
public LensDistortionPass(Camera targetCamera, RenderTexture targetTexture)
{
this.targetTexture = targetTexture;
this.targetCamera = targetCamera;
EnsureInit();
}
public void EnsureInit()
{
if (lensDistortionCrossPipelinePass == null)
{
lensDistortionCrossPipelinePass = new LensDistortionCrossPipelinePass(targetCamera, targetTexture);
lensDistortionCrossPipelinePass.EnsureActivated();
}
}
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
{
EnsureInit();
lensDistortionCrossPipelinePass.Setup();
}
protected override void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResult)
{
CoreUtils.SetRenderTarget(cmd, targetTexture);
lensDistortionCrossPipelinePass.Execute(renderContext, cmd, hdCamera.camera, cullingResult);
}
}
}
#endif

3
com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses.meta


fileFormatVersion: 2
guid: 4cd6f632a845433cbbfc06263002654a
timeCreated: 1615157347

31
com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/InstanceSegmentationUrpPass.cs


#if URP_PRESENT
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace UnityEngine.Perception.GroundTruth
{
class InstanceSegmentationUrpPass : ScriptableRenderPass
{
InstanceSegmentationCrossPipelinePass m_InstanceSegmentationPass;
public InstanceSegmentationUrpPass(Camera camera, RenderTexture targetTexture)
{
m_InstanceSegmentationPass = new InstanceSegmentationCrossPipelinePass(camera);
ConfigureTarget(targetTexture, targetTexture.depthBuffer);
m_InstanceSegmentationPass.Setup();
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var commandBuffer = CommandBufferPool.Get(nameof(InstanceSegmentationUrpPass));
m_InstanceSegmentationPass.Execute(context, commandBuffer, renderingData.cameraData.camera, renderingData.cullResults);
CommandBufferPool.Release(commandBuffer);
}
public void Cleanup()
{
m_InstanceSegmentationPass.Cleanup();
}
}
}
#endif

3
com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/InstanceSegmentationUrpPass.cs.meta


fileFormatVersion: 2
guid: f8f08e25f7cb4355aa70060081bc4200
timeCreated: 1615156976

31
com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/LensDistortionUrpPass.cs


#if URP_PRESENT
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace UnityEngine.Perception.GroundTruth
{
class LensDistortionUrpPass : ScriptableRenderPass
{
public LensDistortionCrossPipelinePass lensDistortionCrossPipelinePass;
public LensDistortionUrpPass(Camera camera, RenderTexture targetTexture)
{
lensDistortionCrossPipelinePass = new LensDistortionCrossPipelinePass(camera, targetTexture);
ConfigureTarget(targetTexture, targetTexture.depthBuffer);
lensDistortionCrossPipelinePass.Setup();
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var commandBuffer = CommandBufferPool.Get(nameof(SemanticSegmentationUrpPass));
lensDistortionCrossPipelinePass.Execute(context, commandBuffer, renderingData.cameraData.camera, renderingData.cullResults);
CommandBufferPool.Release(commandBuffer);
}
public void Cleanup()
{
lensDistortionCrossPipelinePass.Cleanup();
}
}
}
#endif

3
com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/LensDistortionUrpPass.cs.meta


fileFormatVersion: 2
guid: db2ddd6b833f412bb68447d5f85eff4d
timeCreated: 1615157082

31
com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/SemanticSegmentationUrpPass.cs


#if URP_PRESENT
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace UnityEngine.Perception.GroundTruth
{
class SemanticSegmentationUrpPass : ScriptableRenderPass
{
public SemanticSegmentationCrossPipelinePass m_SemanticSegmentationCrossPipelinePass;
public SemanticSegmentationUrpPass(Camera camera, RenderTexture targetTexture, SemanticSegmentationLabelConfig labelConfig)
{
m_SemanticSegmentationCrossPipelinePass = new SemanticSegmentationCrossPipelinePass(camera, labelConfig);
ConfigureTarget(targetTexture, targetTexture.depthBuffer);
m_SemanticSegmentationCrossPipelinePass.Setup();
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var commandBuffer = CommandBufferPool.Get(nameof(SemanticSegmentationUrpPass));
m_SemanticSegmentationCrossPipelinePass.Execute(context, commandBuffer, renderingData.cameraData.camera, renderingData.cullResults);
CommandBufferPool.Release(commandBuffer);
}
public void Cleanup()
{
m_SemanticSegmentationCrossPipelinePass.Cleanup();
}
}
}
#endif

3
com.unity.perception/Runtime/GroundTruth/RenderPasses/UrpPasses/SemanticSegmentationUrpPass.cs.meta


fileFormatVersion: 2
guid: a16b614c904345fa8666f31f18a703af
timeCreated: 1615157147

/com.unity.perception/Runtime/GroundTruth/CustomPasses.meta → /com.unity.perception/Runtime/GroundTruth/RenderPasses.meta

/com.unity.perception/Runtime/GroundTruth/CustomPasses/GroundTruthCrossPipelinePass.cs → /com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/GroundTruthCrossPipelinePass.cs

/com.unity.perception/Runtime/GroundTruth/CustomPasses/InstanceSegmentationCrossPipelinePass.cs → /com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/InstanceSegmentationCrossPipelinePass.cs

/com.unity.perception/Runtime/GroundTruth/CustomPasses/SemanticSegmentationCrossPipelinePass.cs → /com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/SemanticSegmentationCrossPipelinePass.cs

/com.unity.perception/Runtime/GroundTruth/CustomPasses/InstanceSegmentationPass.cs → /com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/InstanceSegmentationPass.cs

/com.unity.perception/Runtime/GroundTruth/CustomPasses/InstanceSegmentationPass.cs.meta → /com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/InstanceSegmentationPass.cs.meta

/com.unity.perception/Runtime/GroundTruth/CustomPasses/LensDistortionPass.cs.meta → /com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/LensDistortionPass.cs.meta

/com.unity.perception/Runtime/GroundTruth/CustomPasses/SemanticSegmentationPass.cs → /com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/SemanticSegmentationPass.cs

/com.unity.perception/Runtime/GroundTruth/CustomPasses/GroundTruthCrossPipelinePass.cs.meta → /com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/GroundTruthCrossPipelinePass.cs.meta

/com.unity.perception/Runtime/GroundTruth/CustomPasses/GroundTruthPass.cs → /com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/GroundTruthPass.cs

/com.unity.perception/Runtime/GroundTruth/CustomPasses/SemanticSegmentationCrossPipelinePass.cs.meta → /com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/SemanticSegmentationCrossPipelinePass.cs.meta

/com.unity.perception/Runtime/GroundTruth/CustomPasses/SemanticSegmentationPass.cs.meta → /com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/SemanticSegmentationPass.cs.meta

正在加载...
取消
保存