   multi-texturing problem(c#)
  Hello all. I am really stuck with a problem and can't figure it out. I have exhausted all sites I could find with information on multi-texturing, and they are not very helpful. Here's the problem:I have made 2 bitmaps. One is a simple green colour. The other is white and grey. They are just two simple things I threw together to test multi-texturing. I wanted the green file to represent a terrain colour, and the other bitmap a detail overlay. Okay, so I load both textures into the app. The green one is called texGreen, and the other is texMask. Now I here is what I don't get:device.SetTexture( 0, texGreen);device.SetTexture( 1, texMask);device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;device.TextureState[1].ColorArgument1 = TextureArgument.Current;device.TextureState[1].ColorArgument2 = TextureArgument.TextureColor;device.TextureState[1].ColorOperation = TextureOperation.Modulate;As I understand, the following is going on: Make the first argument the texture (green) and pass it to stage 1. In stage 1 set the texture (green) to arg1 and modulate it with arg2 which is set to the texture (mask). Then produce the result - which in my thinking is a mixed texture combining both the green and mask bitmaps. Instead, I only see the green texture and that's it. But if I swap the setTexture functions round like this:device.SetTexture( 0, texMask);device.SetTexture( 1, texGreen);It then works...Why is this happening? Am I misunderstanding what's going on here? Thanks for any help you can offer - I am about to pull out my hair :)[Edited by - SavyCat on June 22, 2006 3:10:49 AM]
  I changed the title to something a little clearer. Can anyone give me some help with this? Thanks.   ;  AFAIK the order of the arguments for a modulate operation should not matter indeed, so I don't think this is the correct behavior (please correct me if I'm wrong though). According to Tom's DX FAQ, various cards (pre SM2 mostly) have various issues with handling the texture stages correctly. You could try switching to the reference device to find out what would be the expected behavior, but even if that shows it doesn't matter, it won't do you much good if it doesn't work for your card. Just keep this order if it works [smile]   ;  Thanks remigius, I tried it and it still is doing the same thing - very odd. I have a radeon 9600 / 9700 mobility chip. It has never had any problems before... Let me try adding more bitmaps and see what happens.   ;  There's a way to find out that requires less effort: use MFCTex.exe, a program from the DXSDK 8.1 samples. It allows you to try out different texture stage setups and even shows the corresponding code (C, though). You can easily translate the code to C# as the names of the parameters haven't changed that much [wink].Good luck!Pat.   ;  Would the texture loaded into stage 1 have the same UV co-ordinates as the co-ordinates in stage 0? It seems that the texture is not getting properly loaded into stage 1 or maybe its UV co-ordinates are different. Because if I do the following: device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor;device.TextureState[1].ColorOperation = TextureOperation.SelectArg1;the texture I loaded into stage 1 should be displayed right? Instead the texture is not displayed - just a single colour. Is this a mapping problem maybe? I know it's not my PC as I downloaded a multi-texturing tutorial which worked fine. The only difference that I could see, was that they used a different directX version. Thanks again :)   ;  It might indeed have something to do with the texture coordinates. I haven't worked with the texture stages much (shaders get the job done easier imo), but IIRC each stage uses the texture coordinates at the same index as the stage index by default. If these don't exist the coordinates will default to (0,0), which would be a cause for your problem. The following line of code should fix your problem:device.TextureState[1].TextureCoordinateIndex = 0;Essentially this tells your device to use the coordinates from stage 0 for stage 1 as well.   ;  Yes! Thanks remigius it worked! I was getting so irritated with this. Would going to shaders be easier? If so, know where I can start learning? Thanks guys, you have been very helpful!   ;  Glad to see it worked out [smile]Shaders aren't necessarily easier to code, but using them you can focus on implementing your desired effect, instead of wrestling with the details of the texture stage API and others. You'd typically just set the two textures as shader parameters, after which you can do:OUT.Color = tex2D(maskSampler, IN.texCoords) * tex2D(colorSampler, IN.texCoords);This is just some example code, to give you an idea of what HLSL shaders look like and if it works for you. On MDXInfo you'll find some HLSL tutorials that should get you started. IIRC these tutorials don't go too deep with pixel shaders though, but once you understand the general technique you could look at the freely available sample shaders from NVidia, ATI and MS to see how they get things done. You'll also find extensive information on shaders and the Effects framework (part of the DX API that facilitates the use of shaders) in the unmanaged SDK documentation.Numerous advanced effects are much easier to code using shaders, or even impossible to code without them. It might also be worth mentioning that the Fixed Function Pipeline (the texture stages, lighting etc) will no longer be supported in D3D10, which will exclusively use shaders for this functionality. There's no need yet to drop everything and go learn shaders, but it certainly won't hurt to get familiar with them.   