Programming Serendipity

気まぐれに大まかに生きるブログ

ShaderLabのBlendの考え方

Blend SrcAlpha OneMinusSrcAlphaみたいなやつ。続きからどうぞ。

↑は一般的な通常ブレンドですが、指定可能なオプションは10あり、それぞれ指定できるので10*10=100通り指定できます。

Blend A B とすると、描画結果は

(現在の色) * B + (描画しようとしている色) * A

のようなイメージです。

最初の例のBlend SrcAlpha OneMinusSrcAlphaで言うと、まず描画しようとしているオブジェクトをObjAとすると、ObjAが覆っている矩形部分全体(透明部分含む)にたいして、下地のObjAの該当部分のピクセルの1 - alpha値でかけ、そして、そこにObjAのalpha値でかけたものを合成する、という感じです。

例えばObjAのalphaが0.3のピクセルの部分は、下地は0.7でかけられ、オブジェクト側が1(完全に不透明)なら下地は0(完全に透明)で描画し、オブジェクト側が0なら下地を1で描画する、という形です。 言ってみれば当たり前の処理ですが、それを手動で指定している部分になっているわけです。

指定しなければAlphaが無視されるということで、例えばBlend One Zeroとかにしたら透明度にお構いなくObjAが全部出ます。(このとき、Alphaが0の部分には変な描画がなされます。透明でもRGB情報を持っているのでしょうか?)

ちなみにオプションの~~Color系は、Alphaは自動的に1が補完される模様。

おまけ

いろいろ試したい人用に全組み合わせを用意しました。どうぞ~。

//Blend DstAlpha DstAlpha
//Blend DstAlpha DstColor
//Blend DstAlpha One
//Blend DstAlpha OneMinusDstAlpha
//Blend DstAlpha OneMinusDstColor
//Blend DstAlpha OneMinusSrcAlpha
//Blend DstAlpha OneMinusSrcColor
//Blend DstAlpha SrcAlpha
//Blend DstAlpha SrcColor
//Blend DstAlpha Zero
//Blend DstColor DstAlpha
//Blend DstColor DstColor
//Blend DstColor One
//Blend DstColor OneMinusDstAlpha
//Blend DstColor OneMinusDstColor
//Blend DstColor OneMinusSrcAlpha
//Blend DstColor OneMinusSrcColor
//Blend DstColor SrcAlpha
//Blend DstColor SrcColor
//Blend DstColor Zero
//Blend One DstAlpha
//Blend One DstColor
//Blend One One
//Blend One OneMinusDstAlpha
//Blend One OneMinusDstColor
//Blend One OneMinusSrcAlpha
//Blend One OneMinusSrcColor
//Blend One SrcAlpha
//Blend One SrcColor
//Blend One Zero
//Blend OneMinusDstAlpha DstAlpha
//Blend OneMinusDstAlpha DstColor
//Blend OneMinusDstAlpha One
//Blend OneMinusDstAlpha OneMinusDstAlpha
//Blend OneMinusDstAlpha OneMinusDstColor
//Blend OneMinusDstAlpha OneMinusSrcAlpha
//Blend OneMinusDstAlpha OneMinusSrcColor
//Blend OneMinusDstAlpha SrcAlpha
//Blend OneMinusDstAlpha SrcColor
//Blend OneMinusDstAlpha Zero
//Blend OneMinusDstColor DstAlpha
//Blend OneMinusDstColor DstColor
//Blend OneMinusDstColor One
//Blend OneMinusDstColor OneMinusDstAlpha
//Blend OneMinusDstColor OneMinusDstColor
//Blend OneMinusDstColor OneMinusSrcAlpha
//Blend OneMinusDstColor OneMinusSrcColor
//Blend OneMinusDstColor SrcAlpha
//Blend OneMinusDstColor SrcColor
//Blend OneMinusDstColor Zero
//Blend OneMinusSrcAlpha DstAlpha
//Blend OneMinusSrcAlpha DstColor
//Blend OneMinusSrcAlpha One
//Blend OneMinusSrcAlpha OneMinusDstAlpha
//Blend OneMinusSrcAlpha OneMinusDstColor
//Blend OneMinusSrcAlpha OneMinusSrcAlpha
//Blend OneMinusSrcAlpha OneMinusSrcColor
//Blend OneMinusSrcAlpha SrcAlpha
//Blend OneMinusSrcAlpha SrcColor
//Blend OneMinusSrcAlpha Zero
//Blend OneMinusSrcColor DstAlpha
//Blend OneMinusSrcColor DstColor
//Blend OneMinusSrcColor One
//Blend OneMinusSrcColor OneMinusDstAlpha
//Blend OneMinusSrcColor OneMinusDstColor
//Blend OneMinusSrcColor OneMinusSrcAlpha
//Blend OneMinusSrcColor OneMinusSrcColor
//Blend OneMinusSrcColor SrcAlpha
//Blend OneMinusSrcColor SrcColor
//Blend OneMinusSrcColor Zero
//Blend SrcAlpha DstAlpha
//Blend SrcAlpha DstColor
//Blend SrcAlpha One
//Blend SrcAlpha OneMinusDstAlpha
//Blend SrcAlpha OneMinusDstColor
//Blend SrcAlpha OneMinusSrcAlpha
//Blend SrcAlpha OneMinusSrcColor
//Blend SrcAlpha SrcAlpha
//Blend SrcAlpha SrcColor
//Blend SrcAlpha Zero
//Blend SrcColor DstAlpha
//Blend SrcColor DstColor
//Blend SrcColor One
//Blend SrcColor OneMinusDstAlpha
//Blend SrcColor OneMinusDstColor
//Blend SrcColor OneMinusSrcAlpha
//Blend SrcColor OneMinusSrcColor
//Blend SrcColor SrcAlpha
//Blend SrcColor SrcColor
//Blend SrcColor Zero
//Blend Zero DstAlpha
//Blend Zero DstColor
//Blend Zero One
//Blend Zero OneMinusDstAlpha
//Blend Zero OneMinusDstColor
//Blend Zero OneMinusSrcAlpha
//Blend Zero OneMinusSrcColor
//Blend Zero SrcAlpha
//Blend Zero SrcColor
//Blend Zero Zero