08-01-2024 08:07 PM - edited 08-02-2024 02:05 AM
Hey, folks! I am not exactly HLSL-inclined, is there a way to reference the depth texture produced by DepthAPI in a way similar to the Scene Depth node for Shader Graph? We are attempting to use it directly for certain shader visuals rather than just the final occlusion too.
--
Question is resolved! I've received a response from the DepthAPI team - the following is the Custom Function code snippet for Shader Graph:
#pragma warning (disable : 3568)
#pragma multi_compile _ HARD_OCCLUSION SOFT_OCCLUSION
#ifndef SHADERGRAPH_PREVIEW
#include "Packages/com.meta.xr.sdk.core/Shaders/EnvironmentDepth/URP/EnvironmentOcclusionURP.hlsl"
#endif
void GetEnvironmentSceneDepth_float(float3 posWorld, out float environmentDepth) {
#ifndef SHADERGRAPH_PREVIEW
const float4 depthSpace = mul(_EnvironmentDepthReprojectionMatrices[unity_StereoEyeIndex], float4(posWorld, 1.0));
const float2 uvCoords = (depthSpace.xy / depthSpace.w + 1.0f) * 0.5f;
environmentDepth = SampleEnvironmentDepthLinear(uvCoords);
#else
environmentDepth = 0;
#endif
}
void GetEnvironmentSceneDepth_half(float3 posWorld, out float environmentDepth) {
#ifndef SHADERGRAPH_PREVIEW
const float4 depthSpace = mul(_EnvironmentDepthReprojectionMatrices[unity_StereoEyeIndex], float4(posWorld, 1.0));
const float2 uvCoords = (depthSpace.xy / depthSpace.w + 1.0f) * 0.5f;
environmentDepth = SampleEnvironmentDepthLinear(uvCoords);
#else
environmentDepth = 0;
#endif
}