   [MDX - Solved] texture transparency
  Ok, I have some trees that need some texture transparency on the branches.It uses this texture:I am using D3D10 and what I am looking to know is how I go about removing the black pixels? and does anyone have any sample code I can look at?Thanks.[Edited by - campbellec on March 26, 2006 2:34:56 AM]
  The easiest, most scalable solution is to just use a texture with an alpha channel.  Then you don't need code to procedurally generate a transparent texture, which may not apply to anything else.  I recommend using the DirectX Texture Tool distributed with the SDK.  You can create a new texture with an alpha-supporting format (probably A8R8G8B8) with the dimensions of your image.  Then open your image onto the surface of the texture.  Then open your image onto the alpha channel of the same texture.  I believe that the white pixels will be interpreted as full transparency and you will have a transparent texture that you can save in *.dds format....Now that I think about it, I believe black is interpreted as full transparency, so open your image in paint, invert colors, and apply the inverted version to the alpha channel.Once this is done you should be able to load the *.dds file directly and apply it to your branches.   ;  Thanks.   ;  After posting, I realized there may be a problem with the solution I proposed.  The texture tool will interpret and color value applied to the textures alpha channel as SOME alpha value.  For the sake of generality, it does not just treat black pixels as transparent and non-black pixels as non-transparent.  Since you probably want your leaves to be fully opaque, you may need to, as I recommended against earlier, write some simple code that will go through your image and replace any non-white pixel color with black.  Then my solution will work the way I meant it to.   ;  After making the .dds texture I got the same result.  I then added this code to my render from the MDXinfo.com site:Quote:deviceRenderState.SourceBlend = Blend.SourceAlpha; //set the source to be the source's alphadevice.RenderState.DestinationBlend = Blend.InvSourceAlpha; //set the destination to be the inverse of the source's alphadevice.RenderState.AlphaBlendEnable = true; //enableAnd this is what I got:As you can see, each branch is now transparent for everything else rendered except the other branches of the same mesh.  What can I do to fix that?  Let me know if you need more info.   ;  your original texture already had alpha. (it was transparent in my browser anyway).afaik you have to render alpha textures in far to near order for them to overlay correctly. thats going to impossible if theyre intersecting.you could split each 2 overlapping billboards into 4 non overlapping billboards i guess, but its still a fairly complicated sorting problem.;  The easiest solution for this is probably cullmode sorting (here's a MDX code snippet for that) if you really want to use alpha blending. I'm not 100% sure it will work for your leaf mesh, but I guess it's worth a shot. Other than that, you might want to resort to alpha testing instead of alpha blending. I haven't got any first-hand experience with that, but from what I've heard this does not require depth sorting, eliminating your problem. The downside to alpha testing is that you can only have full or zero opacity, so no blending in between. With sufficient distance between the mesh and the camera and/or sufficiently big texture sizes, this shouldn't be too noticable though.You can use Alt+PrintScreen to only capture the active window by the way, might be a useful tip [smile]   ;  Thanks for your reply!  I tried alpha testing and it worked perfectly.Here is the code I added to my render for alpha testing if anyone else has this problem sometime:Quote:  device.RenderState.AlphaTestEnable = true;  device.RenderState.ReferenceAlpha = 0x08;  device.RenderState.AlphaFunction = CompareFunction.GreaterEqual;;Quote:Original post by campbellecThanks for your reply!  I tried alpha testing and it worked perfectly.Here is the code I added to my render for alpha testing if anyone else has this problem sometime:Quote:  device.RenderState.AlphaTestEnable = true;  device.RenderState.ReferenceAlpha = 0x08;  device.RenderState.AlphaFunction = CompareFunction.GreaterEqual;So hows it look?  Care to share a shot?   ;  Sure[Edited by - campbellec on March 26, 2006 3:54:18 AM]