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

相关推荐
璞瑜无文24 分钟前
Unity 游戏开发之布局(二)
unity·c#·游戏引擎
高远-临客3 小时前
unity IL2CPP模式下中使用UMP插件打包后无法播放视频监控报错问题解决方案
android·unity·音视频
_Cherry|3 小时前
Unity中窗口调整
unity·c#·游戏引擎
_Cherry|8 小时前
Unity在屏幕上滑动
unity·游戏引擎
_Cherry|8 小时前
Unity中使用AVPRO播放视频
unity·c#·音视频
世洋Blog20 小时前
Unity中图片的内存中占用大小、AB占用大小、内存形式
unity·游戏引擎
熬夜敲代码的小N21 小时前
Unity热更新技术详解
unity·游戏引擎
地狱为王1 天前
Cesium for Unity 去除Cesium Logo
unity·游戏引擎·cesium
BuHuaX1 天前
Lua入门
开发语言·unity·junit·c#·游戏引擎·lua
wonder135791 天前
RectTransform位置计算方法和UI自适应
ui·unity·ugui