T.TAO
Back to Blog
/1 min read/Others

Unity Shader #3 URP Upgrade

This note mainly covers how to upgrade Built-in RP shader files to URP.

Structure

SubShader

Add a new render pipeline Tag in Tags .

Plain TextSubShader {
    Tags {
        "RenderPipeline" = "UniversalPipeline"
    }
}

CG Macro

Replace CGPROGRAM / ENDCG with HLSLPROGRAM / ENDHLSL.

Replace CGINCLUDE with HLSLINCLUDE.

#include File Changes

The four commonly used #include directives should be changed as follows:

Plain Text#include "Unity.cginc"
=> #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 

#include "AutoLight.cginc"
=> #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 

#include "AutoLight.cginc"
=> #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 

#include "Lighting.cginc"
=> NOT SUPPORTED

Built-in Helper Function Replacements

Some built-in helper functions have also changed.

Vertex Coordinate Transformation

Built-In

URP

Plain Textfloat4 UnityObjectToClipPos(float3 pos)
Plain Textfloat4 TransformObjectToHClip(float3 positionOS)
Plain Textfloat3 UnityObjectToViewPos(float3 pos)
Plain TextTransformWorldToView(TransformObjectToWorld(positionOS))