73 lines
2.5 KiB
Markdown
73 lines
2.5 KiB
Markdown
---
|
||
title: "URP (Universal Render Pipeline)"
|
||
type: concept
|
||
tags: [game-dev, rendering, unity, pipeline]
|
||
sources: [unity-shader-graph-artist]
|
||
last_updated: 2026-05-01
|
||
---
|
||
|
||
## Aliases
|
||
- Universal Render Pipeline
|
||
- URP
|
||
- LWRP(Legacy,URP 前身)
|
||
|
||
## Definition
|
||
|
||
URP(Universal Render Pipeline,通用渲染管线)是 Unity 的可编程渲染管线,取代了旧版 Built-in 渲染管线。专为跨平台(PC/Console/Mobile/VR)设计,通过 Shader Graph 和 Scriptable Renderer Feature 实现灵活的渲染效果定制。相比 HDRP 更轻量,适合需要多平台支持的项目。
|
||
|
||
## Core Architecture
|
||
|
||
### ScriptableRendererFeature 系统
|
||
URP 自定义通道的核心扩展点:
|
||
|
||
```csharp
|
||
// 必须使用 ScriptableRendererFeature + ScriptableRenderPass
|
||
public class MyRendererFeature : ScriptableRendererFeature
|
||
{
|
||
public override void Create() { _pass = new MyRenderPass(); }
|
||
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
|
||
=> renderer.EnqueuePass(_pass);
|
||
}
|
||
|
||
public class MyRenderPass : ScriptableRenderPass
|
||
{
|
||
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
|
||
{ /* 自定义渲染逻辑 */ }
|
||
}
|
||
```
|
||
|
||
### 关键约束
|
||
- **禁止使用** `OnRenderImage`(Built-in only)
|
||
- Shader Graph 必须设置正确的 URP Render Pipeline Asset
|
||
- URP 图形无法直接在 HDRP 中工作,需要 Porting
|
||
|
||
### 与 HDRP 的核心区别
|
||
|
||
| 特性 | URP | HDRP |
|
||
|------|-----|------|
|
||
| 目标平台 | PC/Console/Mobile/VR | PC/Console(高端) |
|
||
| 渲染质量 | 中等-高 | 极高(物理光照/光线追踪) |
|
||
| 自定义通道 API | `ScriptableRendererFeature` | `CustomPassVolume` |
|
||
| API 兼容性 | **不兼容** HDRP | **不兼容** URP |
|
||
|
||
## Shader Graph in URP
|
||
|
||
- Shader Graph 是 URP 材质创作的首选工具
|
||
- 节点自动映射到 URP 的光照模型
|
||
- 必须使用 Sub-Graph 封装可复用逻辑
|
||
- 暴露参数必须设置 Blackboard tooltip
|
||
|
||
## Performance
|
||
|
||
| 平台 | Fragment Pass 纹理采样上限 | ALU 上限 |
|
||
|------|--------------------------|---------|
|
||
| Mobile | ≤ 32 次/Fragment Pass | ≤ 60 条/不透明 Fragment |
|
||
| PC/Console | 无硬性上限,但 Frame Debugger 审计 | — |
|
||
|
||
## Connections
|
||
- [[Shader]] ← 渲染目标 ← URP
|
||
- [[UnityShaderGraphArtist]] ← 专精 ← URP
|
||
- [[HDRP]] ← 互补管线 ← URP(不兼容)
|
||
- [[ScriptableRenderPass]] ← 核心 API ← URP
|
||
- [[ScriptableRendererFeature]] ← 扩展机制 ← URP
|