浏览代码

Added tests for RGB Output

/0.9.0.preview.1_staging
Aryan Mann 3 年前
当前提交
17894621
共有 6 个文件被更改,包括 259 次插入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. 232
      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
}
}

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


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
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;
#elif HDRP_PRESENT
using UnityEngine.Rendering.HighDefinition;
#endif
namespace GroundTruthTests
{
/// <summary>
/// Tests the captured RGB images across different Graphics/Editor/Project settings.
/// </summary>
/// <remarks>
/// Notes on adding new variations:
/// 1. URP and HDRP variations are handled independently (using conditional compilation)
/// as each of them has a separate RenderPipelineAsset (which contains project settings)
/// 2. OneTimeSetup and Teardown are used "reset" project values back to their original value
/// as changes to the Quality/Graphics settings would persist even after playmode and across tests.
/// 3. The <see cref="s_SceneVariations" /> dictionary maps names (so different variations show up clearly
/// in the TestRunner UI) to functors which change certain settings before a RGB Capture is requested.
/// 4. NUnit parallelizes the test runs which does not work well with Global Settings. You can use
/// "[[Parallelizable(ParallelScope.None)]" to prevent that
/// </remarks>
public class RGBOutputTests : GroundTruthTestBase
{
static readonly Color32 k_ClearPixelValue = new Color32(0, 0, 0, 0);
PerceptionCamera m_PerceptionCamera;
#region Common
[UnitySetUp]
public IEnumerator Setup()
{
SetupCamera((cam =>
{
cam.captureRgbImages = true;
cam.captureTriggerMode = CaptureTriggerMode.Manual;
m_PerceptionCamera = cam;
}));
AddTestObjectForCleanup(TestHelper.CreateLabeledCube());
yield return null;
}
static string GetSrpPrefix()
{
#if URP_PRESENT
return "[URP]";
#elif URP_PRESENT
return "[HDRP]";
#else
return "[Unknown]";
#endif
}
#endregion
#region URP Configuration
#if URP_PRESENT
// Project Settings (URP)
static UniversalRenderPipelineAsset s_UrpAsset;
static MsaaQuality s_InitialMsaaQuality;
[OneTimeSetUp]
public void OneTimeSetup()
{
s_UrpAsset = GetRpAsset();
s_InitialMsaaQuality = (MsaaQuality) s_UrpAsset.msaaSampleCount;
}
[UnityTearDown]
public IEnumerator RpTeardown()
{
TearDown();
// Reset project settings
s_UrpAsset.msaaSampleCount = (int) s_InitialMsaaQuality;
DatasetCapture.ResetSimulation();
yield return null;
}
static Dictionary<string, Action<PerceptionCamera>> s_SceneVariations = new Dictionary<string, Action<PerceptionCamera>>()
{
["Default Project Setup"] = ((camera) =>
{
s_UrpAsset.msaaSampleCount = (int)s_InitialMsaaQuality;
}),
["MSAA 2x"] = ((camera) =>
{
s_UrpAsset.msaaSampleCount = (int)MsaaQuality._2x;
}),
["MSAA Disabled"] = ((camera) =>
{
s_UrpAsset.msaaSampleCount = (int)MsaaQuality.Disabled;
})
};
static string[] sceneVariationKeys => s_SceneVariations.Keys.ToArray();
static UniversalRenderPipelineAsset GetRpAsset()
{
var urpAsset = GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset;
if (urpAsset == null)
Debug.LogError("URP Asset is null. Failing RGB Output tests.");
return urpAsset;
}
#endif
#endregion
#region HDRP Configuration
#if HDRP_PRESENT
// Project Settings (HDRP)
static HDRenderPipelineAsset s_HdrpAsset;
[OneTimeSetUp]
public void OneTimeSetup()
{
s_HdrpAsset = GetRpAsset();
// No variations for HDRP at the moment.
}
[TearDown]
public void RpTeardown()
{
base.TearDown();
// No variations for HDRP at the moment.
}
static Dictionary<string, Action<PerceptionCamera>> s_SceneVariations = new Dictionary<string, Action<PerceptionCamera>>()
{
["Default Project Setup"] = ((camera) => { }),
};
static string[] sceneVariationKeys => s_SceneVariations.Keys.ToArray();
static HDRenderPipelineAsset GetRpAsset()
{
var hdrpAsset = GraphicsSettings.currentRenderPipeline as HDRenderPipelineAsset;
if (hdrpAsset == null)
Debug.LogError("HDRP Asset is null. Failing RGB Output tests.");
return hdrpAsset;
}
#endif
#endregion
#region Tests
[UnityTest]
public IEnumerator RgbOutput_WithProjectSettingVariations_IsNotEmpty(
[ValueSource(nameof(sceneVariationKeys))]
string variationName
)
{
var variationFunctor = s_SceneVariations[variationName];
yield return RgbOutput_ParametricTest(cam =>
{
variationFunctor?.Invoke(cam);
}, captureState =>
{
var colorBuffer = ArrayUtilities.Cast<byte>(captureState.data.colorBuffer as Array);
var imageToColorDistance = ImageToColorDistance(k_ClearPixelValue, colorBuffer, 0);
Assert.IsFalse(imageToColorDistance == 0, $"{GetSrpPrefix()} RGB Output was empty for variation: {variationName}");
});
}
#endregion
#region Test Setup & Helpers
IEnumerator RgbOutput_ParametricTest(Action<PerceptionCamera> initSetup, Action<AsyncRequest<CaptureCamera.CaptureState>> validator)
{
// Setup the readback
AsyncRequest<CaptureCamera.CaptureState> captureState = null;
void RgbCaptureReadback(AsyncRequest<CaptureCamera.CaptureState> request)
{
captureState = request;
}
m_PerceptionCamera.RgbCaptureReadback += RgbCaptureReadback;
// Initialize camera and request a frame for readback
initSetup?.Invoke(m_PerceptionCamera);
// Need to do this for the updated ScriptableRenderPipelineAsset to take effect..
yield return new WaitForFixedUpdate();
m_PerceptionCamera.RequestCapture();
// Wait for the readback
while (captureState == null || captureState.completed == false)
{
yield return null;
}
m_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);
}
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;
}
#endregion
}
}

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


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