Archived

This topic is now archived and is closed to further replies.

stencil buffer issues

This topic is 4945 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to add shadows to my code and I seem to have some issues with the stencil buffer. My main issue is that my game doesnt seem to be using it! How do I enable the stencil buffer ? What I have so far is: d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; I am pretty sure the rest of my code is good becuase: #1 I have the shadows working fine when the game renders in OpenGL #2 The stencil code is quite similiar to the DXSDK shadows example. Am I missing something important ? When I run the game, it simply seems like none of the stencil functions are doing anything. Thanks, Nitzan

Share this post


Link to post
Share on other sites
Have you remembered to:

1) Check that your hardware actually supports that depth/stencil format?. Use IDirect3D*::CheckDeviceFormat(..) to do that.


2) Clear the stencil buffer in your IDirect3DDevice*::Clear(..) call?. If not, specify the D3DCLEAR_STENCIL flag with your other D3DCLEAR_ flags.


3) Enable the stencil buffer by setting the D3DRS_STENCILENABLE render state to TRUE?


4) Set all of the other stencil render states to values that make sense to your application?

Those states are: D3DRS_STENCILFAIL, D3DRS_STENCILZFAIL, D3DRS_STENCILPASS, D3DRS_STENCILFUNC, D3DRS_STENCILREF, D3DRS_STENCILMASK, D3DRS_STENCILWRITEMASK, and for DX9 hardware:
D3DRS_CCW_STENCILFAIL, D3DRS_CCW_STENCILZFAIL, D3DRS_CCW_STENCILPASS, and D3DRS_CCW_STENCILFUNC.


Simon O''Connor
Game Programmer &
Microsoft DirectX MVP

Share this post


Link to post
Share on other sites
Well what it came down to is two different problems.

#1, When I copied some code form the SDK example, I forgot to notice that after drawing the shadow, but before drawing the shadow square on the screen, the SDK example set culling to backface polygons, while my game engine needs the culling to be set to front facing polygons.

#2. There is some blending problem that is causing some blended objects not to appear. This dates back to a previous blending problem I had which I touched in this thread here which no one was able to help me with.

If you have any ideas why blending in Direct3D looks different then in OpenGL when using the same values I will really appreciate your help. I tried messing around with the material values but I still couldnt get it to look right.

Thanks!

Nitzan

Share this post


Link to post
Share on other sites
quote:
Original post by S1CA
Have you remembered to:

1) Check that your hardware actually supports that depth/stencil format?. Use IDirect3D*::CheckDeviceFormat(..) to do that.


2) Clear the stencil buffer in your IDirect3DDevice*::Clear(..) call?. If not, specify the D3DCLEAR_STENCIL flag with your other D3DCLEAR_ flags.


3) Enable the stencil buffer by setting the D3DRS_STENCILENABLE render state to TRUE?


4) Set all of the other stencil render states to values that make sense to your application?

Those states are: D3DRS_STENCILFAIL, D3DRS_STENCILZFAIL, D3DRS_STENCILPASS, D3DRS_STENCILFUNC, D3DRS_STENCILREF, D3DRS_STENCILMASK, D3DRS_STENCILWRITEMASK, and for DX9 hardware:
D3DRS_CCW_STENCILFAIL, D3DRS_CCW_STENCILZFAIL, D3DRS_CCW_STENCILPASS, and D3DRS_CCW_STENCILFUNC.


Simon O''Connor
Game Programmer &
Microsoft DirectX MVP


Dear Mr.O''Connor,

I want to contact you.
Could you tell me your email address?


Sungkwan Park
My Email : skpark@softweb.co.kr
My MSN Messenger : sungkwanpark@hotmail.com
My Phone : +82-11-256-9917

Share this post


Link to post
Share on other sites