Grass and what to do

Started by
22 comments, last by CC Ricers 11 years, 2 months ago

Let me begin by saying, i know that grass is not a majorly important thing since most of the players will simply pass by it without caring too much, but the concept is to make something that is appealing to the eye and non-resource intensive. Before you go saying "that is impossible" i would argue that by using art and optical illusions you can very much do this. The question is how does it translate into code or what are the best practices.

Many games today render grass as a flat plane with a simplified texture over it. This process is not bad but one must ask the question of how to add depth. More planes? Assuming you do figure out a proper method what type of lighting should be applied, how do shadows work?

I have seem some games that add an ambient shadow to the base, where as others do not care about shadows at all and simply ensure the grass matches the tone of the mesh it is attached with.

My overall question is, how would you, fellow coders, do your grass?

Advertisement

1) Many polygons

or

2) Crazy idea where you render the grass on a texture, apply a fancy directional blur-line-drawer shader to pull grass lines from the flat ground pixels and then render that with depth. Or something. :D

o3o

When I started developing the terrain system of my engine I thought long about that and read some articles. In most of todays games or let me say yesterdays games because I dont own many that where released in the past 1-2 years I hate the grass. Often its looking very bad from above or its always rotating to face the camera. I ended up implenting some techniques.

Only one had sufficient quality but it would not win a ressource-saver-price. The basic idea was to render each blade of grass, divide into into slices to get the possibility to animate it and fill it with a gradient color in the shader. It was possible to scale the quality with the number of slices but since it required a lot of them to look good I decided to put the geometry into the object and not into the grass. There was a name for it but I cannot remember it...

Next technique was only a experiment i did out of interest. It was still rendering each blade of grass but this time without the slices. So I got 4 verts for each blade and did the animation in the pixelshader. Basically the gradient color shifted from left to right and back but it looked kinda disturbing and I wanted a technique capable of rendering different types of grass. So I'm going with the basic method of rendering 4 verts with a texture. I can put many textures in one and select the relevant one randomly when creating the vertexbuffer. The alpha channel of the texture contains a noise to control fading in the distance...Thats it and best part is it dont look like sheets of paper from above. There is still some optimization potential but I'm happy with it for now.

I also read about using Parallax Occlusion Mapping to get a grass effect but that would not be very performant either.

I would probably start by creating many textured quads, giving them a sway (via shear matrix), and then batching all of them on the CPU. Then send them all to the GPU in a single (or minimal) render calls.

The problem here will probably be depth sorting (since the grass textures will have alpha): You could either turn off depth writes and just let the pixels clash together, or spend the time sorting them if you have enough CPU resources. I'm sure there are papers on the subject if you want to get more advanced.

If you want the grass to cast shadows, you can still use standard shadow mapping. During the shadow pass, draw the grass with alpha-testing enabled.

http://illogictree.com/upload/site/LeeRealtimeGrassThesis.pdf

This might help you. I think there is a youtube vid showing it off also.

that article is great, assuming you are a math genius and want a very complex system. Not sure we need that since our game is not that complex. Could be adapted at some point though. Thanks so far guys.

What I did a long time ago was create a couple of tiling grass texture patches as side views (along the lines of this) and simply skew the top end to emulate really rudimentary wind. It's cheap, pretty angle sensitive and only works with well tuned skew parameters, but definitely passes as a 90s style game grass.

Umh, the illogictree link is dead for me. I'll try again later.

In the meanwhile, consider Towards Photorealism in Virtual Botany.

It's my gold standard.

In the meanwhile my current target would be something like the XRay engine: stupid particles spawned on special planes.

In the past I also tried experimenting a bit with POM-based techniques: the performance was terrible and I'm inclined to think polygon-based techniques might actually be the best option for another couple of years.

Previously "Krohm"

I think the best solution for our engine, and for optimization is the flat plane option with a bit of curve. My question now is... how do we make the shadowing of it like you see in games such as Saints Row 3 and Firefall? It seems like its just a small texture of black that is applied below the upper mesh parts or it is some form of basic shadowing... not sure. I love all of the suggestions so far. Have been looking at them all and reading up. So much wealth of information

I worked on a project with digital (I hope he doesn't mind me giving away the technique) where he came up with a neat trick that I like to call "texture-space parallax".

Say you've got a 3D model of a bunch of grass blades (please excuse my mspaint art):

Wr1M3.png

If you tiled it in the world and rendered it, the camera rays would look something like below, but your triangle-count would be huge:

nF50c.png

So instead, in this technique you just pick the direction that the camera is looking in (or some other arbitrary choice of direction that looks good), and render a single "tile" of grass to a texture, using an orthographic projection in that direction.

e.g. when looking down/right, or down/left, your ortho renderings would look like this (colours on the line at the top are the resulting 2d "grass" texture from the 3d model):

4LPXn.png nnxQo.png

You then just use that 2D texture as usual on your ground, but as the camera rotates, the parallax effect of the grass blades changes.

This is incorrect, because as you can see, the rays in our ortho view are all parallel, where in the reference image above, the rays all diverge and cause different parallax in the foreground than in the background... but it's ridiculously cheap and worked well enough for us at the time.

When rendering the ortho view, we also rendered height data into the alpha channel, so that we had the option of doing extra effects later when using the texture, like parallax mapping, or outputting modified depth values so that the grass would seem to rise out of the ground and clip with player's feet, or modified lighting based on height, etc...

You've also got to take a lot of care when creating your 3D grass model so that the resulting 2D texture tiles correctly -- e.g. if a bit of grass is near the edge of the "tile", then you've got to duplicate it and move it over, just outside the opposite edge.

This isn't the best example, but here's a flat plane that's been textured with this technique -- http://i.imgur.com/6WEHC.png -- obviously only useful for quite short grass, not fields of wheat, etc wink.png

This topic is closed to new replies.

Advertisement