Legacy Documentation: Version 2018.2 (Go to current version)
GUI Layer (Legacy)
Writing Surface Shaders
Other Versions

Shader Reference

Shaders in Unity can be written in one of three different ways:

  • as surface shadersUnity’s code generation approach that makes it much easier to write lit shaders than using low level vertex/pixel shader programs. More info
    See in Glossary
    ,
  • as vertex and fragment shaders or
  • as fixed function shadersA 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
    .

The shader tutorial can guide you on choosing the right type for your needs.

Regardless of which type you choose, the actual meat of the shader code will always be wrapped in a language called ShaderLabUnity’s declarative language for writing shaders. More info
See in Glossary
, which is used to organize the shader structure. It looks like this:

Shader "MyShader" {
    Properties {
        _MyTexture ("My Texture", 2D) = "white" { }
        // other properties like colors or vectors go here as well
    }
    SubShader {
        // here goes the 'meat' of your
        // - surface shader or
        // - vertex and program shader or
        // - fixed function shader
    }
    SubShader {
        // here goes a simpler version of the SubShader
        // above than can run on older graphics cards
    }
}

We recommend that you start by reading about some basic concepts of the ShaderLab syntax in the sections listed below and then to move on to read about surface shaders or vertex and fragment shadersThe “per-pixel” part of shader code, performed every pixel that an object occupies on-screen. The fragment shader part is usually used to calculate and output the color of each pixel. More info
See in Glossary
in other sections. Since fixed function shaders are written using ShaderLab only, you will find more information about them in the ShaderLab reference itself.

The reference below includes plenty of examples for the different types of shaders. For even more examples of surface shaders in particular, you can get the source of Unity’s built-in shaders from the Resources section. Unity’s post-processing effects allows you to create many interesting effects with shaders.

Read on for shader reference, and check out the shader tutorial as well!

See Also

对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答