Version: Unity 6.2 Alpha (6000.2)
Language : English
Check or write to the stencil buffer in a shader
Set the color channels the GPU renders to

Set the blending mode in a shader

The Blend command determines how the GPU combines the output of the fragment shaderA program that runs on the GPU. More info
See in Glossary
with the render target.

The functionality of this command depends on the blending operation, which you can set using the BlendOp command. Note that while blending itself is supported on all graphics APIs and hardware, some blending operations have more limited support.

Enabling blending disables some optimizations on the GPU (mostly hidden surface removal/Early-Z), which can lead to increased GPU frame times.

Common blend types

Here is the syntax for the most common blend types:

Blend SrcAlpha OneMinusSrcAlpha // Traditional transparency
Blend One OneMinusSrcAlpha // Premultiplied transparency
Blend One One // Additive
Blend OneMinusDstColor One // Soft additive
Blend DstColor Zero // Multiplicative
Blend DstColor SrcColor // 2x multiplicative

Examples

Shader "Examples/CommandExample"
{
    SubShader
    {
         // The rest of the code that defines the SubShader goes here.

        Pass
        {    
              // Enable regular alpha blending for this Pass
      Blend SrcAlpha OneMinusSrcAlpha
            
              // The rest of the code that defines the Pass goes here.
        }
    }
}

This example code demonstrates the syntax for using this command in a SubShader block.

Shader "Examples/CommandExample"
{
    SubShader
    {
         // Enable regular alpha blending for this SubShader
         Blend SrcAlpha OneMinusSrcAlpha

         // The rest of the code that defines the SubShader goes here.        

        Pass
        {    
              // The rest of the code that defines the Pass goes here.
        }
    }
}

Additional resources


对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答
Check or write to the stencil buffer in a shader
Set the color channels the GPU renders to
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961