Feathering with Alpha Blending

Started by
11 comments, last by DonnieDarko 17 years, 11 months ago
I've been looking into ways to render vegetation and make it look good. On grass I tried alpha blending which looks great, but the sorting was a headache. I tried alpha testing, but the edges are so aliased it looks like crap from up close. So then I read in the GPU Gems 2 article "Toward Photorealism in Virtual Botany" of what the author calls 'feather the edges' into the scene. I got this working and I wanted to show the results. First, take a look at this grass with alpha testing only. And here is the result with the 'feathered edges'. This shot shows the difference in red. The good thing about this technique is that it looks just like alpha blending only, and it is effective even when only applied to nearby vegetation. The bad thing is that it takes an extra pass. But it's definately a step toward getting away from the ugly alpha tested look.
Advertisement
Oops I forgot to show the implementation. The technique sums it up nicely.

technique SM11{	pass P0    {      VertexShader = compile vs_1_1 vs11();      PixelShader  = compile ps_1_1 ps11();      AlphaBlendEnable = true;      SrcBlend = SrcAlpha;      DestBlend = InvSrcAlpha;      ZWriteEnable = false;          }        pass P1    {      VertexShader = compile vs_1_1 vs11();      PixelShader  = compile ps_1_1 ps11();            AlphaTestEnable = true;      AlphaRef = 0x00000040;      AlphaFunc = GreaterEqual;      ZWriteEnable = true;          } }
Hmm, I really have to pay more attention to what I'm reading. I've had that book for quite a while, but I completely missed the feathered edges thing and was planning on using plain alpha testing myself for a project. Thanks for pointing it out & showing the results [smile]
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Isn't the passes defined in the wrong order? The way I see the technique it would work best by rendering opaque vegetation geometry first which would setup a correct depth buffer and then render alpha blended parts. The idea is that only minor artifacts are visible where alpha blended plant edges overlap.
I tried it the other way around and noticed more obvious artifacts. I can't think of a good explanation for this though, the way you described seems to make more sense.
The order seems to be correct from the way I understand this technique. Basically you use alphablending first to render the geometry. This step would normally suffer from sorting issues, but since we're only interested in the outer edges, we don't care about these artifacts.

Next we render the opaque geometery on top of the alphablended meshes with the alpha test. This will cover the areas where the 'no sorting artifacts' were apparent, effectively leaving only the featered outer edges of the first alphablending render pass visible.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
That seems to make sense too, I just thinking that it does involve alot of unnecessary overdraw. Why draw the alpha blended areas with sorting artifacts in the first place if they are going to be covered up in the following pass by opaque geometry?
Yep, you're indeed stuck with at least one overdraw in the best case of a simple quad, but I guess that's both easier and generally more efficient than sorting for alphablending, especially when it comes to sorting mesh subsets like branches.

The overdraw doesn't seem unnecessary though, since it serves to cover up the noticable sorting artifacts on the opaque parts of the geometry. The transparent regions of the 1st alphablend pass will be preserved because of the alpha-test in the 2nd pass, giving the geometry it's feathered look... You could reduce the overdraw by using an alpha test on the 1st pass as well (to draw only for Less than the alpha threshold) but I think the testing is probably less efficient than just drawing it twice.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
My point was that sorting the geometry is not needed in either case. I think they should look more or less the same with only the overdraw being the difference.
Sorry about the confusion, I already had a feeling I was missing your point [smile]

Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!

This topic is closed to new replies.

Advertisement