[Shader] Depth Map
공부용으로 작성되는 페이지입니다. 틀린 부분이나 환경에 따라 오류가 발생할 수 있습니다.
Depth Map이란?
viewpoint(일반적으로 카메라)로부터 물체 표면과의 거리와 관련된 정보가 담긴 채널을 의미한다.
모션 트래킹할 때 사용하는 센서들도 보통 Depth Map 옵션을 가지고 있다.
일본어로는 深度マップ 이라고 하는등 결국 초첨은 '깊이' 이다.
Depth Map 뜯어보기
Depth Map의 경우 유니티 자체에 예제로 있기 때문에 오늘은 작성보다는 어떻게 구성되고 작동되는지를 공부하는데 초첨을 맞췄다.
우선 예제에서 복잡한 부분(체크 알고리즘)은 제외하고 Depth와 관련된 부분만 남겨서 정리하였다.
Properties
{ }
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
};
struct Varyings
{
float4 positionHCS : SV_POSITION;
};
Varyings vert(Attributes IN)
{
Varyings OUT;
OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
return OUT;
}
half4 frag(Varyings IN) : SV_Target
{
float2 UV = IN.positionHCS.xy / _ScaledScreenParams.xy;
#if UNITY_REVERSED_Z
real depth = SampleSceneDepth(UV);
#else
real depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, SampleSceneDepth(UV));
#endif
return half4(depth, depth, depth, 1);
}
ENDHLSL
}
}
이 파트를 따로 글을 썼었는데... 슬프게도 다 날아가버렸다.
요약하자면 SampleSceneDepth() 함수를 통해서 Depth값을 구하는 원리이므로
해당 함수가 포함되어있는 파일인 DeclareDepthTexture.hlsl을 반드시 include 해야한다.
ScriptableRendererFeature 작성하기
너무 길어서 따로 나눴다.
[Unity] ScriptableRendererFeature 작성하기
공부용으로 작성되는 페이지입니다. 틀린 부분이나 환경에 따라 오류가 발생할 수 있습니다. ScriptableRendererFeature?쉐이더를 작성하면서 ScriptableRendereFeature 부분이 길어져서 따로 작성하게 되었다
hungrykang.tistory.com
결과물
참고자료
URP에서 깊이를 기록하는 Depth Map 셰이더 만들어보기! + After Effect의 이미지의 레벨 조정(Levels adjustment) 흉내기기!
URP에서 깊이를 기록하는 Depth Map 셰이더 만들어보기! + After Effect의 이미지의 레벨 조정(Levels adjust
서론 Depth Map은 (카메라) 시점으로부터 물체 표면과의 거리와 관련된 정보가 담긴 Map을 의미한다 한국어로는 깊이 맵(Wikipedia에는 왠지 깊이 지도로 되어 있지만…)이라고도 하고, 일본어로는 深
wincnt-shim.tistory.com
Reconstruct the world space positions of pixels from the depth texture | Universal RP | 14.0.12