Sign in to follow this  

Alpha Map/Texture in MDX9

Recommended Posts

So I've been having difficulty getting a rudimentary alpha map to work correctly in managed DX9 with C#. My code programatically generates an alpha texture that is supposed to mask a primary texture (for terrain splatting). However, no matter what texture state settings I try it always shows up opaque. I was under the impression that frame buffer transparency and texture transparency were different and so I didn't NEED to enable the EnableAlphaBlend render state, but I did just in case. I've tried using the primary texture in the first stage and then tried to use the alpha from the texture in the second stage, nothing. I've tried using the alpha texture as the first stage and putting the primary texture in the second stage, nothing. Here is the basic block I've used:
// stage 0 gets set before this in a switch based on splat type

parent.device.TextureState[0].ColorOperation = TextureOperation.Modulate;
parent.device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
parent.device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;

parent.device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;
parent.device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;

parent.device.SetTexture(1, s.AlphaMap);
parent.device.TextureState[1].ColorOperation = TextureOperation.Disable;
parent.device.TextureState[1].AlphaOperation = TextureOperation.SelectArg1;
parent.device.TextureState[1].AlphaArgument1 = TextureArgument.TextureColor;
parent.device.TextureState[1].AlphaArgument2 = TextureArgument.Current;
This seems theoretically correct but I may have overlooked some important detail. My graphics card (rage mobility-m) is quite old, but it reports MaxSimulataneousTextures to be 2, so that shouldn't be a problem. D3DPTEXTURECAPS_ALPHA is true. D3DSpy reports the generated textures are indeed A8R8G8B8 and that they are filled with the correct (or at least different, non-opaque) alpha values. I figure this must be a fairly simple fix, so any guidance would be greatly appreciated since I've been banging my head against this for a few hours.

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