Skip to main content
GameDev.net gamedev.net
🔒 Locked

Alpha blending without sorting?!

Started by godmodder Jul 25, 2006 at 9:25 AM 13 replies 7k views
Original Post
godmodder
godmodder
Hello everyone, I've read somewhere that the use of destination alpha can (partially) solve the issue of having to sort transparent objects for proper blending. It wasn't practical in the old days because almost no card supported it, but it IS supported on allmost all graphics cards nowadays. It seems that this technique has somewhat slipped away from most programmers' mind, cause I can't find many recent sources about it. Has anybody got any experience on how to use destination alpha to render transparent objects? It would be great to render them allmost perfectly (I can stand a few glitches) without the damned sorting. Thanx, Jeroen
wolf
wolf
How about emulating alpha blending in the pixel shader as described in ShaderX2 by Francesco Caruzzi?
Matt Aufderheide
Matt Aufderheide
while nice blending can be acheived using the blend modes, It doesnt really solve the sorting problem: either a pixel writes to the z buffer or it doesnt.

however, Carmack has discussed a novel way of doing order-independent transparency: render all translucent objects to a separate screen-sized render target, with alphablending off, and alphatest on, using a sort of dither pattern to approximate the level of alpha. Then blur the result a bit somehow, then render the final thing to screen aligned quad, using dest alpha. I dont see why this cant work for most purposes.
godmodder
godmodder
Could you point me to an article of Carmack explaining this technique. Or do could you elaborate on it a bit more? I'm very eager to learn about this new way to handle transparency.

Jeroen
l0calh05t
l0calh05t
doesn't sound really "novel" to me, as that seems to just be an advanced form of screen-door transparency. btw, you might want to check out "alpha to coverage" as seen in http://www.humus.ca/index.php?page=3D&ID=61
godmodder
godmodder
Thanx for the replies everyone,

I want to render transparent glass in my game. Is alpha coverage even an option here? Anyway I'd love to here about the way Carmack handles this. A clicky to an article/tutorial would be very much appreciated.

Jeroen
M2tM
M2tM
I've heard of a method which involves multiple renders and the accumulation buffer to get it to work without sorting, but I've never tried it myself. That's the only thing I've seen refrencing it properly and regretfully I don't have the article, hopefully it helps.

EDIT: Here is a paper on it http://developer.nvidia.com/object/Interactive_Order_Transparency.html though I don't know if this is the technique I was refrencing or not. It's called "depth-peeling"
_____"You're using a screwdriver to nail some glue to a ming vase. " -ToohrVyk
l0calh05t
l0calh05t
Quote:
Original post by godmodder
Thanx for the replies everyone,

I want to render transparent glass in my game. Is alpha coverage even an option here? Anyway I'd love to here about the way Carmack handles this. A clicky to an article/tutorial would be very much appreciated.

Jeroen


i think alpha to coverage should look ok for glass (alpha blending isn't particularily realistic for glass either), best you just try it, for example download the humus demo and replace the wire mesh texture with your glass texture (just draw the appropriate alpha into the texture map). source code should also be included with the humus demo, so that's a good starting point for understanding the usage. (basically just load the extension, and enable/disable the right variables)

depth peeling is way too slow on most current graphics cards
Matt Aufderheide
Matt Aufderheide
It's in this QuakeCon talk by Carmack, I'm surprised everyone here hasnt read this :)

http://www.gamedev.net/community/forums/topic.asp?topic_id=266373

His method is more complicated than I described, but thats the basic idea. I dont really get this alpha-to-covereage method though..
AndyTX
AndyTX
Alpha to coverage does exactly that: it uses the pixel alpha to generate the fragment's "coverage" mask. Thus if you're using N-sample multisampling, you get N levels of "free" sorted transparency levels.

It's certainly not a perfect solution, but it's practically free if you're using multisampling already, and works well enough for small objects. Larger objects can be easily sorted.

The only really sure-fire method that will work in all circumstances is to sort per-fragment... depth peeling seems to be the best current option for that.
godmodder
godmodder
I always thought alpha to coverage was a technique for alpha-TESTING and not for alpha blending. Can you even render glass with alpha-testing only?
It would be great though, because that would remove all my sorting issues ;)

Anyway, about alpha blending not being realistic for glass. I can't really think of any other method that is realtime and practical in games. The proper way of doing glass I think would be to simulate some kind of refraction, but all the demos I've seen all use a cubemap for this. I don't know, but using a cubemap sounds like very hard to get right in all scenes and it would be dog slow. Is there another solution to refraction that doesn't use cubemaps?

Actually when you think about it, it's absolutely crazy they're using cubemaps for refraction, because refraction only needs the geometry BEHIND itself, unlike reflection where you do need information about the whole scene.

Please help me out of this transparent mess, I'm kind of lost by the overwhelming possibilities,

Jeroen
Krokhin
Krokhin
Depth peeling-the best way and general solution for all cases,but low performance:(( Actually in real scenes only few objects needs DP,
and other can be drown using bound-box sorting and different,object-specific tecniques.For example, good(almost) solution for transparent glass,which
can't be sorted because of bound-box intersection- ZENABLE=TRUE,ZWRITEENABLE=FALSE

btw,for realistic appiarance of flatless glass you can use common cubemap for reflection,refraction and specular highlights.
Refraction without cubemaps-try transparent EMBM
(Bump lens example -see DX SDK)

[Edited by - Krokhin on July 26, 2006 6:26:33 AM]
AndyTX
AndyTX
Quote:
Original post by godmodder
I always thought alpha to coverage was a technique for alpha-TESTING and not for alpha blending. Can you even render glass with alpha-testing only?

I wouldn't think of it as either... it literally puts the alpha value into the coverage mask of a multisampled fragment.

Quote:
Original post by godmodder
It would be great though, because that would remove all my sorting issues ;)

What "issues" are you having? If it's just large objects (ex. panes of glass), they're generally easy to sort. Things like grass are too expensive, but tend to look fine with alpha->coverage.

Quote:
Original post by godmodder
Is there another solution to refraction that doesn't use cubemaps?

You can render a planar refraction map from your viewport and lookup into it. It's not perfect, but it works well for smaller indices or refraction.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.