浏览代码

#27: Parameterized tests to check RGB output

/0.9.0.preview.1_staging
GitHub Enterprise 3 年前
当前提交
ee130211
共有 6 个文件被更改,包括 225 次插入8 次删除
  1. 11
      TestProjects/PerceptionURP/Assets/Settings/UniversalRPAsset.asset
  2. 2
      TestProjects/PerceptionURP/ProjectSettings/QualitySettings.asset
  3. 8
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  4. 3
      com.unity.perception/Tests/Runtime/Unity.Perception.Runtime.Tests.asmdef
  5. 198
      com.unity.perception/Tests/Runtime/GroundTruthTests/RgbOutputTests.cs
  6. 11
      com.unity.perception/Tests/Runtime/GroundTruthTests/RgbOutputTests.cs.meta

11
TestProjects/PerceptionURP/Assets/Settings/UniversalRPAsset.asset


m_Script: {fileID: 11500000, guid: bf2edee5c58d82540a51f03df9d42094, type: 3}
m_Name: UniversalRPAsset
m_EditorClassIdentifier:
k_AssetVersion: 5
k_AssetVersion: 6
k_AssetPreviousVersion: 5
m_RendererType: 1
m_RendererData: {fileID: 0}

m_OpaqueDownsampling: 1
m_SupportsTerrainHoles: 1
m_SupportsHDR: 1
m_MSAA: 2
m_MSAA: 1
m_RenderScale: 1
m_MainLightRenderingMode: 1
m_MainLightShadowsSupported: 1

m_AdditionalLightShadowsSupported: 1
m_AdditionalLightsShadowmapResolution: 512
m_ShadowDistance: 50
m_ShadowCascades: 1
m_ShadowCascadeCount: 2
m_Cascade3Split: {x: 0.1, y: 0.3}
m_Cascade4Split: {x: 0.067, y: 0.2, z: 0.467}
m_ShadowDepthBias: 1
m_ShadowNormalBias: 1

m_MixedLightingSupported: 1
m_DebugLevel: 0
m_PostProcessingFeatureSet: 0
m_UseAdaptivePerformance: 1
m_ColorGradingMode: 0
m_ColorGradingLutSize: 32
m_ShadowType: 1

m_ShadowAtlasResolution: 256
m_ShaderVariantLogLevel: 0
m_VolumeFrameworkUpdateMode: 0
m_ShadowCascades: 1

2
TestProjects/PerceptionURP/ProjectSettings/QualitySettings.asset


skinWeights: 2
textureQuality: 0
anisotropicTextures: 1
antiAliasing: 2
antiAliasing: 0
softParticles: 0
softVegetation: 1
realtimeReflectionProbes: 1

8
com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs


SensorHandle m_SensorHandle;
Vector2 m_ScrollPosition;
internal Action<AsyncRequest<CaptureCamera.CaptureState>> RgbCaptureReadback = null;
#if URP_PRESENT
// only used to confirm that GroundTruthRendererFeature is present in URP
bool m_IsGroundTruthRendererFeaturePresent;

}
};
AsyncRequest<CaptureCamera.CaptureState> request;
CaptureCamera.Capture(cam, colorFunctor, forceFlip: ForceFlip.None);
request = CaptureCamera.Capture(cam, colorFunctor, forceFlip: ForceFlip.None);
CaptureCamera.Capture(cam, colorFunctor, flipY: flipY);
request = CaptureCamera.Capture(cam, colorFunctor, flipY: flipY);
RgbCaptureReadback?.Invoke(request);
Profiler.EndSample();
}

3
com.unity.perception/Tests/Runtime/Unity.Perception.Runtime.Tests.asmdef


"Unity.Perception.Runtime",
"Unity.Perception.Editor",
"Unity.Simulation.Core",
"Unity.Simulation.Capture",
"Unity.RenderPipelines.HighDefinition.Runtime",
"Unity.RenderPipelines.Universal.Runtime"
],

}
],
"noEngineReferences": false
}
}

198
com.unity.perception/Tests/Runtime/GroundTruthTests/RgbOutputTests.cs


using System;
using System.Collections;
using NUnit.Framework;
using Unity.Simulation;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.Rendering;
using UnityEngine.TestTools;
#if URP_PRESENT
using UnityEngine.Rendering.Universal;
#endif
#if HDRP_PRESENT
using UnityEngine.Rendering.HighDefinition;
#endif
namespace GroundTruthTests.RgbOutputTests
{
public abstract class RgbOutputTestBase : GroundTruthTestBase
{
internal static readonly Color32 clearPixelValue = new Color32(0, 0, 0, 0);
internal PerceptionCamera perceptionCamera;
[UnityTearDown]
public IEnumerator Teardown()
{
base.TearDown();
yield return new WaitForSeconds(2f);
}
internal IEnumerator GenerateRgbOutputAndValidateData(
Action<AsyncRequest<CaptureCamera.CaptureState>> validator = null
)
{
// Setup the readback
AsyncRequest<CaptureCamera.CaptureState> captureState = null;
void RgbCaptureReadback(AsyncRequest<CaptureCamera.CaptureState> request)
{
captureState = request;
}
perceptionCamera.RgbCaptureReadback += RgbCaptureReadback;
// Initialize camera and request a frame for readback
perceptionCamera.RequestCapture();
yield return null;
// perceptionCamera.RgbCaptureReadback -= RgbCaptureReadback;
// Preliminary check on capture
Assert.IsTrue(captureState.error == false, "Capture Request had an error.");
// Custom validation of the readback data
validator?.Invoke(captureState);
}
internal static int ImageToColorDistance(Color32 exemplar, byte[] inputs, int deviation)
{
var numItems = ArrayUtilities.Count(inputs);
var count = 0;
for (var i = 0; i < numItems; i += 4)
{
Color32 c;
c.r = inputs[i + 0];
c.g = inputs[i + 1];
c.b = inputs[i + 2];
c.a = inputs[i + 3];
var redDelta = Math.Abs(exemplar.r - c.r);
var greenDelta = Math.Abs(exemplar.g - c.g);
var blueDelta = Math.Abs(exemplar.b - c.b);
var alphaDelta = Math.Abs(exemplar.a - c.a);
if (redDelta > deviation || greenDelta > deviation || blueDelta > deviation || alphaDelta > deviation)
++count;
}
return count;
}
}
#if URP_PRESENT
public class UrpRgbOutputTests : RgbOutputTestBase
{
static UniversalRenderPipelineAsset urpAsset => GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset;
// Initial Project Settings
static int s_InitialMsaaSampleCount;
[OneTimeSetUp]
public void OneTimeSetup()
{
s_InitialMsaaSampleCount = urpAsset.msaaSampleCount;
}
[UnityTearDown]
public IEnumerator UrpTeardown()
{
base.TearDown();
// Reset project settings
urpAsset.msaaSampleCount = s_InitialMsaaSampleCount;
DatasetCapture.ResetSimulation();
yield return null;
}
#region MSAA Test
static MsaaQuality[] s_MSAAVariations = {
MsaaQuality.Disabled,
MsaaQuality._2x,
MsaaQuality._8x
};
[UnityTest]
public IEnumerator RgbOutput_MsaaVariation_IsNotEmpty(
[ValueSource(nameof(s_MSAAVariations))]
MsaaQuality msaa
)
{
// Setup the camera and scene
var camera = SetupCamera((cam =>
{
cam.captureRgbImages = true;
cam.captureTriggerMode = CaptureTriggerMode.Manual;
perceptionCamera = cam;
// Change the MSAA Graphics setting
urpAsset.msaaSampleCount = (int)msaa;
}));
AddTestObjectForCleanup(camera);
AddTestObjectForCleanup(TestHelper.CreateLabeledCube());
// Validate RGB output image by checking if its empty
yield return GenerateRgbOutputAndValidateData(
validator: (captureState) =>
{
// Check if color buffer is all zeros
var colorBuffer = ArrayUtilities.Cast<byte>(captureState.data.colorBuffer as Array);
var imageToColorDistance = ImageToColorDistance(clearPixelValue, colorBuffer, 0);
Assert.IsFalse(imageToColorDistance == 0, $"[URP] RGB Output was empty for MSAA (${msaa.ToString()})");
}
);
}
#endregion
}
#endif
#if HDRP_PRESENT
public class HdrpRgbOutputTests : RgbOutputTestBase
{
static HDRenderPipelineAsset urpAsset => GraphicsSettings.currentRenderPipeline as HDRenderPipelineAsset;
// Initial Project Settings
[OneTimeSetUp]
public void OneTimeSetup()
{
}
[UnityTearDown]
public IEnumerator UrpTeardown()
{
base.TearDown();
// Reset project settings
DatasetCapture.ResetSimulation();
yield return null;
}
#region Blank Image Test
[UnityTest]
public IEnumerator RgbOutput_DefaultProjectSettings_IsNotEmpty()
{
// Setup the camera and scene
var camera = SetupCamera((cam =>
{
cam.captureRgbImages = true;
cam.captureTriggerMode = CaptureTriggerMode.Manual;
perceptionCamera = cam;
}));
AddTestObjectForCleanup(camera);
AddTestObjectForCleanup(TestHelper.CreateLabeledCube());
// Validate RGB output image by checking if its empty
yield return GenerateRgbOutputAndValidateData(
validator: (captureState) =>
{
// Check if color buffer is all zeros
var colorBuffer = ArrayUtilities.Cast<byte>(captureState.data.colorBuffer as Array);
var imageToColorDistance = ImageToColorDistance(clearPixelValue, colorBuffer, 0);
Assert.IsFalse(imageToColorDistance == 0, $"[HDRP] RGB Output was empty for default project settings.");
}
);
}
#endregion
}
#endif
}

11
com.unity.perception/Tests/Runtime/GroundTruthTests/RgbOutputTests.cs.meta


fileFormatVersion: 2
guid: e1fdf6e94ce954f2f9af3f32c1a33810
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存