I was going through this tutorial for having transparency which can be used to solve my problem here. The code is written in XNA 3 but I'm using XNA 4.

What is the alternative for the following code in XNA 4?

device.RenderState.AlphaTestEnable = true;
device.RenderState.AlphaFunction = CompareFunction.GreaterEqual;
device.RenderState.ReferenceAlpha = 200;
device.RenderState.DepthBufferWriteEnable = false;

I searched a lot but didn't find anything useful.

  • \$\begingroup\$ Here is the blog post that details the removal of the alpha test render state in XNA 4.0 (and the introduction of state objects). If alpha-testing is all you need, there is a built-in AlphaTestEffect that you can use. \$\endgroup\$ – Andrew Russell May 31 '14 at 14:13

You can Alpha test in pixel shader by discarding the pixel if its alpha is below a certain level:




These two have the same effect which is discarding the pixel if its alpha is below 0.1. I am not sure what exactly is referencealpha in the renderstate but I am guessing it is an unnormalized alpha value, so 200 would be 200.0/255.0 in pixel shader. You can turn off depth write by:

device.DepthStencilState = DepthStencilState.DepthRead;
//device is your GraphicsDevice
| improve this answer | |

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.