Unity supports all #pragma
directives that are part of standard HLSL, as long as these directives are in regular include files. For more information on these directives, see the HLSL documentation: pragma Directive.
If you are writing a Surface ShaderA streamlined way of writing shaders for the Built-in Render Pipeline. More info
See in Glossary, use this directive to tell the compiler which function to use as the surface function, and pass data to that function.
Statement | Function |
---|---|
#pragma surface <surface function> <lighting model> <optional parameters> |
Compile the function with the given name as the surface shader, so that it works with the given lighting model. For more information, see Surface Shaders. |
If you are writing a regular graphics shaderA program that runs on the GPU. More info
See in Glossary, use these directives to tell the compiler which functions to use for different shader stages. The #pragma vertex
and #pragma fragment
directives are required, but other stages are optional.
Statement | Function |
---|---|
#pragma vertex <name> |
Compile the function with the given name as the vertex shader. Replace <name> with the function name. This directive is required in regular graphics shaders. |
#pragma fragment <name> |
Compile the function with the given name as the fragment shader. Replace <name> with the function name. This directive is required in regular graphics shaders. |
#pragma geometry <name> |
Compile the function with the given name as the geometry shader. Replace <name> with the function name. This option automatically turns on #pragma require geometry ; for more information, see Targeting shader models and GPU features in HLSL.Note: Metal does not support geometry shaders. |
#pragma hull <name> |
Compile the function with the given name as the DirectX 11 hull shader. Replace <name> with the function name. This automatically adds #pragma require tessellation ; for more information, see Targeting shader models and GPU features in HLSL. |
#pragma domain <name> |
Compile the function with the given name as the DirectX 11 domain shader. Replace <name> with the function name. This option automatically turns on #pragma require tessellation ; for more information, see Targeting shader models and GPU features in HLSL. |
Use these directives to tell the shader compiler how to handle shader variants and keywords. For more information, see Declaring and using shader keywords in HLSL.
Directive | Description |
---|---|
#pragma multi_compile <keywords> |
Declares a collection of keywords. The compiler includes all of the keywords in the build. You can use suffixes such as _local to set additional options.For more information and a list of supported suffixes, see Declaring and using shader keywords in HLSL. |
#pragma shader_feature <keywords> |
Declares a collection of keywords. The compiler excludes unused keywords from the build. You can use suffixes such as _local to set additional options.For more information and a list of supported suffixes, see Declaring and using shader keywords in HLSL. |
#pragma hardware_tier_variants <values> |
Built-in Render Pipeline only: Add keywords for graphics tiers when compiling for a given graphics API. For more information, see Graphics tiers. |
#pragma skip_variants <list of keywords> |
Strip specified keywords. |
Use these directives to tell the compiler that your shader requires specific GPU features.
Statement | Function |
---|---|
#pragma target <value> |
The minimum shader model that this shader program is compatible with. Replace <value> with a valid value. For a list of valid values, see Shader compilation: Targeting shader models and GPU features in HLSL. |
#pragma require <value> |
The minimum GPU features that this shader is compatible with. Replace <value> with a valid value, or multiple valid values separated by a space. For a list of valid values, see Shader compilation: Targeting shader models and GPU features in HLSL. |
Use these directives to tell Unity to include or exclude code for a given graphics API.
Statement | Function |
---|---|
#pragma only_renderers <value> |
Compile this shader program only for given graphics APIs. Replace <values> with a space-delimited list of valid values. For more information and a list of valid values, refer to Targeting graphics APIs and platforms in HLSL. For example, #pragma only_renderers glcore only compiles for the desktop OpenGL. Like the ES 3 target, this also scales up to contain all desktop OpenGL versions, where basic shaders will support OpenGL 2.x while shaders requiring shader model 5.0 features require OpenGL 4.2+. |
#pragma exclude_renderers <value> |
Do not compile this shader program for given graphics APIs. Replace <value> with a space-delimited list of valid values. For more information and a list of valid values, refer to Targeting graphics APIs and platforms in HLSL. |
Statement | Function |
---|---|
#pragma instancing_options <options> |
Enable GPU instancing in this shader, with given options. For more information, see GPU instancing |
#pragma once |
Put this directive in a file to ensure that the compiler includes the file only once in a shader program. Note: Unity only supports this directive when the Caching Shader Preprocessor is enabled. |
#pragma enable_d3d11_debug_symbols |
Generates shader debug symbols for supported graphics APIs, and disables optimizations for all graphics APIs. Use this for debugging shader code in an external tool. Unity generates debug symbols for Vulkan, DirectX 11 and 12, and supported console platforms. Warning: Using this results in an increased file size and reduced shader performance. When you have finished debugging your shaders and you are ready to make a final build of your application, remove this line from your shader source code and recompile the shaders. |
#pragma skip_optimizations <value> |
Forces optimizations off for given graphics APIs. Replace <values> with a space-delimited list of valid values. For a list of valid values, see Targeting graphics APIs and platforms in HLSL |
#pragma hlslcc_bytecode_disassembly |
Embed disassembled HLSLcc bytecode into a translated shader. |
#pragma disable_fastmath |
Enable precise IEEE 754 rules involving NaN handling. This currently only affects the Metal platform. |
#pragma editor_sync_compilation |
Force synchronous compilation. This affects the Unity Editor only. For more information, see Asynchronous Shader compilation. |
#pragma enable_cbuffer |
Emit cbuffer(name) when using CBUFFER_START(name) and CBUFFER_END macros from HLSLSupport even if the current platform does not support constant buffers. |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.
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.