Version: Unity 6.1 Alpha (6000.1)
Language : English
Set a shader to require a shader model or GPU feature
Set the render queue of a shader

Set a shader to require a package

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.

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.

Note: The PackageRequirements block must come before all other declarations inside the SubShader or Pass.

Example

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"
            }

            // The rest of the code for the Pass
        }
        Pass
        {
            PackageRequirements
            {
                "com.unity.render-pipelines.high-definition": "[8.0,8.5]"
            }

            // The rest of the code for the Pass

        }
    }
}

Additional resources

Set a shader to require a shader model or GPU feature
Set the render queue of a shader