Archived

This topic is now archived and is closed to further replies.

Alpha in texture makes whole model transparent

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Why does D3D seem to turn an entire model transparent when it has an alpha layered image applied to any part of it? For example, if you have a sphere mesh with a solid texture, and a cube mesh with an alpha texture, and these meshes are put together in an X file, and drawn in the same call: If you look at the sphere through the cube, it''s invisible. Doesn''t seem right, does it? Anyone know why or what setting I need to adjust? Or is it just my video card? Thanks for any suggestions

Share this post


Link to post
Share on other sites
It''s probably drawing the box first, with ZWRITEENABLE set. Then the sphere is drawn, except it fails the Z test, as the Z buffer was filled in by the box. Partially transparent objects must be drawn after all solid objects, and must be drawn in back to front order, in order to blend correctly. Yes it sucks, but it''s a fact of life with the way all current cards (and all cards in the forseeable future) work.

You will need to draw these objects (or parts of objects) seperately, rather than in one call. You''ll need to be able to queue each object or part of object you need to render. You''ll need to develop some form of sorting function to sort solids first, and transparent objects last, and by decreasing Z. Preferably you''ll sort the solids by texture/effect and increasing Z too.

Share this post


Link to post
Share on other sites
I don''t have the problem unless the object overlaps itself. Are you saying that even seperate models need to be sorted?

Even if not, what about thin layers of hair which go completely around the character''s head? Obviously the thin plane wrapped around the head is going to overlap itself at almost any perspective. It would be impossible to sort unless you did so on the triangle/face level.

Surely there is another way?

Share this post


Link to post
Share on other sites
Yes, you won''t get Z problems unless two meshes or parts of a mesh share the same Z.

D3D draws things in the order it''s given to it. Lets say you clear your background to black. Next, you draw a 50% blended red box at Z=50. Next, you draw a solid blue box at Z=200, behind the red box. What do you expect to see?

D3D will draw the red box, blending with the existing black background data, and fill in the Z as 50. When you try to draw the blue box, it just knows that a Z of 200 can''t draw over a Z of 50.

Ok, so lets disable Z writes and try again...

D3D will draw the red box, blending with black. Next, the blue box will be drawn solid. Despite being further than the red box, it''s not blended with it in any way. You see, D3D doesn''t know there was a red transparent thing in front, it just knows it''s supposed to draw a blue box with no blending.

Ok, lets try one more time, with what I''ve described...

We draw solid objects first, so we draw our blue box. Next we draw transparent objects back to front. So we now draw a red box blended 50% with what''s already there...some black background, and some blue box. If there was another box closer then Z = 50, we''d draw that next.

Graphics cards are extremely simple and dumb. They don''t take the entire scene into account, they just draw with the operations you specify when you ask it to.

Things like hair, leaves, etc. are the bane of engine programmers existances. We try to use alphatest instead of blend if we can. Sorting transparent objects, poly for poly, is the extreme case, which usually isn''t necessary.

Some transparent objects can be rendered with a Z first pass, then a color pass. For other objects that produces the wrong effect (can see back side faces, or overlapping sections of mesh, like arms, on other side). Some objects can be broken down into several convex meshes, which can each be sorted and rendered. This is almost as good as sorting poly for poly.

There is a lot of research going into techniques for order independant transparency, but as far as I know, it''s still one of your biggest headaches as a graphics engine coder.

Share this post


Link to post
Share on other sites