Unity升级管线的注意事项

Unity升级管线的注意事项

一月 18, 2022

升级渲染管线在PM中下载 Universal RP

材质记得替,不如会出现洋红色

使用的简单的建模工具

在pm包中有不错的东西

在游戏中进行简单的建模可以用ProBuilder和Polybrush这两个包进行修改地形的顶点

ProGrids做方格的校准

阴影部分

百人计划说的很详细了

简单着色样例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Shader "CustomLit"
{
Properties
{
_MainTex("主贴图", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
Tags
{
"LightMode" = "UniversalForward"
}
//Zwrite off
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag

#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
#pragma multi_compile _ Anti_Aliasing_ON

#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"

struct appdata
{
float4 vertex : POSITION;
float4 uv : TEXCOORD0;

};

struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float3 worldPos : TEXCOORD1;
};

sampler2D _MainTex;
float4 _MainTex_ST;

v2f vert(appdata v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);

return o;
}

float4 _Color;

float4 frag(v2f i) : SV_Target
{
float4 SHADOW_COORDS = TransformWorldToShadowCoord(i.worldPos);

Light mainLight = GetMainLight(SHADOW_COORDS);
half shadow = MainLightRealtimeShadow(SHADOW_COORDS);

return float4(shadow, shadow, shadow,1);
}
ENDHLSL
}
UsePass "Universal Render Pipeline/Lit/ShadowCaster"
//pass {
// Name "ShadowCast"

// Tags{ "LightMode" = "ShadowCaster" }
// HLSLPROGRAM
// #pragma vertex vert
// #pragma fragment frag
// #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

// struct appdata
// {
// float4 vertex : POSITION;
// };

// struct v2f
// {
// float4 pos : SV_POSITION;
// };

// sampler2D _MainTex;
// float4 _MainTex_ST;

// v2f vert(appdata v)
// {
// v2f o;
// o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
// return o;
// }
// float4 frag(v2f i) : SV_Target
// {
// float4 color;
// color.xyz = float3(0.0, 0.0, 0.0);
// return color;
// }
// ENDHLSL
//}
}
}

在这里插入图片描述

HDR解码函数

由于hlsl函数没有了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 half3 DecodeHDR    (half4 data, half4 decodeInstructions) {
// Take into account texture alpha if decodeInstructions.w is true(the alpha value affects the RGB channels)

half alpha = decodeInstructions.w * (data.a - 1.0) + 1.0 ;
// If Linear mode is not supported we can skip exponent part
#if defined (UNITY_COLORSPACE_GAMMA)
return (decodeInstructions.x * alpha) * data.rgb;
#else
#if defined (UNITY_USE_NATIVE_HDR)
return decodeInstructions.x * data.rgb;
// Multiplier for future HDRI relative to absolute conversion.
#else return (decodeInstructions.x * pow (alpha, decodeInstructions.y)) * data.rgb;
#endif
#endif
}