Jump to content
  • Advertisement
Sign in to follow this  

Stencil Test

This topic is 563 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

Hey guys,

Im trying to make a texture mask using stencil test on directx9, but for some reason i didnt understand totally stencil yet, or im doing something wrong.


My code it's:

		renderDevice.GetDevice()->SetRenderState( D3DRS_COLORWRITEENABLE, 0 );
		renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILENABLE, true );
		renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_ALWAYS );
		renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILREF, 0 );
		/*renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILMASK, 0xFFFFFFFF );
		renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILWRITEMASK, 0xFFFFFFFF );*/
		renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_REPLACE );
		renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILFAIL, D3DSTENCILOP_REPLACE );
		renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );

		---(drawing mask image)

		renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_EQUAL );
		renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_ZERO );

		renderDevice.GetDevice()->Clear( 0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0,0,0,0), 1.0f, 0 );

		--(drawing object that i want to clipping)

		renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILENABLE, false );

I have a png image, where the black part it's i want to clip, but when i run the code, never happens, keep rendering entire object.

(ah, i was trying to follow this tutorial: https://research.ncl.ac.uk/game/mastersdegree/graphicsforgames/scissorsandstencils/Tutorial%205%20-%20Scissors%20and%20Stencils.pdf)



Edited by pristondev

Share this post

Link to post
Share on other sites

If you just want to not render anything when the input texture texel is black, you can use HLSL clip() function.



Alternatively convert the black part to an alpha channel when loading and then enable alpha testing or alpha blending.

Stencil is entirely the wrong way to go about what you're trying to do.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!