Shaders can define a list of parameters to be set by artists in Unity’s material inspector. The Properties block in the shader file defines them.
Properties { Property [Property ...] }
Defines the property block. Inside braces multiple properties are defined as follows.
name ("display name", Range (min, max)) = number
name ("display name", Float) = number
name ("display name", Int) = number
These all defines a number (scalar) property with a default value. The Range
form makes it be displayed as a slider between min and max ranges.
name ("display name", Color) = (number,number,number,number)
name ("display name", Vector) = (number,number,number,number)
Defines a color property with default value of given RGBA components, or a 4D vector property with a default value. Color properties have a color picker shown for them, and are adjusted as needed depending on the color space (see Properties in Shader Programs). Vector properties are displayed as four number fields.
name ("display name", 2D) = "defaulttexture" {}
name ("display name", Cube) = "defaulttexture" {}
name ("display name", 3D) = "defaulttexture" {}
Defines a 2D Texture, cubemapA collection of six square textures that can represent the reflections in an environment or the skybox drawn behind your geometry. The six squares form the faces of an imaginary cube that surrounds an object; each face represents the view along the directions of the world axes (up, down, left, right, forward and back). More info
See in Glossary or 3D (volume) property respectively.
Each property inside the shaderA small script that contains the mathematical calculations and algorithms for calculating the Color of each pixel rendered, based on the lighting input and the Material configuration. More info
See in Glossary is referenced by name (in Unity, it’s common to start shader property names with underscore). The property will show up in material inspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary as display name. For each property a default value is given after equals sign:
Later on in the shader’s fixed function parts, property values can be accessed using property name in square brackets: [name]. For example, you could make blending mode be driven by a material property by declaring two integer properties (say “SrcBlend“ and ”DstBlend”), and later on make Blend Command use them: Blend [_SrcBlend] [_DstBlend]
.
Shader parameters that are in the Properties
block are serialized as MaterialAn asset that defines how a surface should be rendered, by including references to the Textures it uses, tiling information, Color tints and more. The available options for a Material depend on which Shader the Material is using. More info
See in Glossary data. Shader programs can actually have more parameters (like matrices, vectors and floats) that are set on the material from code at runtime, but if they are not part of the Properties block then their values will not be saved. This is mostly useful for values that are completely script code-driven (using Material.SetFloat and similar functions).
In front of any property, optional attributes in square brackets can be specified. These are either attributes recognized by Unity, or they can indicate your own MaterialPropertyDrawer classes to control how they should be rendered in the material inspector. Attributes recognized by Unity:
[HideInInspector]
- does not show the property value in the Material inspector.[NoScaleOffset]
- material inspector will not show Texture tiling/offset fields for Texture properties with this attribute.[Normal]
- indicates that a Texture property expects a normal-map.[HDR]
- indicates that a Texture property expects a high-dynamic range (HDR) Texture.[Gamma]
- indicates that a float/vector property is specified as sRGB value in the UI(User Interface) Allows a user to interact with your application. More info[PerRendererData]
- indicates that a property will be coming from per-renderer data in the form of a MaterialPropertyBlock. Material inspector shows these properties as read-only.[MainTexture]
- indicates that a property is the main texture for a Material. By default, Unity considers a texture with the property name name _MainTex
as the main texture. Use this attribute if your texture has a different property name, but you want Unity to consider it the main texture. If you use this attribute more than once, Unity uses the first property and ignores subsequent ones. When the main texture is set using the [MainTexture]
attribute, it is not visible in the Inspector in Debug mode. When the main texture is set using the [MainTexture]
attribute, it is not visible in the Game view when you use the texture streaming debugging view mode or a custom debug tool.[MainColor]
- indicates that a property is the main color for a Material. By default, Unity considers a color with the property name name _Color
as the main color. Use this attribute if your color has a different property name, but you want Unity to consider it the main color. If you use this attribute more than once, Unity uses the first property and ignores subsequent ones.// properties for a water shader
Properties
{
_WaveScale ("Wave scale", Range (0.02,0.15)) = 0.07 // sliders
_ReflDistort ("Reflection distort", Range (0,1.5)) = 0.5
_RefrDistort ("Refraction distort", Range (0,1.5)) = 0.4
_RefrColor ("Refraction color", Color) = (.34, .85, .92, 1) // color
_ReflectionTex ("Environment Reflection", 2D) = "" {} // textures
_RefractionTex ("Environment Refraction", 2D) = "" {}
_Fresnel ("Fresnel (A) ", 2D) = "" {}
_BumpMap ("Bumpmap (RGB) ", 2D) = "" {}
}
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.