• 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

  • 相关阅读:
    09课堂问题整理
    08课堂问题整理
    Eclipse开发工具的编码问题
    【伸手党】需要我帮你Google/百度吗?
    IDEA更改左侧目录层级结构
    IDEA设置类和方法的注释
    一篇系列
    "Notice: unserialize(): Error at offset xx of xxx bytes"错误的处理(转载)
    git push命令每次都要输入用户名和密码的问题处理
    在网站添加qq客服功能
  • 原文地址:https://www.cnblogs.com/minggoddess/p/14532050.html
Copyright © 2020-2023  润新知