dx10 how to enable stencil test???

Started by
0 comments, last by MJP 15 years, 8 months ago
Hi i´m making a shadow volume implementation and i´ve some doubts how can i render something with stencil test enabled??? i mean, i can change the depth stencil state. The stencil buffer is supposed to be filled with a previous render pass. Now i want to draw pixels only where the stencil is greater than zero i´m using this state ID3D10DepthStencilState *dx10_ds_state = NULL; D3D10_DEPTH_STENCIL_DESC ds_desc; ds_desc.DepthEnable = true; ds_desc.DepthFunc = D3D10_COMPARISON_LESS; ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL; //stencil D3D10_DEPTH_STENCILOP_DESC stencil_op_front, stencil_op_back; ds_desc.StencilEnable = true; ds_desc.StencilReadMask = 0xFF; ds_desc.StencilWriteMask = 0xFF; stencil_op_front.StencilFunc = stencil_op_back.StencilFunc = 3D10_COMPARISON_GREATER; stencil_op_front.StencilDepthFailOp = stencil_op_back.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP; stencil_op_front.StencilFailOp = stencil_op_back.StencilFailOp = D3D10_STENCIL_OP_KEEP; stencil_op_front.StencilPassOp = stencil_op_back.StencilPassOp = D3D10_STENCIL_OP_KEEP; ds_desc.FrontFace = stencil_op_front; ds_desc.BackFace = stencil_op_back; HRESULT hr = idevice->CreateDepthStencilState( &ds_desc, &dx10_ds_state ); if (FAILED(hr)) return; else idevice->OMSetDepthStencilState( dx10_ds_state, 0 ); is this the way of preventing a pixel to be drawn in the screen if the stencil has a value grater than zero??? thanks edit: how can i debug each pixel value in the stencil buffer???
Advertisement
IF you want to prevent pixel from being drawn where the stencil is < 0, you need to set the StencilFunc to D3D10_COMPARISON_EQUAL and pass "0" as the REF value when you call ID3D10Device::OMSetDepthStencilState.

This topic is closed to new replies.

Advertisement