• Advertisement
Sign in to follow this  

Stencil Test

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_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED );
		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)

 

Thanks.

Edited by pristondev

Share this post


Link to post
Share on other sites
Advertisement

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

 

This.

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement