Alpha Blending Insanity

Started by
2 comments, last by v1nd1cat10n 19 years, 10 months ago
I''ve been struggling with this for some time now (I''m not very good at asking for help). I''m doing a terrain texture using splatting from http://www.cbloom.com/3d/techdocs/splatting.txt I have 4 sets of textures. In each set the second texture is the terrain splat texture (i.e. grass,rocks,sand,snow, etc..) The first texture is an alpha map for the second texture. my code looks like this (C# Managed DirectX): device.RenderState.AlphaBlendEnable = true; device.RenderState.SourceBlend = Blend.SourceAlpha; device.RenderState.DestinationBlend = Blend.InvSourceAlpha; //Then we loop through the 4 texture sets { device.SetTexture(0,alphaTexture); device.SetTexture(1,splatTexture); device.TextureState[0].ColorOperation = TextureOperation.SelectArg1; device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1; device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor; device.TextureState[1].ColorOperation = TextureOperation.SelectArg1; device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[1].AlphaOperation = TextureOperation.SelectArg1; device.TextureState[1].AlphaArgument1 = TextureArgument.Current; } What happens with this code is that the first texture set looks great with the right transparency etc, but I see no sign of any of the other texture sets. I can choose only to render one set (any of the sets) and it looks good so I know the other sets are good and the multiple stage texturing is working as planned. I just can only get one set to work. Can somebody let me know if I am screwed in the head thinking I can do it this way? I am doing multi-textureing (> 1 stage) AND multiple passes, is there a problem with this?? Help!! Thanks in advance
v1nd1cat10n"It's nice to be nice to the nice." - Frank Burns
Advertisement
There is a sample in the SDK called MFCTex. There, you can setup your texture stages and fiddle around with it's appearance in realtime. Then, it'll give you all the code you need to get the given appearance.

I suggest that you check that out, and make the textures look the way you want there. Then, take the code info it gives you, and put it in your app.

Edit: the config you have there seems to work okay


Dustin Franklin
Mircrosoft DirectX MVP

[edited by - circlesoft on June 5, 2004 7:00:58 PM]
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
That looks okay (though I''d set stage 2 to DISABLE).

When you use just one splat, you say it''s fine, with the correct alpha, so we can assume your alpha textures really are alpha textures. After that, the only think I can think of that would stop multipass from working is if you ZFUNC is D3DCMP_LESS instead of D3DCMP_LESSEQUAL. You should make sure.

Multistage and multipass are completely seperate issues. You can mix them like you''re doing just fine.

If you have large areas where the alpha is 0, consider turning on alphatest with an alpharef of 0 (or something low, like 8) and an alphafunc of greater. This will save tons of memory bandwidth for each pixel it doesn''t need to alphablend.
Thanks for the peace of mind that I wasn''t all screwed in the head. I have it working now. I added an initial pass of a base texture with Alpha Blending off before the blended textures. After that, everything else shows up correctly.

Does anybody know why that would be the case??

"It''s nice to be nice to the nice." - Frank Burns
v1nd1cat10n"It's nice to be nice to the nice." - Frank Burns

This topic is closed to new replies.

Advertisement