The over operator shows how we can get a transparent effect by blending 2
objects. However, there's one little catch. How does the Z buffer work when
you're using transparent objects. Think about what the Z buffer is dong. It
stores the depth of the object that is closest to the eye. Say, we draw the blue
far object first, then draw and blend in the red transparent object. This works
fine. The blue object's color is taken and blended with the red fragment that is
drawn. However, if we reverse the draw order, we start to get into problems. We
get the red fragment and want to blend it. But we don't even have the blue
object in the Z buffer yet. Even if we decide to wait for the blue object, we
get into trouble. When the blue fragment renders, it is considered hidden by the
red filter, since its farther away from the eye.
オーバーオペレータでは2つの色をブレンドして
透明処理を実行しました
しかし1つ問題があります
Zバッファは透明なオブジェクトを
どのように処理するのでしょうか
Zバッファの働きについて考えましょう
視点に一番近いオブジェクトのZ値を保管しています
青のオブジェクトを先に描いてから
透明な赤のオブジェクトを描きブレンディングすると
青は赤のフラグメントにブレンドされるので
この場合は特に問題ありません
しかし描写する順番を変えると問題が生じます
赤のフラグメントを描いたら
ブレンディングしたいのですが
Zバッファにはまだ青の情報はありません
青のオブジェクトの登場を待っても問題は残ります
青の方が視点から遠い位置にあるので
赤のフィルタに隠れるように処理されるのです
Over 運算子展示了我們能對兩個物件混色達到透明的效果
但是有個問題
Z 緩衝區在有透明物件時如何運作
回想一下 Z 緩衝區運作原理,它儲存最接近眼睛的物件的深度
如果我們先畫藍色較遠的物件,再畫紅色透明物件
這樣沒問題,藍色物件顏色會被拿來跟紅色 Fragment 混色
但如果繪圖順序反過來就會有問題
我們得到紅色 Fragment 想要混色
但 Z 緩衝區還沒有藍色物件
即使我們要等藍色物件也會有問題
當藍色 Fragment 繪製時會視為被紅色過濾片遮擋,因為它距離眼睛較遠