각 픽셀에 고정밀도 뎁스 값이 포함된 렌더 텍스처를 만들 수 있습니다. 일부 효과에 씬의 뎁스가 필요한 경우 이 텍스처가 주로 사용됩니다. 예를 들어 소프트 파티클, 스크린 공간 앰비언트 오클루전 및 반투명에는 모두 씬의 뎁스가 필요합니다. 이미지 효과에도 뎁스 텍스처가 종종 사용됩니다.
픽셀 값은 0과 1 사이의 뎁스 텍스처 범위 안에 있고 비선형 분포를 나타냅니다. 정밀도는 설정과 사용 플랫폼에 따라 일반적으로 32 또는 16비트입니다. 뎁스 텍스처에서 읽는 경우 범위가 0과 1 사이인 고정밀도 값이 반환됩니다. 카메라와의 거리나 기타 리니어 0–1 값을 구해야 하는 경우 헬퍼 매크로를 사용하여 수동으로 계산해야 합니다(아래 참조).
뎁스 텍스처는 대부분의 최신 하드웨어 및 그래픽스 API에서 지원됩니다. 아래에는 특별한 요구 사항이 나열되어 있습니다.
뎁스 텍스처는 대부분의 경우 카메라에서 뎁스를 렌더링하는 데 사용됩니다. UnityCG.cginc 포함 파일에는 이 사례에서 위의 복잡성을 처리하는 매크로가 몇 개 있습니다.
참고: DX11/12, PS4, XboxOne 및 Metal에서 Z 버퍼 범위는 1–0이고 UNITY_REVERSED_Z가 정의됩니다. 다른 플랫폼에서 범위는 0–1입니다.
예를 들어, 다음 셰이더는 게임 오브젝트의 뎁스를 렌더링합니다.
Shader "Render Depth" {
SubShader {
Tags { "RenderType"="Opaque" }
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 depth : TEXCOORD0;
};
v2f vert (appdata_base v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
UNITY_TRANSFER_DEPTH(o.depth);
return o;
}
half4 frag(v2f i) : SV_Target {
UNITY_OUTPUT_DEPTH(i.depth);
}
ENDCG
}
}
}
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.