Jump to content
  • Advertisement
Sign in to follow this  
peon1234

How is foliage done in modern games?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

All modern games seem to have foliage that is a texture with transparency, except that you can't see the pixels, and the edge between the transparent stuff and the leaves are really smooth. How is that done?

Share this post


Link to post
Share on other sites
Advertisement
High resolution texture + proper pre-multiplied alpha + texture filtering + anti aliasing = smooth outline.

Share this post


Link to post
Share on other sites
Even with high-res textures and filtering, you still get a (rounded) staircase pattern if you zoom in close enough.

One way to get really smooth edges is to store a distance-field in the alpha channel instead of an alpha-mask. This gets high-res looking results with only low res textures, plus it works on old hardware (like the Wii ;P).

Another technique to look into is alpha to coverage which lets alpha masks cooperate with MSAA.

Share this post


Link to post
Share on other sites
Quote:
Original post by Hodgman
Even with high-res textures and filtering, you still get a (rounded) staircase pattern if you zoom in close enough.
interpolating the alphachannel and applying alpha-test is how distancefields work.

Share this post


Link to post
Share on other sites
Quote:
Original post by Krypt0n
Quote:
Original post by Hodgman
Even with high-res textures and filtering, you still get a (rounded) staircase pattern if you zoom in close enough.
interpolating the alphachannel and applying alpha-test is how distancefields work.
The alpha-channel doesn't contain a simple mask though, each pixel contains the shortest distance to a pixel of the opposite type (type being "inside" or "outside" the mask). Inside pixels store positive distances, outside pixels store negative distances. All distances are biased by 127 to fit them in a unsigned byte, hence 50% alpha == 0 distance to the nearest edge.
Because a distance-field is a very smooth gradient, it interpolates much better than a traditional alpha mask, which means you don't get (rounded) staircase patterns - if you zoom in really close it actually looks like it's made out of polygons (in the pic below, look at the top of the 2 or 3).
e.g. in this picture the actual texture for each character is about 36 pixels, but the texture is stretched about 10x bigger than that (click for full size).
The distance-field data also makes the bevel, outline and drop-shadow effects ridiculously efficient to implement in a pixel shader ;)

Share this post


Link to post
Share on other sites
Quote:
Original post by Hodgman
Quote:
Original post by Krypt0n
Quote:
Original post by Hodgman
Even with high-res textures and filtering, you still get a (rounded) staircase pattern if you zoom in close enough.
interpolating the alphachannel and applying alpha-test is how distancefields work.
The alpha-channel doesn't contain a simple mask though, each pixel contains the shortest distance to a pixel of the opposite type (type being "inside" or "outside" the mask).
for alpha-blend-textures it means above and below the treshold.

Quote:

Because a distance-field is a very smooth gradient, it interpolates much better than a traditional alpha mask, which means you don't get (rounded) staircase patterns

usually for alphablended geometry you already have smooth alpha values, you can easily switch to alpha test (if the diffuse is created properly) and get away with a nice smooth shape.

Quote:
- if you zoom in really close it actually looks like it's made out of polygons (in the pic below, look at the top of the 2 or 3).
e.g. in this picture the actual texture for each character is about 36 pixels, but the texture is stretched about 10x bigger than that (click for full size).
The distance-field data also makes the bevel, outline and drop-shadow effects ridiculously efficient to implement in a pixel shader ;)

efficiency seems to be relative, cause a game like FarCry(1) had similar smooth tree-sillouettes and did not use any shader instruction to accomplish that, just by passing the alpha to the alpha-test-stage.

Share this post


Link to post
Share on other sites
Quote:
Original post by Krypt0n
efficiency seems to be relative, cause a game like FarCry(1) had similar smooth tree-sillouettes and did not use any shader instruction to accomplish that, just by passing the alpha to the alpha-test-stage.

I suggest you read the distance field paper linked earlier. Distance fields can be rendered with just an alpha test and produce the same results, the pixel shader is just to add the gradients/outline/shadow/etc.

Quote:
Original post by Krypt0n
usually for alphablended geometry you already have smooth alpha values, you can easily switch to alpha test (if the diffuse is created properly) and get away with a nice smooth shape.

No, a regular alpha channel (done as a mask for blending) is not the same as a distance field. It defines a (possibly antialiased) boundary, not a continuous field of values. As such, when alpha test is applied you'll get stair-stepping with a regular alpha mask, but a distance field ends up much smoother.

I wouldn't be surprised if FarCry is using distance fields for it's foliage.

Share this post


Link to post
Share on other sites
Quote:
Original post by Krypt0n
usually for alphablended geometry you already have smooth alpha values, you can easily switch to alpha test (if the diffuse is created properly) and get away with a nice smooth shape.
Yes, this is not a distance field though. It doesn't produce the same results. Same code, different data.
Quote:
efficiency seems to be relative, cause a game like FarCry(1) had similar smooth tree-sillouettes and did not use any shader instruction to accomplish that, just by passing the alpha to the alpha-test-stage.
Far cry also didn't perform outlined/shadowed/bevelled-font rendering on it's foliage! That was just an aside on other things that distance-field data is useful for (besides foliage). I mentioned to begin with that it works on old hardware (by simply performing an alpha-test on the data)! I'm confused as to what you're saying...

Share this post


Link to post
Share on other sites
Quote:
Original post by Hodgman
Quote:
Original post by Krypt0n
usually for alphablended geometry you already have smooth alpha values, you can easily switch to alpha test (if the diffuse is created properly) and get away with a nice smooth shape.
Yes, this is not a distance field though. It doesn't produce the same results. Same code, different data.
Quote:
efficiency seems to be relative, cause a game like FarCry(1) had similar smooth tree-sillouettes and did not use any shader instruction to accomplish that, just by passing the alpha to the alpha-test-stage.
Far cry also didn't perform outlined/shadowed/bevelled-font rendering on it's foliage! That was just an aside on other things that distance-field data is useful for (besides foliage). I mentioned to begin with that it works on old hardware (by simply performing an alpha-test on the data)! I'm confused as to what you're saying...
I'm just saying how it's done. that was the question from peon1234.
The data is created by artist who controll themself how it should look like, the result is the same and created without any distance-field paper in mind, since the first days of alpha test
(tho, you have better quality now than we got back in the days where trees had 64x32 pixel, just because of resolution).


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!