浏览代码

Fix issues with orthographic views and points close to far plane

/keypoint_self_occlusion
Jon Hogins 3 年前
当前提交
d41df908
共有 3 个文件被更改,包括 27 次插入9 次删除
  1. 2
      com.unity.perception/Runtime/GroundTruth/Resources/KeypointDepthCheck.shader
  2. 11
      com.unity.perception/Runtime/GroundTruth/Resources/KeypointDepthCheckHDRP.shader
  3. 23
      com.unity.perception/Tests/Runtime/GroundTruthTests/KeypointGroundTruthTests.cs

2
com.unity.perception/Runtime/GroundTruth/Resources/KeypointDepthCheck.shader


Shader "Perception/KeypointDepthCheck"
Shader "Perception/KeypointDepthCheckOld"
{
Properties
{

11
com.unity.perception/Runtime/GroundTruth/Resources/KeypointDepthCheckHDRP.shader


float4 checkDepth = _KeypointCheckDepth.Load(float3(varyings.positionCS.xy, 0));
float depth = LoadCameraDepth(float2(checkPosition.x, _ScreenSize.y - checkPosition.y));
depth = LinearEyeDepth(depth, _ZBufferParams);
PositionInputs positionInputs = GetPositionInput(checkPosition, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V);
depth = positionInputs.linearDepth;
//encode and decode checkDepth to account for loss of precision with depth values close to far plane
float4 viewPos = mul(UNITY_MATRIX_I_VP, float4(positionInputs.positionWS.x, positionInputs.positionWS.y, checkDepth.x, 1.0));
float4 positionCheckWS = mul(UNITY_MATRIX_VP, viewPos);
//depth = LinearEyeDepth(depth, _ZBufferParams);
uint result = depth > checkDepth.x ? 1 : 0;
uint result = depth >= positionCheckWS.z ? 1 : 0;
return float4(result, result, result, 1);
}
#else

23
com.unity.perception/Tests/Runtime/GroundTruthTests/KeypointGroundTruthTests.cs


Global,
JointLabel
}
public enum ProjectionKind
{
Orthographic,
Projection
}
public static IEnumerable<(Vector3 origin, float checkDistance, float pointDistance, float cameraFieldOfView, bool expectOccluded)>
Keypoint_InsideBox_RespectsThreshold_TestCases()

0.005f,
1f,
false);
//larger value here for the occluded check due to lack of depth precision close to far plane.
//We choose to mark points not occluded when the point depth and geometry depth are the same in the depth buffer
0.1f,
0.2f,
1f,
2f,
1f,
true);
}

[ValueSource(nameof(Keypoint_InsideBox_RespectsThreshold_TestCases))]
(Vector3 origin, float checkDistance, float pointDistance, float cameraFieldOfView, bool expectOccluded) args,
[Values(CheckDistanceType.Global, CheckDistanceType.JointLabel)] CheckDistanceType checkDistanceType)
[Values(CheckDistanceType.Global, CheckDistanceType.JointLabel)] CheckDistanceType checkDistanceType,
[Values(ProjectionKind.Orthographic, ProjectionKind.Projection)] ProjectionKind projectionKind)
{
if (checkDistanceType == CheckDistanceType.JointLabel)
Assert.Inconclusive("Not yet implemented");

var camComponent = cam.GetComponent<Camera>();
camComponent.fieldOfView = args.cameraFieldOfView;
// camComponent.orthographic = true;
// camComponent.orthographicSize = .5f;
if (projectionKind == ProjectionKind.Orthographic)
{
camComponent.orthographic = true;
camComponent.orthographicSize = .5f;
}
var cube = TestHelper.CreateLabeledCube(scale: 1f, x: args.origin.x, y: args.origin.y, z: args.origin.z);
SetupCubeJoint(cube, template, "Center", 0f, 0f, -.5f + args.pointDistance);

AddTestObjectForCleanup(cam);
AddTestObjectForCleanup(cube);
// while (true)
//for (int i = 0; i < 10000; i++)
yield return null;
//force all async readbacks to complete

正在加载...
取消
保存