zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    EM and GMM(Code)
    EM and GMM(Theory)
    安装Sphere v2.7 遇到的问题
    pyqt的 .ui 转换为 .py 后的操作注意事项
    SVM入门(一)
    关于范数的理解
    快速排序的C语言实现
    QT编程环境搭建
    flex布局左边固定,右边自适应,右边内容超出会影响布局
    未知宽高的div怎么垂直水平居中
  • 原文地址:https://www.cnblogs.com/minggoddess/p/14532050.html
Copyright © 2011-2022 走看看