Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Transparent textures on 3D models Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Tristan

February 22, 2005, 07:01 AM

Hi,

I'm starting to import 3D models (.x) in my DirectX programs. Unfortunately I'm not able to solve the following problem.
Usually when using transparency on objects in direct3D you just sort the polygons from back to front to avoid parts not being drawn because of the z-buffer. When these polygons are on a model you've created using textures with an alpha layer, you won't be able to sort them.
I've created a tree where several branches and leaves are formed by one polygon with a texture with transparency and the tree consists of several of them. I can't imagine that every polygon should be created seperately to be sorted. How do games like Call of Duty and Far Cry do this?

Thanks,
Tristan

 
Corre

February 22, 2005, 07:39 AM

Use alpha testing instead of alpha blending. Then you don't have to sort anything

 
Rui Martins

February 22, 2005, 08:37 AM

The only downside is that you loose the smooth transition, it becomes an on/off feature, each pixel either is fully transparent or fully opaque.

In some cases this is a life saver and can even be suitable depending on the subject matter (object).

 
Axel

February 22, 2005, 09:03 AM

Don't use alpha testing. It will break multisample antialiasing.

 
Tristan

February 22, 2005, 10:12 AM

Alpha testing is no option. When a transparent pixel is drawn, it's also drawn in the z-buffer. The problem remains that objects are not drawn behind a transparent pixel if it's drawn afterwards.

Besides, it's ugly!-)

 
Francis

February 22, 2005, 10:46 AM

The method that will work in all cases to render objects with transparent materials is:
1. Enable front-face culling
2. Render your object as usual
3. Enable back-face culling
4. Render your object as usual

This way, you'll be sure that all your transparent faces will be handled perfectly althought rendering will take more time. You could also try only rendering using steps 3-4 if you don't mind your "front-faces" not being rendered.

 
Tristan

February 22, 2005, 12:09 PM

That will only work when the object is convex (like the windows in a car). In most models it is possible to have two front-face polygons overlapping. When the closest one is drawn first, the other is not drawn because of the z-buffer. Think of my tree with a lot of branches in various orientations.

 
theAntiELVIS

February 22, 2005, 02:59 PM

The only sure way to accomplish this is D3D is to make the transparent parts a separate mesh and draw all transparent meshes in the model last.

 
ganchmaster

February 22, 2005, 03:52 PM

As you can see from the previous posts, this can be a difficult problem.

The best way to deal with this is to use alpha-testing if possible, as opposed to alpha blend. A previous poster seemed to say that alpha-failed pixels write into the zbuffer; this is not true. The original post mentioned Far Cry; a ton of foliage in that game is drawn with alpha test leaf textures. Obviously it's not filling the Z buffer when it does that.

There are a couple of potential problems with using alpha test; it can decrease the efficiency of Z culling optimizations on some PC hardware, and it can cause problems for stencil shadows. But if you have to use it, you have to use it.

It is possible to render using true blending also. The method Francis suggested will not work in general (concave objects, and why would you want to render all the backfaces?). One way is to break the translucent parts into a separate mesh as theAntiElvis suggested. This will still have problems if the translucent parts do not form a convex object.

One way to handle more complicated objects with translucency is to first, only render objects with translucent parts after all other models, and sort them as you would any translucent object. Render the object to Z buffer only. Then render the object using alpha blend with Z testing. Only the pixels nearest to the viewer will be rendered. This is good for things like a whole character fading out (due to distance or removing a camera obstruction, for example). But it won't help you if the object has multiple layers of true translucent materials that need to be visible.

You might also try looking up "depth peeling".


 
Moe

February 22, 2005, 04:14 PM

You donít need an extra mesh. You could also use subsets.

Render all opaque parts sorted from near to far or/and using z buffer (only front faces). Then render all transparent parts from far to near (front and back faces if an object is translucent you will actually see the back faces).

You might get more accuracy if you write your own shader witch checks but doesnít write the z buffer for your transparent objects (instead of sorting by distance).

 
theAntiELVIS

February 22, 2005, 06:59 PM

Yeah - I meant use subsets. Either way as long as you can draw the parts independently.

 
Tristan

March 01, 2005, 07:22 AM

Thanks for all the help.

Alpha testing works, but there is no antialiasing possible. It's very ugly! will mipmapping help?

Thanks,
Tristan

 
eulogy

March 01, 2005, 07:31 AM

Sorry about the double posting.. I'm not used to this forum yet :P

I've had the same problem, but haven't found any good solutions. Sorting polygons will slow down the whole engine alot (you may have to switch textures and shaders all the time). Another problem is the sorting. Sorting by midZ is for instance not good enough, since it doesn't do a perfect job. How does games handle this?

 
eulogy

March 01, 2005, 07:32 AM

I've had the same problem, but haven't found any good solutions. Sorting polygons will slow down the whole engine alot (you may have to switch textures and shaders all the time). Another problem is the sorting. Sorting by midZ is for instance not good enough, since it doesn't do a perfect job. How does games handle this?

 
This thread contains 14 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.