Blend コマンドは、フラグメントシェーダーの出力を GPU がどのようにレンダーターゲットと組み合わせるかを決定します。
このコマンドの機能は、BlendOp コマンドで設定できるブレンド操作に依存します。ブレンド自体はすべてのグラフィックス API とハードウェアでサポートされていますが、一部のブレンド操作はサポートが制限されることに注意してください。
ブレンドを有効にすると、GPU でのいくつかの最適化 (主に隠れたサーフェスの除去/Early-Z) が無効になるため、GPU のフレームタイムが長くなることがあります。
ここでは、最も一般的なブレンドタイプの構文を紹介します。
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
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.
}
}
}
このサンプルコードでは、SubShader ブロックでこのコマンドを使用するための構文を示しています。
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.
}
}
}