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

相关推荐
Cool-浩7 小时前
【征文计划】Rokid 语音指令开发教程 【包含工程源码 和体验包APK】
unity·ar·语音识别·rokid·语音指令
小剑修15 小时前
2025.10.18 复习
unity
future_studio2 天前
聊聊 Unity(小白专享、C# 小程序 之 播放器)
unity·小程序·c#
向宇it2 天前
【unity实战】MapMagic 2实战例子
游戏·3d·unity·c#·游戏引擎
SlowFeather2 天前
Unity TMP可控角度多色渐变文字
unity·游戏引擎
霜绛3 天前
Unity:UGUI笔记(一)——三大基础控件、组合控件
笔记·学习·unity·游戏引擎
小趴菜82273 天前
Android中加载unity aar包实现方案
android·unity·游戏引擎
今夕资源网3 天前
牛童三国单机游戏Unity源码 免费开源
游戏·unity·单机游戏·游戏源码·unity源码·unity游戏
future_studio3 天前
聊聊 Unity(小白专享、C# 小程序 之 图片播放器)
unity·小程序·c#
ellis19704 天前
toLua[七] Examples 06_LuaCoroutine2分析
unity