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连线获取深度图

相关推荐
Madokaly7 小时前
DOTween的Vector3Plugin
unity
一梭键盘任平生18 小时前
Shader入门笔记2
unity
点心的游戏开发世界1 天前
Unity C# 脚本学习笔记:命名空间与 using
学习·unity·c#
点心的游戏开发世界1 天前
Unity C# 脚本学习笔记:泛型
学习·unity·c#
微三云生态系统架构师-彭丹3 天前
任务卷轴积分系统架构设计:从任务状态机到合规风控的完整实现
unity·系统架构·游戏引擎
XR技术研习社3 天前
从 PICO 文档看未来短期内的 Unity 版本选择
unity·游戏引擎·xr·vr
玖玥拾3 天前
Unity 热更新(一)
unity·游戏引擎
软件黑马王子3 天前
1.non-MonoBehaviour 单例模式泛型基类
unity·前端框架·c#
KhalilRuan3 天前
Unity性能优化
unity·性能优化·游戏引擎
ellis19703 天前
u3d IMGUI[二] 编辑器扩展
unity