ue对 scene depth的封装
SceneTexturesCommon.ush
float LookupDeviceZ( float2 ScreenUV )
{
//mg_hack
//return 1;
#if SCENE_TEXTURES_DISABLED
return FarDepthValue;
#elif (POST_PROCESS_MATERIAL || POST_PROCESS_MATERIAL_MOBILE) && !POST_PROCESS_AR_PASSTHROUGH
#if MOBILE_DEFERRED_SHADING
return Texture2DSample(MobileSceneTextures.SceneDepthAuxTexture, MobileSceneTextures.SceneDepthAuxTextureSampler, ScreenUV).r;
#else
// SceneDepth texture is not accessible during post-processing as we discard it at the end of mobile BasePass
// instead fetch DeviceZ from SceneColor.A
return Texture2DSample(MobileSceneTextures.SceneColorTexture, MobileSceneTextures.SceneColorTextureSampler, ScreenUV).a;
#endif
#elif COMPILER_GLSL_ES3_1 && PIXELSHADER
#if !OUTPUT_MOBILE_HDR
// Try framebuffer_fetch_depth_stencil to get the depth directly if the extension is available.
// We cannot fall back to fetching the alpha channel when MobileHDR=false because the alpha channel is only 8-bit.
return DepthbufferFetchES2();
#else
return FramebufferFetchES2().w;
#endif
#elif VULKAN_SUBPASS_DEPTHFETCH && PIXELSHADER
// Special intrinsic to read from the current depth buffer
return VulkanSubpassDepthFetch();
#elif (METAL_PROFILE && !MAC) && PIXELSHADER
return DepthbufferFetchES2();
#else
// native Depth buffer lookup
return Texture2DSampleLevel(MobileSceneTextures.SceneDepthTexture, MobileSceneTextures.SceneDepthTextureSampler, ScreenUV, 0).r;
#endif
}
/** Returns clip space W, which is world space distance along the View Z axis. Note if you need DeviceZ LookupDeviceZ() is the faster option */
float CalcSceneDepth(float2 ScreenUV)
{
#if SCENE_TEXTURES_DISABLED
return SCENE_TEXTURES_DISABLED_SCENE_DEPTH_VALUE;
#else
return ConvertFromDeviceZ(LookupDeviceZ(ScreenUV));
#endif
}
CalcSceneDepth
材质编辑器那边加的节点里面的代码是这个
CalcSceneDepth
相关节点有
sceneDetph
pixelDepth
SceneTexture:SceneDepth
DepthFade
https://docs.unrealengine.com/en-US/RenderingAndGraphics/Materials/ExpressionReference/Depth/index.html
浙公网安备 33010602011771号