http://www.icpchaxun.com/video/1626255034097811456
新建工程,安裝Universal RP,我的Unity版本是2022.2
b5824a264b93e998486125b646dd9fb0
記得勾選DepthTexture和OpaqueTexture,之後會用到
6d79d05167688f35173f587d6f67b68b
7ccf19ddd865e678df070b249cd7a3c2
添加UV,法線等信息,用於後續計算
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD1;
float3 normal : TEXCOORD2;
float3 worldPos : TEXCOORD3;
float4 screenPos : TEXCOORD4;
float4 localPos : TEXCOORD5;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = TransformObjectToHClip(v.vertex.xyz);
o.uv = v.uv;
o.normal = TransformObjectToWorldNormal(v.normal);
o.worldPos = TransformObjectToWorld(v.vertex.xyz);
o.localPos = v.vertex;
o.screenPos = o.vertex;
#if UNITY_UV_STARTS_AT_TOP
o.screenPos.y *= -1;
#endif
return o;
}