book/19-urp-shader-methods-reference.md

19. URP Shader Methods Reference

Based on Unity 6.3 (6000.3) / URP 17.3.0, reference organizing frequently used URP/Core HLSL functions/macro in Signature/Returns/Params/Defined-in/Used-by format.

This chapter is a dictionary (reference) chapter that collects “symbols that are frequently used when studying shaders.”

Principle:

  • All items are provided with return value/parameter/definition location (file/line).
  • The list is curated only for “learning core”. For the full index, search ide.

19.0 Accurate Reference (IDE)

19.1 Transform / Space (Coordinate transformation)

APISignatureDefined-inUsed-by / Notes
TransformObjectToWorldfloat3 (float3 positionOS)<CORE>/ShaderLibrary/SpaceTransforms.hlsl:79OS→WS basic conversion
TransformObjectToHClipfloat4 (float3 positionOS)<CORE>/ShaderLibrary/SpaceTransforms.hlsl:108OS→Clip (most often)
TransformWorldToViewfloat3 (float3 positionWS)<CORE>/ShaderLibrary/SpaceTransforms.hlsl:97WS→VS
TransformWorldToHClipfloat4 (float3 positionWS)<CORE>/ShaderLibrary/SpaceTransforms.hlsl:115WS→Clip
TransformWorldToShadowCoordfloat4 (float3 positionWS)<URP>/ShaderLibrary/Shadows.hlsl:356WS→ShadowCoord

Related: 08, 16

19.2 Vertex input helper (Attributes → Inputs)

APISignatureDefined-inUsed-by / Notes
GetVertexPositionInputsVertexPositionInputs (float3 positionOS)<URP>/ShaderLibrary/ShaderVariablesFunctions.hlsl:8Prepare WS/VS/CS/NDC at once
GetVertexNormalInputsVertexNormalInputs (float3 normalOS)<URP>/ShaderLibrary/ShaderVariablesFunctions.hlsl:22Case without tangent
GetVertexNormalInputsVertexNormalInputs (float3 normalOS, float4 tangentOS)<URP>/ShaderLibrary/ShaderVariablesFunctions.hlsl:31tangent basis preparation

Related (struct field): @@TOK_27_de3113a7@@

19.3 Screen/UV/Depth helper (core screen-based effects)| API | Signature | Defined-in | Used-by / Notes |

|---|---|---|---| | GetNormalizedScreenSpaceUV | float2 (float4 positionCS) | <URP>/ShaderLibrary/ShaderVariablesFunctions.hlsl:570 | Forward+ (cluster) key input | | SampleSceneColor | float3 (float2 uv) | <URP>/ShaderLibrary/DeclareOpaqueTexture.hlsl:10 | OpaqueTexture sample | | SampleSceneDepth | float (float2 uv) | <URP>/ShaderLibrary/DeclareDepthTexture.hlsl:18 | raw depth (nonlinear) | | SampleSceneNormals | float3 (float2 uv) | <URP>/ShaderLibrary/DeclareNormalsTexture.hlsl:26 | normals texture sample | | Linear01Depth | float (float depth, float4 zBufferParam) | <CORE>/ShaderLibrary/Common.hlsl:1198 | raw→0..1 linear | | LinearEyeDepth | float (float depth, float4 zBufferParam) | <CORE>/ShaderLibrary/Common.hlsl:1208 | raw→eye depth |

Practical Checklist: @@TOK_18_d1d44a5e@@

19.4 Lit entry/initialization (Forward)

APIReturnsParams (Summary)Defined-inUsed-by / Notes
LitPassVertexVaryingsAttributes input<URP>/Shaders/LitForwardPass.hlsl:158ForwardLit vertex entry
LitPassFragmentvoidVaryings input, out SV_Target0 ...<URP>/Shaders/LitForwardPass.hlsl:223out SV_Target contract
InitializeStandardLitSurfaceDatavoidfloat2 uv, out SurfaceData<URP>/Shaders/LitInput.hlsl:252Configure SurfaceData
InitializeInputDatavoidVaryings, normalTS, out InputData<URP>/Shaders/LitForwardPass.hlsl:72Configure InputData
InitializeBakedGIDatavoidVaryings, inout InputData<URP>/Shaders/LitForwardPass.hlsl:132Baked GI preparation
ApplyDecalToSurfaceDatavoidpositionCS, inout SurfaceData, inout InputData<URP>/ShaderLibrary/DBuffer.hlsl:191DBuffer decals
UniversalFragmentPBRhalf4InputData, SurfaceData<URP>/ShaderLibrary/Lighting.hlsl:282PBR synthesis
MixFoghalf3half3 color, half fog<URP>/ShaderLibrary/ShaderVariablesFunctions.hlsl:513fog combined
OutputAlphahalfhalf alpha, bool transparent<URP>/ShaderLibrary/ShaderVariablesFunctions.hlsl:239Transparent processing

Call flow/edit point: @@TOK_55_e356ea28@@

19.5 Lights (main/additional lights) + Forward+ (cluster) loop

19.5.1 Light access function| API | Returns | Params (Summary) | Defined-in | Notes |

|---|---|---|---|---| | GetMainLight | Light | (none) | <URP>/ShaderLibrary/RealtimeLights.hlsl:81 | Simplest | | GetMainLight | Light | float4 shadowCoord | <URP>/ShaderLibrary/RealtimeLights.hlsl:102 | Includes shadow input | | GetAdditionalLight | Light | uint i, float3 positionWS | <URP>/ShaderLibrary/RealtimeLights.hlsl:224 | Forward Basic | | GetAdditionalLight | Light | uint i, InputData, half4 shadowMask, AO | <URP>/ShaderLibrary/RealtimeLights.hlsl:257 | Function combination | | GetAdditionalLightsCount | int | (none) | <URP>/ShaderLibrary/RealtimeLights.hlsl:271 | May be 0 in Forward+ (Contract) |

19.5.2 Forward+ loop macro (most important)

SymbolKindDefined-inKey Points
_CLUSTER_LIGHT_LOOPshader keyword<URP>/ShaderLibrary/ForwardPlusKeyword.deprecated.hlsl:20 etc.variant branch
USE_CLUSTER_LIGHT_LOOPmacro 0/1<URP>/ShaderLibrary/Core.hlsl:14 / :16include internal switches
LIGHT_LOOP_BEGIN/ENDmacros<URP>/ShaderLibrary/RealtimeLights.hlsl:28 / :36loop implementation unification

Forward+ Advanced: 07

19.6 Shadows

APIReturnsParams (Summary)Defined-inNotes
GetShadowCoordfloat4VertexPositionInputs<URP>/ShaderLibrary/Shadows.hlsl:524Main light shadowCoord ready
MainLightRealtimeShadowhalffloat4 shadowCoord<URP>/ShaderLibrary/Shadows.hlsl:385main light realtime shadow
AdditionalLightRealtimeShadowhalfint lightIndex, float3 positionWS, half3 lightDir<URP>/ShaderLibrary/Shadows.hlsl:425Additional light shadow

Macro (representative):

MacroKindDefined-inNotes
SAMPLE_SHADOWMASKfunction-like macro<URP>/ShaderLibrary/Shadows.hlsl:45 etc.shadow mixing path

19.7 Indirect / SH / GI (indirect light)

APIReturnsParams (Summary)Defined-inNotes
SampleSHVertexhalf3half3 normalWS<URP>/ShaderLibrary/GlobalIllumination.hlsl:45Vertex SH
SampleSHPixelhalf3half3 L2Term, half3 normalWS<URP>/ShaderLibrary/GlobalIllumination.hlsl:60Pixel SH
SampleSHreal3real3 normalWS<CORE>/ShaderLibrary/AmbientProbe.hlsl:69Core SH sample

Macro (representative):

MacroKindDefined-inNotes
SAMPLE_GIfunction-like macro<URP>/ShaderLibrary/GlobalIllumination.hlsl:212 etc.Lightmap/Probe Branch

19.8 “The function I am looking for is not found” — Quick find routine

  1. Search function name in @@TOK_54_20e1594e@@
  2. Check the context by opening the local URP/Core source with the path Defined-in
  3. If you need call flow: xref: @@TOK_56_8394c928@@