Depth Imageの初期値設定時の注意点
初期値(clear value)より奥のfragmentは描画されないので注意が必要
Depth Value
depthの値はVkPipelineDepthStencilStateCreateInfoのminDepthBoundsからmaxDepthBoundsの値に制限される。
Vulkan® 1.3.205 - A Specification (with all registered Vulkan extensions)
Clear Value
VkRenderPassBeginInfoにVkClearValueで設定する。
VkClearDepthStencilValue(3)
depth is the clear value for the depth aspect of the depth/stencil attachment. It is a floating-point value which is automatically converted to the attachment’s format.
初期値の意味
OpenGLの数式を例にして、zにnearとfarを入れるとわかる通り、
0.0f | <-> | 1.0f |
手前 | <-> | 奥 |
の関係になっている。例えばdepthを0.0fで初期化してしまうと、すべてのfragmentが手前で初期化されてしまうので、どの図形も見えなくなる。
必ず初期値は奥になるようにしなければ、何も見えない。
以下は縦軸と横軸のdepthが異なるひし形を2枚描いた図である。
上図が図形のすべてが描画されている状態。
下図は0.5fで初期化した場合で、depthの値が0.5fより大きいfragmentは描かれないことがわかる。