例子见Nvidia DX10 sdk 《Stencil Routed KBuffer》
主要实现:第一遍正常渲染,获得Z最小的一层深度值,第二层将第一层深度值作为ShaderResourceView传入,若场景的Z小于等于第一层深度,则discard,这样获得第二层深度值;后面以此类推。
// tDepthBuffer为上一层深度, IN.HPosition为屏幕坐标 DepthColorOutput DepthPeelPS ( Geometry_VSOut IN ) { DepthColorOutput output = (DepthColorOutput)0.0f; float zFront = tDepthBuffer.Load( int3( IN.HPosition.xy, 0 ) ).r; if (IN.HPosition.z <= zFront) discard; output.DepthColor.x = pack_eyez(IN.HPosition.w); output.DepthColor.y = pack_normal(IN.Normal); return output; };