Depth API 샘플 - 2024-Adoor/practice GitHub Wiki
https://github.com/oculus-samples/Unity-DepthAPI
Scenes
OcclusionToggler
이 씬은 오클루전 기능의 일반적인 설정과 다양한 모드 간 전환 방법을 보여줍니다.
컨트롤러의 A 버튼을 눌러 NoOcclusion, HardOcclusion, SoftOcclusion의 세 가지 모드를 전환하는 씬
오클루전 모드: 하드는 계단현상이 보이는 날카로운 처리, 소프트는 더 자원을 먹지만 부드럽게 처리
클래스 Meta.XR.Depth.EnvironmentDepthOcclusionControllerz
에
public void EnableOcclusionType(OcclusionType newOcclusionType, bool updateDepthTextureProvider = true)
전역적으로 바꿔주는 함수가 있다.
PerObjectOcclusion
위 씬처럼 직접 전환하는 대신 각 세 모드에 대한 오브젝트가 한번에 배치되어있는 씬
각 오브젝트에 OcculusionController 컴포넌트가 달려있고 모드 값이 유니티 에디터로 사전 설정되있다
거기에는 이 함수가 있다
private void UpdateMaterialKeywords()
{
switch (_occlusionType)
{
case OcclusionType.HardOcclusion:
_material.DisableKeyword(EnvironmentDepthOcclusionController.SoftOcclusionKeyword);
_material.EnableKeyword(EnvironmentDepthOcclusionController.HardOcclusionKeyword);
break;
case OcclusionType.SoftOcclusion:
_material.DisableKeyword(EnvironmentDepthOcclusionController.HardOcclusionKeyword);
_material.EnableKeyword(EnvironmentDepthOcclusionController.SoftOcclusionKeyword);
break;
default:
_material.DisableKeyword(EnvironmentDepthOcclusionController.HardOcclusionKeyword);
_material.DisableKeyword(EnvironmentDepthOcclusionController.SoftOcclusionKeyword);
break;
}
}
머티리얼에 직접 끄고 켜는 방식으로 할 수 있나 보다.
SceneAPIPlacement
Scene API를 이용해 표면에 포스터를 붙이는데, z-fightihg을 막기 위해 일정 거리를 띄우는 예제
값이 클수록 벽에서 멀어지고 카메라에 가까워지게 된다.
약 0.06의 값을 사용하는 것이 좋지만 값은 배치되는 콘텐츠 유형에 따라 달라질 수 있습니다.
// OcclusionDepthBias.cs
public void SetDepthBias(float value)
{
DepthBiasValue = value;
if (_materials.Count <= 0)
{
Debug.LogWarning("No materials found on object. This component will not do anything");
}
else
{
foreach (var material in _materials)
{
material.SetFloat("_EnvironmentDepthBias", DepthBiasValue);
}
}
}
HandsRemoval
손이 AR 물체를 가릴 때 기존 처리 대신 Hand Tracking을 이용해서 더 깔끔한 마스크를 얻어보려는 씬
// EnvironmentDepthTextureProvider.cs
public void RemoveHands(bool areHandsRemoved)
{
_areHandsRemoved = areHandsRemoved;
Utils.SetEnvironmentDepthHandRemoval(areHandsRemoved);
}