UnityURP-SurfaceShaderSolution 使用教程
1. 项目的目录结构及介绍
UnityURP-SurfaceShaderSolution/
├── Assets/
│ ├── Shaders/
│ │ └── SurfaceShaderExample.shader
│ └── Materials/
│ └── SurfaceShaderExampleMaterial.mat
├── Packages/
│ └── manifest.json
├── ProjectSettings/
│ └── GraphicsSettings.asset
├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
- Assets/: 包含项目的主要资源文件,如 Shaders 和 Materials。
- Shaders/: 存放着色器文件,例如
SurfaceShaderExample.shader
。 - Materials/: 存放材质文件,例如
SurfaceShaderExampleMaterial.mat
。
- Shaders/: 存放着色器文件,例如
- Packages/: 包含项目的包管理文件
manifest.json
,用于管理项目的依赖包。 - ProjectSettings/: 包含项目的设置文件,例如
GraphicsSettings.asset
,用于配置渲染设置。 - .gitattributes: Git 属性设置文件。
- .gitignore: Git 忽略文件设置。
- LICENSE: 项目许可证文件。
- README.md: 项目说明文件。
2. 项目的启动文件介绍
项目的启动文件主要是 SurfaceShaderExample.shader
,这是一个示例着色器文件,展示了如何在 Unity URP 中使用表面着色器。
Shader "Custom/SurfaceShaderExample"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
3. 项目的配置文件介绍
项目的配置文件主要是 GraphicsSettings.asset
,位于 ProjectSettings/
目录下。这个文件用于配置 Unity 的图形渲染设置,包括渲染管线、着色器等。
globalSettings:
scriptableRenderPipeline:
- {fileID: 11500000, guid: 28e146b3b1b2d4d47b5f5b6e45f13c80, type: 2}
tierSettings:
- standard:
renderingPath: 1
useHDR: 1
useDepthTexture: 1
useOcclusionCulling: 1
lodBias: 1
maximumLODLevel: 0
particleRaycastBudget: 1024
asyncUploadTimeSlice: 2
asyncUploadBufferSize: 4
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
defaultRenderingLayerMask: 1
useScriptableRenderPipelineBatching: 0
transparencySortMode: 0
transparencySortAxis: {x: 0, y: 0, z: 1}
detailNormalMap: 0
billboardFaceCameraPos: 0
lineSpacing: 1
fog: 1
fogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
fogMode: 3
fogDensity: 0.01