I am working on an oculus quest app and am trying to get the depth texture but i get it only on the left eye. My guess is that its cause oculus quest using a screenspace-texture-array instead of a double wide render texture. Is there a way of defining the format of the depth texture using RenderTextureDescriptor? Any insight would be appreciated. Here are my example codes.
In the .cs:
private void Start()
{
this.gameObject.GetComponent<Camera>().depthTextureMode = DepthTextureMode.Depth;
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
Graphics.Blit(source, destination, fog);
}
And the shader:
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
uniform half4 _MainTex_ST;
UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthTexture);
uniform half4 _CameraDepthTexture_ST;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float2 scrPos : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata v)
{
v2f o;
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o)
o.vertex = UnityObjectToClipPos(v.vertex);
o.scrPos = TRANSFORM_TEX(v.uv, _CameraDepthTexture);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
float _DepthStart;
float _DepthDistance;
fixed4 frag(v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
fixed4 orCol = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, i.uv);
float depthValue = Linear01Depth(UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthTexture, i.uv).r) * _ProjectionParams.z;
depthValue = saturate((depthValue - _DepthStart) / _DepthDistance);
return fixed4(depthValue, depthValue, depthValue, 1);
}
ENDCG