• Popular Now

• 15
• 15
• 11
• 9
• 10

This topic is 2805 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hello together,

i am trying to use a alphmap as mask with this code:

m_Target.SetTexture(0, m_VBC.mVB_Texture2);
//m_Target.TextureState[0].TextureCoordinateIndex = 0;
m_Target.TextureState[0].ColorOperation = Direct3D.TextureOperation.Disable;
m_Target.TextureState[0].ColorArgument1 = Direct3D.TextureArgument.Current;
m_Target.TextureState[0].AlphaArgument1 = Direct3D.TextureArgument.TextureColor;
m_Target.TextureState[0].AlphaOperation = Direct3D.TextureOperation.SelectArg1;

m_Target.SetTexture(1, m_VBC.mVB_Texture);
m_Target.TextureState[1].TextureCoordinateIndex = 0;
m_Target.TextureState[1].ColorOperation = Direct3D.TextureOperation.SelectArg1;
m_Target.TextureState[1].ColorArgument1 = Direct3D.TextureArgument.TextureColor;
//m_Target.TextureState[1].ColorArgument2 = Direct3D.TextureArgument.Current;
m_Target.TextureState[1].AlphaOperation = Direct3D.TextureOperation.SelectArg1;
m_Target.TextureState[1].AlphaArgument1 = Direct3D.TextureArgument.Current;

m_Target.RenderState.SourceBlend = Direct3D.Blend.SourceAlpha;
m_Target.RenderState.DestinationBlend = Direct3D.Blend.InvSourceAlpha;
m_Target.RenderState.AlphaTestEnable = true;
m_Target.RenderState.AlphaFunction = Direct3D.Compare.GreaterEqual;

it doesn't work and i dont know why. If i turn on colorop for stage 0 i will see texture of stage 1, else i dont see anything.

Maybe someone knows the requirements for doing such multitexturing operation?

Pascal

p.s: Sorry for my english

Share on other sites
Quote:
 If i turn on colorop for stage 0 i will see texture of stage 1, else i dont see anything

The latter happens because if you disable one texture stage, you disable the later ones as well, and since you disable the first stage you disable texturing altogether.

If you want to achieve some alpha blending (guessing, since you use SourceBlend and DestinationBlend) you have to set m_Target.RenderState.AlphaBlendEnable to true. Alpha test is something else.

It's not quite clear yet what you want do though - my guess is masking one texture with another in 2D. If it's 3D, yeah, maybe you need some alpha test trick then. Could you show us your textures and what you want as result please ?

Apart from that: Can you consider using shaders instead of the fixed function pipeline ?

Share on other sites
Hello Unbird,

If i turn off colorop for stage 0, i can't use only the alpha channel of texture 0? I have to take the colorinformation, too?

I can't use shader for my Application-i have to use fixed function pipeline because the Target-OS is windows mobile.

Thanks
Pascal

Share on other sites
Quote:
 If i turn off colorop for stage 0, i can't use only the alpha channel of texture 0? I have to take the colorinformation, too?

Not necessarily. You enable the stage but you will ignore the color information. If your alpha is in the first stage (first texture), you either propagate all channels or set some dummy for the color other than disable, I think something like this.

m_Target.TextureState[0].ColorOperation = Direct3D.TextureOperation.SelectArg1;m_Target.TextureState[0].ColorArgument1 = Direct3D.TextureArgument.Constant;m_Target.TextureState[0].AlphaOperation = Direct3D.TextureOperation.SelectArg1;m_Target.TextureState[0].AlphaArgument1 = Direct3D.TextureArgument.TextureColor;

Then, in the second stage you take the alpha of the last (i.e. TextureArgument.Current) stage and the color of the current texture:
m_Target.TextureState[1].ColorOperation = Direct3D.TextureOperation.SelectArg1;m_Target.TextureState[1].ColorArgument1 = Direct3D.TextureArgument.TextureColor;m_Target.TextureState[1].AlphaOperation = Direct3D.TextureOperation.SelectArg1;m_Target.TextureState[1].AlphaArgument1 = Direct3D.TextureArgument.Current;

Haven't checked that code myself yet - there even might be typos -, but I think this is a viable approach. I wonder if you also have to look out for some further tweaks to get it working. Getting renderstates right is always tricky, especially with FFP. Maybe I'll find some time later and test it myself. Just report back your progress.
Quote:
 ...because the Target-OS is windows mobile.

Hmmm, so I guess it's pre-WM 7, otherwise you could use XNA 4.

Share on other sites
It works. Thank you but which effect got the argument constant?

Thanks
Pascal

Share on other sites
I'm glad it worked on my first shot [smile].

I can't say if I got your question right though, so will just explain the the ColorArgument.Constant The (color) value will be taken from this stages constant, i.e.
m_Target.TextureState[0].ConstantColor

Like I said, it's dummy, since it will be ignored in the next (and final) stage. No need to set it at all.

Look out though. Reading the DirectX docs I realized that this is not always possible, the device has to be checked if this is supported. This D3DPMISCCAPS_PERSTAGECONSTANT in DirectX, don't know for MDX. But since it's dummy, go for anything suitable. It's also likely that different setups have different performance. You could also consider one-channel only textures (e.g. L8 format). Be aware though, AFAIR in that case you have to treat the "alpha" as a color and likely use the alpha-replicate and/or other tweaks.

Share on other sites
Hello Unbird,

my new problem is that i got gunturrets that aim a target, therefore i use atan2. Now the ship the guns mounted rotate additionaly, that is done by matrix transformations, i use the result of the transformation to determine the new aim. But i got a silly problem, the turrets aim accurrat, but the projectile fly diagonal of gun aiming away. First i seached the problem in the aiming-calculation, but i didn't find a problem. Now i am thinking that the problem could the direction-vectors that i save in a array...

Code:
weapon[cnt].g_Projectile[cnt2].X += (float)(modGraphicExtension.RotVectors[(180+(int)weapon[cnt].g_Projectile[cnt2].Direction) % 360].X * 5f *GraphicEngineNET.GraFX_001_GRAPHIC.AV(0.5f));						weapon[cnt].g_Projectile[cnt2].Y += (float)(modGraphicExtension.RotVectors[(180+(int)weapon[cnt].g_Projectile[cnt2].Direction) % 360].Y * 5f *GraphicEngineNET.GraFX_001_GRAPHIC.AV(0.5f));

for (I = 0; I < 360; I++) {{    RotVectors.X = (float)( (System.Math.Cos((270+I) *					                                            GraphicEngineNET_MATH.GraFX_002_MATH.pi / 180)*5) /					                          Math.Sqrt(Math.Pow( Math.Abs((System.Math.Cos((270+I) * GraphicEngineNET_MATH.GraFX_002_MATH.pi / 180)*5)),2) +					                                    Math.Pow( Math.Abs((System.Math.Sin((270+I) * GraphicEngineNET_MATH.GraFX_002_MATH.pi / 180)*5)),2) ));RotVectors.Y = (float)( (System.Math.Sin((270+I) * GraphicEngineNET_MATH.GraFX_002_MATH.pi / 180)*5) /					                          Math.Sqrt(Math.Pow( Math.Abs((System.Math.Cos((270+I) * GraphicEngineNET_MATH.GraFX_002_MATH.pi / 180)*5)),2) +					                                    Math.Pow( Math.Abs((System.Math.Sin((270+I) * GraphicEngineNET_MATH.GraFX_002_MATH.pi / 180)*5)),2) ));					RotVectors.Z = 0;				}			}

[Edited by - pascalh on July 17, 2010 5:41:56 AM]

Share on other sites
I admit, I do speak German, but please post in English here, since others might benefit from the thread, too, let alone receiving more attention for your problem. And your English was good, by the way. And when posting source code use source tags (explained here and here), it's hard to read unformatted code. Reading the forum FAQs is also a good idea.

Since your new problem does not really relate to the masking problem, having started a new thread would have been more appropriate. I will help, but please make the suggested modifications (you can always make corrections by editing a post).

Edit: Thanks [smile]

Ok, doing a lookup table for performance reasons is fine, but for a start I'd rather use the angles directly until it works.

For a start I'd simplify things: In your table setup you first scale the sin/cos with a constant of 5, and then divide it again by the (re-)calculated length. This is absolutely superflous because
sin(x)^2 + cos(x)^2 = 1

will hold for any x.

So your loop just constructs a pure sin/cos-table in a complicated way. This should suffice:
    for (I = 0; I < 360; I++)     {	    RotVectors.X = (float)( (System.Math.Cos((270+I) * GraphicEngineNET_MATH.GraFX_002_MATH.pi / 180));	    RotVectors.Y = (float)( (System.Math.Sin((270+I) * GraphicEngineNET_MATH.GraFX_002_MATH.pi / 180));	    RotVectors.Z = 0;    }

Quote:
 but the projectile fly diagonal of gun aiming away

Can't tell from here what's the problem exactly, I just hint you to some likely pitfalls. You mention atan2 which is ok, but you haven't showed how you used it. Then your table setup uses a fixed offset of 270 degrees. Please explain why. Then there can always be a left-handed / right-handed system confusion, depending on how you finally draw your stuff, so showing your drawing code could also help. As a shot in the dark: Try using a negated y in the atan2 call (or alternatively a negated y in the table setup).

By the way: Vectors can (mostly) used like base number types, MDX supports operator overloading, too. No need to add/subtract the components manually. (I admit though, you can gain performance in some cases doing it this way).

[Edited by - unbird on July 17, 2010 6:38:12 AM]

Share on other sites
Ok Thank you unbird for the note. But how i can format the sourcecode is c# correct for lang tag?

Greets
Pascal