Advertisement

why sort when you can glDepthMask ?

Started by April 04, 2002 02:53 PM
3 comments, last by nitzan 22 years, 10 months ago
Why would I ever want to sort blended particles and display them farthest to nearest when I can just use glDepthMask(0) drawBlendedParticles() glDepthMask(1) Nitzan ------------------------- www.geocities.com/nitzanw www.scorchedearth3d.net -------------------------

Because if multiple blended objects are in the same place, they don''t blend properly unless they are sorted.

Imagine looking through a series of tinted windows of various colors. Unless you sort the windows properly, you might end up with the tint adding together in an incorrect away. (Parts might be red that should have been blue.)
Advertisement
Would it ? Wouldnt I always get the same color ? I mean I am thinking about looking through some see thru film... like the one they use for red/green 3d glasses, and it seems to me I would see the same color no matter what order the films were in.

I just never got the chance to look through a bunch of tinted windows all lined up...

Nitzan

-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
quote:
Original post by nitzan
Would it ? Wouldnt I always get the same color ? I mean I am thinking about looking through some see thru film... like the one they use for red/green 3d glasses, and it seems to me I would see the same color no matter what order the films were in.

I just never got the chance to look through a bunch of tinted windows all lined up...





If you''re using additive blending (like your film example), it doesn''t make a difference. If you use multiplicative or blend based on alpha channels (like glass which has varying amounts of transparency) it does make a difference.
quote:

Would it ? Wouldnt I always get the same color ?


No, you wouldn't. Standard blending ( c = a * f + b * (1-f) ) is not cumulative. A bit like with matrix math, the order of the operations is important.

Eg.

colour_1 BLEND ( colour_2 BLEND colour_3 )

is *not* equal to

( colour_1 BLEND colour_2 ) BLEND colour_3

Both will produce different results.

The only blendmode where this works is additive blending, but it doesn't give visually appealing results. And, of course, multiplicative blending, but you don't want to use that for transparency.

[AP: multiplicative blending is order independend, just as additive is]

/ Yann

[edited by - Yann L on April 4, 2002 4:45:02 PM]

This topic is closed to new replies.

Advertisement