Some shadersA program that runs on the GPU. More info
See in Glossary need to support multiple render pipelinesA series of operations that take the contents of a Scene, and displays them on a screen. Unity lets you choose from pre-built render pipelines, or write your own. More info
See in Glossary simultaneously. Adding package requirements to SubShaders and Passes enables you to avoid compilation errors when shader code uses an include file from a package that is not installed or requires a specific version of a package to compile.
Feature name | Built-in Render Pipeline | Universal Render Pipeline (URP) | High Definition Render Pipeline (HDRP) | Custom SRP |
---|---|---|---|---|
ShaderLabUnity’s language for defining the structure of Shader objects. More info See in Glossary: PackageRequirements block |
Yes | Yes | Yes | Yes |
To specify package requirements for a SubShader or a Pass, you use the PackageRequirements
block. ShaderLab supports a single PackageRequirements
block per SubShader or Pass, but each block can specify multiple package requirements.
Note: if you provide a PackageRequirements
block, it must come before all other declarations inside the SubShader or Pass.
Signature | Function |
---|---|
PackageRequirements{ [requirement definition]} |
Defines the package requirements for the Pass or SubShader. |
There are multiple ways to declare package requirements. Each one provides a different behavior. They are:
Version restrictions define a set of version ranges. If the installed version of a required package is not inside any of the ranges, the package requirement is not met. Similarly, if a requirement specifies a set of Unity version restrictions, the same applies to the current version of Unity. For information about the syntax of version restrictions, see Version syntax.
If a SubShader or Pass declares package requirements that the project does not meet, Unity excludes the SubShader or Pass from further processing and compilation. This happens if the project does not include the required packages, or includes them but not with a compatible version. If a shader does not contain a single SubShader that meets the requirements, or if no SubShader contains Passes that meet the requirements, the Console windowA Unity Editor window that shows errors, warnings and other messages generated by Unity, or your own scripts. More info
See in Glossary shows a warning message.
In ShaderLab’s package requirements, a version uses the major.minor
or major.minor.patch
format. If you only use major.minor
, Unity uses 0
for the patch
. Package versions can also include a -preview
or a -preview.n
postfix where -preview
is equivalent to -preview.0
. Preview versions come before non-preview versions, so 1.2.3-preview.4
comes after 1.2.2
but before 1.2.3
.
There are multiple ways to specify a version range. Each one provides a different behavior. They are:
1.2.3
includes all versions starting with 1.2.3
;[1.2.3]
only includes version 1.2.3
;[1.2.3,2.3.4)
includes all versions from 1.2.3 to 2.3.3.You can also specify sets of version ranges for a single package. To create a set of version ranges from individual ranges, use a semicolon as a separator. For example, [2.0,3.4.5];[3.7];4.0
includes versions from 2.0.0 to 3.4.5, version 3.7.0, and version 4.0.0 and above.
When you set the versions for a package, be aware of the following:
If the syntax does not adhere to the above, the version restriction is invalid. For more information on what happens with invalid package requirements, see Error checking.
The following code example shows how to specify package requirements in both a SubShader and a Pass. The SubShader declares a single package requirement for a package called “com.my.package” and works with any version of this package starting from 2.2.0. The SubShader has two Passes:
The first Pass requires:
The Universal Render Pipeline package with a version between 10.2.1 and 11.0.
The Text 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 Pro package with a version of 3.2 or above.
The second Pass requires:
The High-Definition Render Pipeline package with a version between 8.0 to 8.5
Shader "Examples/ExampleShader"
{
SubShader
{
PackageRequirements
{
"com.my.package": "2.2"
}
Pass
{
PackageRequirements
{
"com.unity.render-pipelines.universal": "[10.2.1,11.0]"
"com.unity.textmeshpro": "3.2"
}
}
Pass
{
PackageRequirements
{
"com.unity.render-pipelines.high-definition": "[8.0,8.5]"
}
}
}
}
If you define package requirements that can never be satisfied, the shader import process fails with an error. This section provides examples of the most common invalid package requirement definitions.
PackageRequirements {
"com.some.package.x": "[10.2.1,9.0]" // Error, empty version range
"com.some.package.y": "[10.2.1.9,11.0]" // Error, incorrect version format
"com.some.package.z": "[2.3,3.5],[3.0,4.0]" // Error, ranges intersect
"com.some.package.z" : "[10.2.1,11.0]" // Error, extra whitespace after the package name
"" : "[2.3.4,3.4.5]" // Error, no package name provided
}
PackageRequirements {
"com.some.package.x": "[10.2.1,11.0]"
"com.some.package.x": "[11.2.1,12.0]" // Error, dependency on "com.some.package.x" declared twice
"unity" : "2021.2"
"unity" : "2021.3" // Error, dependency on Unity version declared twice
}
PackageRequirements {
"com.some.package.x": "unity=[2021.2.1,2021.3.3]"
"unity" : "2021.2" // Error: Unity version requirement cannot be declared on a package and on its own simultaneously
}
SubShader {
PackageRequirements {
"com.some.package.x": "[2.3.4,3.4.5]"
"com.some.package.z": "[1.1,3.2]"
"unity": "2021.2"
}
Pass {
PackageRequirements {
"com.some.package.y": "[1.2.2,2.5]" // Fine, SubShader doesn’t declare a dependency on "com.some.package.y"
"com.some.package.z": "[2.0,3.1]" // Fine, SubShader dependency intersects the provided version range
"com.some.package.x": "[1.1.1, 2.2.2]" // Error, SubShader version range for "com.some.package.x" does not intersect the provided range
"com.some.package.w": "unity=[2021.2.1,2021.2.5]" // Fine, SubShader dependency intersects the provided version range
"com.some.package.u": "unity=[2020.2.1,2020.2.5]" // Error, SubShader Unity version range does not intersect the provided range
}
}
}
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.