Jump to content
  • Advertisement
Sign in to follow this  
Alex Red

Ideas for Alpha Blending V ZBuffer

This topic is 4883 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

Hi guys... I am considering fixing an Alpha Blend V Zbuffer problem already present in a DX7 engine I am rewriting... The problem is the usual... Alpha Blended surfaces drawn before others do not mix anymore with underlying surfaces drawn after, having Alpha Blended Holes in surfaces as a result... I am evaluating many solutions, from ZBufeer disabling on Alpha Blending, to cache alpha blended surfaces to be drawn after all... looking for Texture Stages solutions too... I'd like also to receive new Ideas for solutions or Advices if any1 has... tnx [R]ed

Share this post


Link to post
Share on other sites
Advertisement
The classic solution is to draw all opaque geometry front-to-back (although, this doesn't really matter) and then render all semi-transparent objects back-to-front (the order is important). If you can afford the extra draw calls, doing a 2-pass approach of back faces then front faces for each semi-transparent object works quite well.

As for Z Buffer related tricks, don't completely disable it, just turn off Z-Writing (keep Z-Testing) if you want - this is quite common for particle systems, although, beyond that it starts to look a bit rubbish.

hth
Jack

Share this post


Link to post
Share on other sites
Yep...
Tnx JokllyJeffers... the solution I was thinking was this one... and of course I disable only Z-Write...not the buffer...
The problem I am thinking too is that a scene in this game may be very complex, and sorting may be a nice time costing feature...
but for now, ur solution seems the best...

tnx

[R]ed

Share this post


Link to post
Share on other sites
If you want to avoid sorting your options are (and I don't know their d3d names):
a. Alpha testing. Grass, railings etc.
b. Only additive blending. Explosions maybe.

Both of which can be useful at times, but aren't really worth thinking about for glass or similar.

Share this post


Link to post
Share on other sites
This is something that I've mentioned before, but sorting is not as expensive as you'd think. The assumption is (if you sort every frame), if an object is sorted in one frame, then chances are it will be sorted the next frame; games run at high frame rates and objects don't just jump positions randomly, but rather move.

With an already sorted or nearly sorted set, running an insertion sort is a linear time function. I'm sure you can afford visiting every object once a frame, as you probably do it multiple times for movement, drawing, logic, etc.

--Vic--

Share this post


Link to post
Share on other sites
You can also work to keep the number of transparent objects down to a minimum. Really, besides special effects and a few materials such as glass, there isn't that much that needs to be transparent. You might have maybe 10-15% of your scene transparent at any given time, and if that only consists of 100 objects, sorting wouldn't take that long (quicksort averages O(xlog(x)), meaning ~200 swaps for 100 objects, and that's if you do a quicksort every frame).

Now, if everything in your game is transparent.. that might be another issue!

Share this post


Link to post
Share on other sites
Tnx for advices guys...
I found the right solution...
Each object caches it's Alpha surfaces while drawing..
All Alphas are drawn at last, with ZWRITE and BACKCULLING Disabled.
this way need no sorting, Alpha Surfaces will be compared in ZBuffer with all 'Solid' objects already written, but will eventually overwrite other alpha surfaces making Translucent over Translucent possible in any order...

tnx to all for interest

[R]ed

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!