Version: Unity 6.7 Alpha (6000.7)
Language : English
Import a file from the shader library in the Built-In Render Pipeline
Lighting variables in the Built-In Render Pipeline reference

Use built-in HLSL structures in the Built-In Render Pipeline

Important: The Built-In Render Pipeline is deprecated and will be made obsolete in a future release.
It remains supported, including bug fixes and maintenance, through the full Unity 6.7 LTS lifecycle.
For more information on migration, refer to Migrating from the Built-In Render Pipeline to the Universal Render Pipeline and Render pipeline feature comparison.

Use prebuilt HLSL vertex input structures from UnityCG.cginc to simplify vertex shader declarations in the Built-In Render Pipeline.

To use a prebuilt structure, follow these steps:

  1. Add #include "UnityCG.cginc" at the top of your HLSLPROGRAM. This imports the UnityCG.cginc file, which contains the prebuilt structures.
  2. When you declare your vertex shader function, use one of the prebuilt structures as the input parameter type. For example, to use appdata_base, use v2f vert (appdata_base vertex_data).

The prebuilt structures in UnityCG.cginc are:

  • appdata_base: Declares vertex for position, normal, and texcoord.
  • appdata_tan: Declares vertex for position, tangent, normal, and texcoord.
  • appdata_full: Declares vertex for position, tangent, normal, color, texcoord, texcoord1, texcoord2, and texcoord3.
  • appdata_img: Declares vertex for position, and texcoord.

Example

The following shader uses appdata_base, and colors the mesh based on its normals.

Shader "VertexInputSimple" {
    SubShader {
        Pass {
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"
         
            // Declare the structure for data passed from the vertex shader to the fragment shader.
            struct v2f {
                float4 position : SV_POSITION;
                half4 color : COLOR;
            };
            
            // Use the built-in appdata_base structure for the vertex shader.
            v2f vert (appdata_base v)
            {
                v2f output_data;

                // Use the position from appdata_base.
                output_data.position = UnityObjectToClipPos(v.vertex);

                // Use the normal from appdata_base. 
                output_data.color.xyz = v.normal * 0.5 + 0.5;

                output_data.color.w = 1.0;
                return output_data;
            }

            half4 frag (v2f i) : SV_Target { 
                return i.color; 
            }

            ENDHLSL
        }
    } 
}

Additional resources

Import a file from the shader library in the Built-In Render Pipeline
Lighting variables in the Built-In Render Pipeline reference