Sign in to follow this  
fireangel

MDX / C++.net Alpha Maps

Recommended Posts

fireangel    122
Using DX9 with VS 2003(.net). ( I know both are dead, but I have alot of stuff I'd have to upgrade, so I'm waiting for a large chunk of time to do so ). So, I've basically plugged away all day at trying to get an Alpha map image to "Mask" another image. Not too much explaination of what all the variables do that go into it, and so, I'm lost... ( If anyone has any good tutorials on it, please give me the link and I'll go look at it. Doesn't matter if its DX8 or C#/VB.net, concepts should still be the same ). My main texture is a PNG with no transparency defined ( I have several of these for various colors I use ). The mask texture is also a PNG with no transparency, and is basically white where I want the first texture to show thru, and black where I don't want it. For What I have
drawDevice->RenderState->SourceBlend = Direct3D::Blend::SourceAlpha;
drawDevice->RenderState->DestinationBlend = Direct3D::Blend::InvSourceColor;
//drawDevice->RenderState->BlendOperation = Direct3D::BlendOperation::Add;
drawDevice->RenderState->AlphaBlendEnable = true;
Blend operation is commented out, since I've seen some posts that do not have it assigned. For what I have, it doesn't seen to make a differance one way or the other.
	drawDevice->SetTexture( 0, textureBase);     //The base color texture to use
	drawDevice->SetTexture( 0, textureAlpha);    //Our mask

	drawDevice->TextureState->get_TextureState(0)->ColorOperation = TextureOperation::SelectArg1;
	drawDevice->TextureState->get_TextureState(0)->ColorArgument1 = TextureArgument::TextureColor;
	drawDevice->TextureState->get_TextureState(0)->AlphaOperation = TextureOperation::SelectArg2;
	drawDevice->TextureState->get_TextureState(0)->AlphaArgument2 = TextureArgument::Diffuse;

Note ( For C# ppl ). drawDevice->TextureState->get_TextureState(1) is the same as drawDevice.TextureState[1]. For some reason array brackets won't work with 2003 ( but they do with 2005 ). So. Here is what I THOUGHT I was doing. Select color from Argument1 ( Arguement 1 is the FIRST Texture [0] in the draw device )
drawDevice->TextureState->get_TextureState(0)->ColorOperation = TextureOperation::SelectArg1;
Set argument1 to use the Texture Color ( But not alpha )
drawDevice->TextureState->get_TextureState(0)->ColorArgument1 = TextureArgument::TextureColor;
Select the Alpha from Arguement2, which is the Second Texture [1] in the draw device
drawDevice->TextureState->get_TextureState(0)->AlphaOperation = TextureOperation::SelectArg2;
Use the color as the alpha value ( Black = transparent, white = not transparent )
drawDevice->TextureState->get_TextureState(0)->AlphaArgument2 = TextureArgument::Diffuse;
What do I get? Well. The closer to white the base texture is, the move visible it is. The mask is not even seen at all. I have also tried
	drawDevice->TextureState->get_TextureState(0)->ColorOperation = TextureOperation::SelectArg2;
	drawDevice->TextureState->get_TextureState(1)->ColorOperation = TextureOperation::Modulate;
	drawDevice->TextureState->get_TextureState(1)->ColorArgument1 = TextureArgument::Current;
	drawDevice->TextureState->get_TextureState(1)->ColorArgument2 = TextureArgument::TextureColor;		//Doesn't seam to do anything..

	drawDevice->TextureState->get_TextureState(0)->AlphaOperation = TextureOperation::SelectArg1;
	drawDevice->TextureState->get_TextureState(0)->AlphaArgument1 = TextureArgument::TextureColor;
	//drawDevice->TextureState->get_TextureState(0)->AlphaArgument2 = TextureArgument::Diffuse;
	drawDevice->TextureState->get_TextureState(1)->AlphaOperation = TextureOperation::SelectArg1;
	drawDevice->TextureState->get_TextureState(1)->AlphaArgument1 = TextureArgument::Current;
	//drawDevice->TextureState->get_TextureState(1)->AlphaArgument2 = TextureArgument::Diffuse;

This makes everything close to transparent, but instead of seeing the colors, everything is black. Obviously I have no clue what each does, and MS documentation is pretty crappy. The second set I believe was found in a thead here at GameDev. Why use TextureState 0 vs 1? Does textureState 0 corrispond to Texture 0 ( and 1 to 1? ). If I tell it to SelectArg1, should I define what Argument1 is? I've seen places that do not. Also, if I tell it to SelectArg1, should I define Arg1 AND 2? I have more questions, but I this will get me started. I thought this was easy! ( Can't wait to try Alpha Mask and normal maps at the same time! ). Thanks Geoff

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