目录
二、Post Process 辉光Bloom效果 + 矩形渐隐
涉及知识点:Decal贴花、屏幕后处理Bloom、屏幕空间构建世界空间、ChracterController物体移动、Terrain地形创建
一、基础版
Unity 2019.4.0f1 普通渲染管线(非URP、非HDRP)
URP HDRP 在Unity 2021.2以上均可直接使用内置的贴花系统,具体网上有说明。
贴花物体是一个个Cube立方体,我将它拉长了Y轴 便于能接触到地面。
其中角色物体胶囊体要进行设置渲染层级,GetComponent<MeshRenderer>().material.renderQueue = 3001; //将人物放到贴花物体之后渲染,不被贴花物体影响
如这个Cube长方体就是红色边缘的Cube贴花,贴花颜色是红色。
贴花物体是透明层,不写入深度和深度检测,以及裁剪正面,不裁剪背面。
可参考:贴花(Decal)效果在Shader里是如何实现的_哔哩哔哩_bilibili
核心代码是DepthToWorldPosition,屏幕空间反向构建世界空间,很类似全局雾效,注意摄像机要开启深度贴图。摄像机挂上这个如下脚本设置:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OpenDepthTexture : MonoBehaviour
{
public DepthTextureMode mode;
private void Awake()
{
GetComponent<Camera>().depthTextureMode = mode;
}
}
Shader "Unlit/SimpleDecal"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
LOD 100
Pass
{
//Blend One DstAlpha
Blend SrcAlpha OneMinusSrcAlpha
//Blend One One
ZWrite Off
ZTest Off
Cull Front
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;