Closed GTD-Carthage closed 1 month ago
Hello,
Try this:
Create a subnode that looks like this:
The Custom Function node should accept an HLSL file and have these params:
Here's the HLSL code:
#pragma warning (disable : 3568)
#pragma multi_compile _ HARD_OCCLUSION SOFT_OCCLUSION
void GetEnvironmentSceneDepth_float(float3 posWorld, out float environmentDepth) {
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);
environmentDepth = 0;
}
void GetEnvironmentSceneDepth_half(float3 posWorld, out float environmentDepth) {
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);
environmentDepth = 0;
}
This will give you the linear depth value at a certain world position.
Thank you and for the quick response too! This works perfectly and is exactly what we want!
Hello all! I am hoping to reference the environment depth texture directly via Depth API to achieve certain shaders (namely in Shader Graph) - is there a way to access this and not just the occlusion result? Unfortunately, I am not exactly overly HLSL code inclined, thus trying to read all the includes at the moment is not working well for me.
We are hoping to get something similar to the result of Scene Depth node to control certain effects.