Stencil Test

Started by
1 comment, last by 21st Century Moose 6 years, 10 months ago

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.

Advertisement

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

.:vinterberg:.

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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement