Sign in to follow this  
DerAndiY

Grass

Recommended Posts

DerAndiY    128
I'd like to render some sort of grass/plants on the ground... Any suggestions for a (reasonably performant) way of doing it? Cheers Andy

Share this post


Link to post
Share on other sites
kburkhart84    3187
The easiest(and ugliest) is a quick texture-mapped quad. This works great if too much detail isn't too important, especially if you have a good texture. Any other way I can think of seems too slow for real-time graphics(games). If you want it beautiful, but slow, just render it with little triangles, just like everthing else.

Share this post


Link to post
Share on other sites
unreason    139
The book GPU gems I think has something on using pixel shaders to simulate fields of grass. I just looked at it in the store, but it looks like what they did was combine 3 billboards with grass on them like this:


x x
x x
xxxxxxxxx
x x
x x

This way some of the grass billboards are always facing. They repeat these things lots of times. Of course, they used the power and speed of the pixel shaders to do lots of fancy stuff to these things, but that's the basic idea, I think.

Share this post


Link to post
Share on other sites
Pipo DeClown    804
Quote:
Original post by unreason
Oops, the post ruined my diagram. It should look like an X with a horizontal line running through the center.

Try [ code ][ /code ]. ;P

Share this post


Link to post
Share on other sites
vincoof    514
Actually the most popular algorithm is probably the "Shells And Fins" algorithm, which has been implemented for instance in the incredible life-like real-time fur demo (with source code) sumbitted to NeHe Productions last year. Despite the current lack of support of the site, there is still tons of very useful resource at NeHe Productions. :)

Share this post


Link to post
Share on other sites
DerAndiY    128
Ta to the community for all the useful advise!
Feel free to keep on posting. I'll post my decision on which model to use soonish.
Cheers

Share this post


Link to post
Share on other sites
Raduprv    997
IMHO, the best tradeoff between speed and nicelookingness is to create a cylinder mapped with a color keyed texture. Works great for grass and grassy like plants (such as some waterplants and weeds). It also looks good from any angle, except if looked at from the top.
Most of the demos I've seen have a big plane with a grass texture, and while it looks good if the camera is pointed at the right angle, when you move the camera, especially looking downwards, or just rotating in place, it will look VERY ugly.

Share this post


Link to post
Share on other sites
Xero-X2    184
Quote:
Original post by DerAndiY
Hi,
what is a color keyed texture? Sorry I'm new to this whole OpenGL thingy. :)


a Texture with an alpha channel set to 1 everywere except where your KEYCOLOR is present, there it is 0. so that one color is transparent, while everything else is Fully opaque

(Bright Purple is a common used color for this, sence you hardly ever would see such a color in a texture)

AlphaTesting is commonly used with Color Keyed Textures, senced there is no need to have partially blended colors.

Share this post


Link to post
Share on other sites
cowsarenotevil    3006
A method that works very well when you're relatively above the grass looking down is simply to have a series of quads with a masked texture of dots layered on top of eachother to give the illusion that you have complete lines. It's also pretty easy to get some motion. The main problems are that it's impossible to move blades of grass individually (only in "chunks") and that it's hard to get curved blades, along with the fact that if your perspective gets too sharp, you'll end up seeing between the quads and your grass will look flickery or simply as separate floating dots ;).

Share this post


Link to post
Share on other sites
FReY    424
Quote:

...that if your perspective gets too sharp, you'll end up seeing between the quads and your grass will look flickery or simply as separate floating dots


true, you've described the 'shells' part of the 'fins and shells' algorithm, but the 'fins' part solves that problem you mentioned :)

Share this post


Link to post
Share on other sites
vincoof    514
Quote:
Original post by cowsarenotevil
A method that works very well when you're relatively above the grass looking down is simply to have a series of quads with a masked texture of dots layered on top of eachother to give the illusion that you have complete lines.

That's part of the shells ans fins algorithm, as FreY mentioned.
Note that this effect only (ie without fins) has been used in many games like Star Fox Adventures (GameCube) and look pretty good granted that the camera has limited view angles. The mistake made in Star Fox Adventures is that the effect was not only applied on grass : it was also applied on the hero (note: the hero is a fox, thus fur rendering) but the polygons of the hero can be parallelto the viewing direction, and in that case the shells look crap without the fins.

Quote:
Original post by cowsarenotevil
It's also pretty easy to get some motion.

True.

Quote:
Original post by cowsarenotevil
The main problems are that it's impossible to move blades of grass individually (only in "chunks") and that it's hard to get curved blades,

With vertex programs thing become a tad easier, but it's true that there's still no complete freedom for the grass physics.

Quote:
Original post by cowsarenotevil
along with the fact that if your perspective gets too sharp, you'll end up seeing between the quads and your grass will look flickery or simply as separate floating dots ;).

A common way to avoid the minification (flicker) problem is to play with mipmaps, because in OpenGL you can define your own mipmap levels (and this is a perfect example on where it's useful NOT to use traditional mipmap computation).
As for magnification, there are other techniques, such as LOD bias which works more or less depending on your application.

Share this post


Link to post
Share on other sites
soconne    105
You could just do it the way battlefield and many many other games do it, including FarCry.

Create a texture that represents where grass is on your terrain, if a pixel has a value of 0, no grass, > 0 there is grass. Then during rendering, figure out where the player is in relation to the texture, then scan all pixels in the texturemap within a specified radius on the texture, and for each pixel you encounter with a value > 0, render a set of grass quads, or even a single grass quad.

This is by far the easiest method and actually looks pretty good. With this method it is very easy to have grass fade in and out with distance.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this