   [.net] Create a texture using a seperate texture as the alpha
  Hi,  I have been trying to find out how i would create a texture with an alpha channel from two textures.Texture a would be the normal texture and texture b would be the alpha channel.A+B = C kinda thing.I tried locking the textures and placing them in the new texture but only ended with with a kinda ghost effect.Thanks for any help,   -Dave   
  So you want to keep them as separate textures and combine at rendering time, or do you want to actually replace the A's alpha channel with B's? The former can be done with pixel shaders (or the stencil buffer on some cards I think); for the latter the simplest way should be to lock the two surfaces and set A's alpha value = B's, pixel by pixel.;  Yea i have two textures, and i want to combine them into a third.Texture one will the the image.Texture two will be the alpha.Texture three will be the combination of these.Basically im trying to find out how i can add an alpha channel to an exsisting texture.Thanks for the help, sorry if my explaination of what im trying to do is a bit left of center,   -Dave   ;  Create a 32-bit surface (Format.X8R8G8B8 or Format.A8R8G8B8).Basically, for each pixel, you doclr = surfaceA.GetPixel(x, y);alpha = surfaceB.GetPixel(x, y).A;clr = Color.FromArgb(alpha, clr.R, clr.G, clr.B);surfaceC.SetPixel(x, y, clr);This is very slow, though. It's better to use unsafe pointer operations but that code would be too long here. If you want, I've got wrapper classes that handle this (for both Bitmaps and Surfaces) - you use pretty much the same code as above but it's many times faster.   ;  Nice one Jonas, that worked perfect.Thanks for the help,   -Dave   ;Quote:Original post by Jonas BCreate a 32-bit surface (Format.X8R8G8B8 or Format.A8R8G8B8).Basically, for each pixel, you doclr = surfaceA.GetPixel(x, y);alpha = surfaceB.GetPixel(x, y).A;clr = Color.FromArgb(alpha, clr.R, clr.G, clr.B);surfaceC.SetPixel(x, y, clr);This is very slow, though. It's better to use unsafe pointer operations but that code would be too long here. If you want, I've got wrapper classes that handle this (for both Bitmaps and Surfaces) - you use pretty much the same code as above but it's many times faster.You an avoid unsafe code by using locking the surface, getting the pointer, and then using Marshal.Copy() to copy into managed byte arrays. It's not as efficient of course, but is better overall.   