Drawing alpha-tested foliage nicely (WARNING: image heavy)

Started by
37 comments, last by DonnieDarko 16 years, 9 months ago
Quote:Original post by Matt Aufderheide
That's because these shots are a worst-case scenario--black tree with fine detail against a light background.. is guarenteed to look bad with alpha-to-coverage.
Isn't that pretty much the standard scenario for trees? You'll see dark colored foliage against a light colored sky, except at night -- and you can't see jack at night anyway so who cares?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Advertisement
Quote:Original post by Matt Aufderheide
That's because these shots are a worst-case scenario--black tree with fine detail against a light background.. is guarenteed to look bad with alpha-to-coverage.

In my experience, A2C is far better than this two-pass method, which is terrible for fillrate. Imagine doing a grass field with the two pass method...impossible. How often do you just have one tree standing alone?

Also this is very low-poly-looking tree; most trees in modern applications are higher poly, 5000-8000 at the nearest LOD with a LOT of overdraw for dense foliage. The two-pass method is a clear loser.

That's seems pretty closed-minded. As AndyTX pointed out, the two-pass is just another tool in the toolbox, there to use when it's most useful. Not every game is set in a dense forest or lush pastures.

No-one said anything about a single tree. But in any case there are scenarios where a single tree might indeed be rendered; say in a garden in an urban area. There are plenty of games set in sparsely forested outdoors areas; most of World of Warcraft, Guild Wars, Half-Life 2, just to name three.

Flat Out, which was the game I discovered the idea being used in, renders hundreds of trees and bushes per frame using the two-pass method and that is not a slow game by any means. For them it was more important to render low-poly trees that looked good whilst moving fast, than it was to have high-poly trees that sparkled with motion.

And talking of worse-case scenarios, you're right, the above pictures are not the best for A2C. I've rendered forests of trees using each method and there were angles where there was no noticeable difference between A2C and two-pass (and some where even alpha-testing looked as good), but there were also other angles where A2C looked worse than even alpha-testing.

The thing was, there wasn't a single angle that made the two-pass look bad. In every instance I tried it matched or exceeded the quality of the other methods, sometimes by a large margin.

For me, two-pass is a clear winner but only for those times I can afford to burn the extra fill-rate (and that's assuming you use the fixed-function pipeline - it may be possible to single-pass it with a custom fragment shader).

But hey, I'm not gonna lose sleep over it if you never use it. :-)
in my experience when rendering foliage, overdraw is by far the biggest problem. Doing two passes will obviously increase this, therefore, when taking into consideration the complex lighting models and large amounts of foliage detail that realism demands, two-pass rendering is a bad idea in the general case.

Alpha-to-coverage is not a perfect solution, yet provides far better performance in a real-world situation.
I`m with PlayerX here. If nothing else, this technique works great for screenshots and videos. In worst case, the framerate should be just halved. So, if quality is necessary, I believe it`s great to have something like that.

Also, with future HW in mind, one could implement this as a "High Quality" setting for trees rendering and leave regular Alpha testing as "Medium Quality" - thus anyone can choose whether he wants sparkling trees or les smooth framerate.

And who says you can`t have both worlds ? Since these methods are separate, you can easily switch between them automatically, based on framerate ("Auto detail" setting) or amount of trees in frustum (or near player).

I`m definitely going to implement this in my engine (I too am frustrated by regular alpha testing) and am glad PlayerX shared his findings.

VladR My 3rd person action RPG on GreenLight: http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

Quote:Original post by PlayerX
For me, two-pass is a clear winner but only for those times I can afford to burn the extra fill-rate (and that's assuming you use the fixed-function pipeline - it may be possible to single-pass it with a custom fragment shader).

But hey, I'm not gonna lose sleep over it if you never use it. :-)

In my eyes, that two-pass technique that you explained looks very nice, and I didn't know about it before. Personally, I'd rather reduce the world detail and do two nice-looking passes than one with artifacts. So thanks a lot for your well-illustrated explanation! [smile]
It's always good to know tricks like that, if I'm doing something similar later it's good to know about it.
Why not use alpha testing with blending (fast, looks pretty good), and then use this texture preparation technique to get rid of the "fringe" artifacts:

http://www.vterrain.org/Plants/Alpha/index.html
No this doesnt work. The fringing isnt a result of bad alpha masking, but an artifact of the zbuffer. So there will be a halo around the edges of the foliage because of the z-writes blocking anything drawn out of order.

Of course you can get rid of the halo by setting the alpha mask to either black or white, but then that's the same as alpha testing....

...

However, I have come up with a way of getting smooth edges with perfect z sorting, wihout A2C or 2 passes!

It' quite simple: render all the foliage using a different screen-sized render target, and the same zbuffer you use for normal rendering. Render the foliage using normal alpha testing (but make sure your render target has an alpha channel, and you clear the alpha channel as well as the rgb every frame..this messed me up for a bit).

Then simply render the texture to a screen-aligned quad, and combine a fast 4-tap blur filter with a simple sample for sharpness, and enable alphablending, and disable alphatest and zwrites.

Then you have your soft-edged foliage without any z-errors or artifacts, and only one pass of geometry..this makes it appropriate for grass fields, forests, etc.. I think it would be best to make sure you render foliage after everything else has been rendered.

[Edited by - Matt Aufderheide on July 24, 2007 5:38:03 AM]
Quote:Original post by Matt Aufderheide
No this doesnt work. The fringing isnt a result of bad alpha masking, but an artifact of the zbuffer.


Right, good point.

Quote:Then simply render the texture to a screen-aligned quad


Wouldn't this end up drawing the foliage quad on top of objects that the foliage is supposed to be behind?

No becasue you use the same z buffer form the main scene when you render the foliage... that way there is correct z sorting no matter what.
Just so you're aware, your idea of using a different render target but the same Z buffer is likely to cause serious frame corruption if antialiasing is enabled via the driver control panel, and it's flat out illegal if you enable multisampling in your app. (It might still pass, at least under release mode DX, but again, you're likely to get corruption.)
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

This topic is closed to new replies.

Advertisement