# Feathering with Alpha Blending

This topic is 4520 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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;          } }

##### Share on other sites
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]

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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?

##### Share on other sites
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.

##### Share on other sites
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.

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 9
• 23
• 9
• 32
• ### Forum Statistics

• Total Topics
632619
• Total Posts
3007496
• ### Who's Online (See full list)

There are no registered users currently online

×