UnityURP 自定义PostProcess之深度图应用

UnityURP 自定义PostProcess之深度图

前言

Unity URP中利用深度图可以实现以下两种简单的效果,其他设置参考
UnityURP 自定义PostProcess


项目

Shader代码获取深度图

c 复制代码
Shader "CustomPost/URPScreenTintShader"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _OverlayColor ("Tint Color", Color) = (1,1,1,1)
        _Intensity ("Intensity", Range(0,1)) = 1
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalPipeline" }

        Pass
        {
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
                float2 uv : TEXCOORD0;
            };

            sampler2D _MainTex;
            float _Intensity;
            float4 _OverlayColor;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = TransformObjectToHClip(v.vertex);
                o.uv = v.uv;
                return o;
            }

            float4 frag (v2f i) : SV_Target
            {
                // 采样深度纹理
                float rawDepth = SampleSceneDepth(i.uv);
                
                // 转换为线性深度
                float depth = LinearEyeDepth(rawDepth, _ZBufferParams);
                
                float4 finalColor=half4(depth,depth,depth,1);
                return finalColor;
            }
            ENDHLSL
        }
    }
}

ASE连线获取深度图

相关推荐
老朱佩琪!2 小时前
Unity备忘录模式
java·unity·备忘录模式
一帘多啦A梦3 小时前
解决unity2022.3.x版本项目使用vs无法生成解决方案的问题
unity·vs
weixin_424294675 小时前
Unity LocalPosition 和 Position 的区别?还有其他的Position 没?
unity·游戏引擎
UX20176 小时前
Git LFS 管理 Unity 大文件
git·unity
nnsix6 小时前
Unity WebGL端调用Windows窗口选择文件
unity·游戏引擎·webgl
向宇it6 小时前
【unity游戏开发——网络】使用Unity+PurrNet+Heathens+Steam,在 Unity 中通过 Steam与你的朋友建立联系
网络·游戏·unity·c#·游戏引擎·steam
nnsix7 小时前
Unity 反编译dll(Windows平台)
unity
XR技术研习社7 小时前
四种安装特定版本Package的方法
unity·ar·xr·vr
dzj20218 小时前
Unity行为脚本与编辑器脚本的解耦例子之一
unity·解耦·编辑器脚本·行为脚本
小蜗 strong10 小时前
Unity中MRTK下载相关功能配置(适用HoloLens 2 部署)
unity·游戏引擎·hololens