2
\$\begingroup\$

Exactly as the question says. Is there a way i can draw vertices only into the stencil buffer.

Basically i want to perform some operations on some vertices of a mesh and based on the result, draw passing vertices only onto the stencil buffer of the screen

\$\endgroup\$
2
\$\begingroup\$

This is part of the GraphicsDevice.BlendState. Set ColorWriteChannels to none. (https://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.blendstate_members.aspx)

\$\endgroup\$
  • \$\begingroup\$ ok that disables write to the color buffer , but how do i enable write to the stencil ? \$\endgroup\$ – B0rn2C0de Oct 5 '16 at 9:13
  • \$\begingroup\$ use GraphicsDevice.DepthStencilState w/ StencilEnable = true. All the stencil ops are in there (and depth ops) \$\endgroup\$ – CobaltHex Oct 5 '16 at 17:17
1
\$\begingroup\$

I have to do like this:

//Disable writing to screen
BlendState disableColorBufferState = new BlendState();
disableColorBufferState.ColorWriteChannels = ColorWriteChannels.None;

spriteBatch.Begin(SpriteSortMode.Immediate, disableColorBufferState, null, stencilAlways, null, alphaTestEffect);
//draw here
spriteBatch.End

//Enable it again to draw another model
BlendState enableColorBufferState = new BlendState();
enableColorBufferState.ColorWriteChannels = ColorWriteChannels.All;
spriteBatch.Begin(SpriteSortMode.Immediate, enableColorBufferState);
spriteBatch.End();

//Draw another 3D model here
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.