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

相关推荐
惊鸿醉5 小时前
Unity_JK框架【4】MonoSystem 和 协程工具类 的剖析与实践
游戏·unity·单例模式
FAREWELL0007513 小时前
Untiy基础学习(六)MonoBehaviour基类的简单介绍
学习·unity·游戏引擎
unityのkiven19 小时前
介绍Unity中的Dictionary
unity·游戏引擎
cwl722 天前
Unity WebGL、js发布交互
javascript·unity·webgl
雪下的新火2 天前
PBR材质-Unity/Blender/UE
unity·blender·材质·ue
KhalilRuan3 天前
Unity-Shader详解-其四
unity·游戏引擎
[abcdem]3 天前
Unity学习笔记二
笔记·学习·unity
太妃糖耶3 天前
URP - 深度图
unity·shader
大飞pkz4 天前
【Unity】使用XLua实现C#访问Lua文件
unity·c#·lua·c#访问lua
KhalilRuan4 天前
Unity-Shader详解-其三
unity·游戏引擎