16. URP ShaderLibrary actual map: Lit-based include chain
The goal of this chapter is to help you answer the following questions “without losing track.”
- What paths (LightMode) does URP
Lit.shaderconsist of? - Which
.hlsldoes each pass include, and which entry functions (vertex/fragment) are defined there? - From which file do functions like
TransformObjectToHClip,GetMainLight,UniversalFragmentPBRcome from?
Very important
In URP, the file configuration/function names change slightly when the package version changes.
This document is designed to help you understand by fixing the “role/connection structure” based on **URP Lit, and to do the final verification using the local package source.
16.0 Accurate Reference (Generated, URP 17.3.0)
The “accuracy anchor” for this chapter is the automatic creation below.
- Lit Pass/Include Map (Stable): @@TOK_5_14164784@@
- Lit Pass/Include Map (Versioned): @@TOK_6_34501e9e@@
- Lit core symbol xref (definition/representation reference): @@TOK_7_8394c928@@
- Function signature index: @@TOK_8_20e1594e@@
- Structure index (including field list): @@TOK_9_11a7626e@@
Principle: For “Definition location (file/line)”, generated is the first correct answer.
The context (why it is implemented that way) is read by opening the local URP/Core source.
Predecessor:
16.1 First, let’s fix the version (the reality of “Unity 6.3”)
Unity 6.3 usually means the editor version 6000.3.*, but the shader include chain is determined by the URP package version.
Practice check:
- Check the
com.unity.render-pipelines.universalversion in Package Manager. - Open the local package source (
Packages/orLibrary/PackageCache/) to check actual file
Related: 01. 큰그림
16.2 Lit.shader is a “pass bundle” (URP 17.3.0: 9 LightMode types)
URP Lit.shader consists of a bundle of several ShaderLab Passes to allow “Lit Materials” to participate in multiple stages of the pipeline.
There are 9 LightMode Passes below in Lit.shader in URP 17.3.0 (see @@TOK_16_14164784@@ for exact list/include).
| Pass Name | LightMode | When is it consumed (Summary) |
|---|---|---|
ForwardLit |
UniversalForward |
Default Forward color (including Forward+) |
GBuffer |
UniversalGBuffer |
GBuffer output in deferred rendering |
ShadowCaster |
ShadowCaster |
Shadow map rendering |
DepthOnly |
DepthOnly |
Camera Depth/Depth Freepass |
DepthNormals |
DepthNormals |
Depth+Normals texture creation (SSAO/Outline based) |
Meta |
Meta |
For lightmap baking |
MotionVectors |
MotionVectors |
Object motion vector (velocity) |
XRMotionVectors |
XRMotionVectors |
XR Motion Vector (+Stencil Agreement Included) |
Universal2D |
Universal2D |
2D Renderer Compatibility Pass |
These passes are selected when URP's Render Pass (=C# pipeline stage) looks for a “ShaderLab Pass with a specific LightMode”.
Related: 09. URP 호환 셰이더 작성
16.3 Lit standard “include chain” large map
The inclusion of Lit shaders is stable if you think of them as three layers.1. Core layer (base): Coordinate transformation/platform macro/utility/definition 2. Functional Layer (Input/Lighting/Shadow/GI): Light Access, BRDF, Shadow Sampling, Lightmap/Probe. 3. Pass layer (entry): vertex/fragment entry function of Forward/Depth/Shadow/Meta
16.3.1 Chain as Mermaid (Concept Map)
This graph represents “what roles are connected to where”.
The exact file name may be different in the URP version, so follow the graph and check in your local package.
Parse error on line 33: ...ader --> ForwardPass --> LitForward Li -----------------------^ Expecting 'SEMI', 'NEWLINE', 'EOF', got 'ARROW_POINT'
Based on this map, we keep track of where the functions are coming from.
16.4 “Entry functions” and main responsibilities for each pass (URP 17.3.0)
The most important thing in a URP shader is “which entry/output each pass is responsible for (= contract).”
| Pass Name | LightMode | Entry (Representative) | Core Responsibilities (Summary) |
|---|---|---|---|
| ForwardLit | UniversalForward |
LitPassVertex / LitPassFragment |
SurfaceData/InputData configuration → PBR synthesis → Fog/Alpha → SV_Target* output |
| GBuffer | UniversalGBuffer |
LitGBufferPassVertex / LitGBufferPassFragment |
GBuffer output for Deferred |
| ShadowCaster | ShadowCaster |
ShadowPassVertex / ShadowPassFragment |
Shadow map depth recording (+alpha clip/bias) |
| DepthOnly | DepthOnly |
DepthOnlyVertex / DepthOnlyFragment |
depth recording (+alpha clip) |
| DepthNormals | DepthNormals |
DepthNormalsVertex / DepthNormalsFragment |
depth+normal recording (based on SSAO/outline) |
| Meta | Meta |
UniversalVertexMeta / UniversalFragmentMetaLit |
Meta output for baking (albedo/emission centered) |
| MotionVectors | MotionVectors |
(entry provided by ObjectMotionVectors) | velocity output (ColorMask RG) |
| XRMotionVectors | XRMotionVectors |
(entry provided by ObjectMotionVectors) | XR velocity output (+stencil contract) |
| Universal2D | Universal2D |
vert / frag(Universal2D) |
2D Renderer compatible color path |
Practical points
“Fully compliant” is not just ForwardLit, it is providing a LightMode Pass that the project actually consumes.
Contract full table (when/why consumed): @@TOK_24_b865c9ce@@
Related: 09. URP 호환 셰이더 작성
16.5 Fixing Lit Forward (UniversalForward) to the “correct reference”
Lit Forward is the most customized area in URP, so it is recommended that the symbols below be fixed to the signature/return value/definition position.
Original: @@TOK_25_8394c928@@
16.5.1 Key symbols (return value/definition location)
| Symbol | Returns | Params (Summary) | Defined-in |
|---|---|---|---|
TransformObjectToHClip |
float4 |
float3 positionOS |
<CORE>/ShaderLibrary/SpaceTransforms.hlsl:108 |
LitPassVertex |
Varyings |
Attributes input |
<URP>/Shaders/LitForwardPass.hlsl:158 |
LitPassFragment |
void |
out SV_Target* output |
<URP>/Shaders/LitForwardPass.hlsl:223 |
InitializeStandardLitSurfaceData |
void |
float2 uv, out SurfaceData |
<URP>/Shaders/LitInput.hlsl:252 |
InitializeInputData |
void |
Varyings, normalTS, out InputData |
<URP>/Shaders/LitForwardPass.hlsl:72 |
UniversalFragmentPBR |
half4 |
InputData, SurfaceData |
<URP>/ShaderLibrary/Lighting.hlsl:282 |
16.5.2 Why LitPassFragment is not half4 return: out SV_Target(MRT/Rendering Layers)
In URP 17.3.0, LitPassFragment outputs SV_Target0 (and the conditional SV_Target1) as an out parameter instead of the return value.
- Definition:
<URP>/Shaders/LitForwardPass.hlsl:223
This form:
- Maintain scalable form with MRT (Multiple Render Target Output),
- It is easy to attach additional output when features such as Rendering Layers are turned on.
- Increases the likelihood that “fully compatible” custom shaders will be combined with URP features.### 16.5.3 Lit Forward call flow (step fixation)
The URP Lit Forward fragment is roughly structured in the following order (the exact call point is fixed by the generated xref):
InitializeStandardLitSurfaceData— Construct SurfaceData with UV/TextureInitializeInputData— Configuring InputData with Varyings/normalTS- (Optional) Combining peripheral functions such as Decal/GI/APV
UniversalFragmentPBR— Main/Additional Light/Shadow/GI Composition- Output
SV_Target*after post-processingMixFog,OutputAlpha, etc.
Parse error on line 1: flowchart TD A[Lit ^ Expecting 'NEWLINE', 'SPACE', 'GRAPH', got 'ALPHA'
16.5.4 Forward+ loop branch (summary)
In Forward+, the additional light loop contract is different.
GetAdditionalLightsCount()can return 0 (contract).- Definition:
<URP>/ShaderLibrary/RealtimeLights.hlsl:271
- Definition:
- URP simultaneously satisfies the Forward/Forward+ loop with
LIGHT_LOOP_BEGIN/END.- Definition:
<URP>/ShaderLibrary/RealtimeLights.hlsl:28/:36
- Definition:
More details/debugging routines: 07. Forward/Forward+/Lights
16.6 SurfaceData vs InputData: “What do you put where?”
The best way to understand URP Lit is to separate these two structures and memorize them.
16.6.1 SurfaceData (Surface/Material input)
SurfaceData is information about “what surface the material is.”
- Albedo (Base Color/Base Map)
- Normal Map
- Metallic/Smoothness/Occlusion/Emission
- Alpha/Cutoff
In other words, texture sampling and organizing material parameters are key.
16.6.2 InputData (space/camera/light input)
InputData is information “where that surface is in the scene and under what camera/lighting conditions.”
- positionWS / normalWS / viewDirectionWS -shadowCoord -fogCoord
- bakedGI / shadowMask -normalizedScreenSpaceUV
In other words, space/coordinates/camera/shadow/GI preparation is key.
Understanding this separation:
- “I want to change the surface model” → SurfaceData creation/transformation page
- “I want to change the lighting calculation” → PBR function or light access side
- “Depth/Screen UV is needed” → InputData/Core Utility page
You can quickly get your bearings.
16.7 How to automatically generate “accurate references” locally (recommended)
Since this book aims to learn based on the “original (package source)”, it provides a workflow that automatically extracts include/symbols/xref to create an “accurate reference”.
- One-click runner:
tools/generate-all.ps1 - Output root:
book/generated/(stable) +book/generated/urp-17.3.0/(versioned) - Product list/implementation method: @@TOK_8_396718ca@@
tools/generate-all.ps1 does the following in order:
- Create Lit Pass/Include map: @@TOK_10_14164784@@
- Create symbol index (function/structure/macro/file):
book/generated/urp-17.3.0/symbols/* - Creation of Lit core symbol xref: @@TOK_12_8394c928@@
Run (example):
powershell -ExecutionPolicy Bypass -File tools/generate-all.ps1 -UnityProjectRoot "<YOUR_UNITY_PROJECT_ROOT>"
The product does not expose the absolute path as is, but replaces it with <URP>, <CORE>.
Note
If you need individual executions, you can also use a single script liketools/generate-urp-lit-map.ps1,
To maintain the “document-reference link”, a one-click runner is recommended as the default routine.
16.8 What should we watch next?
- “A template that reflects this include/path structure” is: 18. 완전 호환 Pass 템플릿
- “If you want to create SSAO/SSR type with Compute/UAV pattern”: 17. RenderGraph Compute/UAV 패턴
16.9 Practice assignment (recommended)
- Run
tools/generate-all.ps1and open @@TOK_4_14164784@@. - Look at the include list in the
ForwardLit (UniversalForward)section. - Trace the following from @@TOK_6_8394c928@@ to “Definition location → Call destination”.
LitPassFragmentInitializeStandardLitSurfaceDataInitializeInputDataUniversalFragmentPBR
- Use the Frame Debugger to check “when DepthNormals pass is called” in the actual frame.