I have read the documentation but not quite get it.
D3DRS_STENCILFUNC
The comparison function is used to compare the reference value to a stencil buffer entry.
This comparison applies only to the bits in the reference value and stencil buffer entry that are set in the stencil mask (set by the D3DRS_STENCILMASK render state).
If TRUE, the stencil test passes.
Let me go step by step.
1.
First i use Clear function to clear BB & DS surface with stencil of 0.
Then i draw some object with:
D3DDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE); D3DDevice->SetRenderState(D3DRS_STENCILREF, 1); D3DDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); D3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE); D3DDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP); D3DDevice->SetRenderState(D3DRS_STENCILREF, 1);// this sets value of 1 to stencil where some object is drawn? Right? sphere1->Draw();
Then i draw some other object overlaping first one with:
D3DDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL); D3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE); D3DDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP); D3DDevice->SetRenderState(D3DRS_STENCILREF, 1);// value to compare with previous one? Also writes this one to stencil? sphere2->Draw();
2. Considering D3DRS_STENCILZFAIL, is this the case (where yellow color is drawn) in this picture?

3. About D3DRS_STENCILMASK and D3DRS_STENCILWRITEMASK, how is this used? What is it "masking"/"write-masking"? I don't understand.
Can you please show me some example pseudo code?






