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.
To pass data into a custom shaderA program that runs on the GPU. More info
See in Glossary in High-Level Shader Language (HLSL), create a struct that declares shader variables and connects them to the meshThe main graphics primitive of Unity. Meshes make up a large part of your 3D worlds. Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info
See in Glossary vertex data.
Use one of the following methods:
Unity has a library of High-Level Shader Language (HLSL) shader files that contain prebuilt HLSL structures with common vertex inputs. For more information, refer to:
To declare a custom vertex structure, follow these steps:
HLSLPROGRAM, add a struct that declares a variable for each input you want to access from the mesh.For a list of semantics, refer to HLSL semantics reference.
For example:
Shader "VertexInputCustom" {
SubShader {
Pass {
HLSLPROGRAM
...
struct custom_vertex_input {
// Declare a variable for the vertex position, and connect it to the mesh data using the POSITION semantic.
float4 vertex : POSITION;
// Declare a variable for the vertex normal, and connect it to the mesh data using the NORMAL semantic.
float3 normal : NORMAL;
};
...
v2f vert (custom_vertex_input v) {
...
}
ENDHLSL
}
}
}
If a variable contains more components than the mesh data, the extra components are 0 for x, y, and z, and 1 for w. For example, if you declare a float4 with TEXCOORD0, the value is (u, v, 0, 1).
The data you pass from the vertex shaderA program that runs on each vertex of a 3D model when the model is being rendered. More info
See in Glossary to the fragment shader, known as interpolators, has limits based on the target platform and GPU.
To minimize the number of interpolators you use, pack data into single variables. For example, combine two sets of float2 UV coordinates into one float4 variable, where x and y contain the first UV coordinate and z and w contain the second UV coordinate.
DirectX groups all uniform variables into constant buffers. Rendering might be faster if you group uniform variables into separate constant buffers depending on how often they change.
To create a constant buffer, use the CBUFFER_START and CBUFFER_END Unity macros. For example:
CBUFFER_START(RarelyUpdatedVariables)
float4 lightPosition;
CBUFFER_END
CBUFFER_START(FrequentlyUpdatedVariables)
float4 colorTint;
CBUFFER_END