Advertisement Jump to content
Sign in to follow this  

Real Time Grass

This topic is 3851 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

I have a terrain of size 2.4 square miles...and i want to put vegetation on it like wavering grasses...but how should i manage data is actually the problem... Grasses have to be put over the surface of variable height......I cant store the data statically because terrain is big and it will take more memory.... Now in alternate choice, height of the terrain is stored in bmp map so that i can draw grasses over the surface dynamically in real time calculation...i want to put 100 square meter area filled with grasses that repetitively tiles over 2.4 mile square area but how do i do that is the real question when the player walks ahead the grass should not looks like moving along with the player...i mean that grass changing its height but from their appearance (size, rotation angle) remains same...... one choice is to put equal scaled single type grass with no rotation over all space and only change the height...But this is not what i want actually...i want to put grasses of variable size and rotation over the terrain... Any idea on it

Share this post

Link to post
Share on other sites
instancing is not really gonna help, the bottleneck with grass is the huge amount of fill required


each grass pixel here has prolly been overdraw 5+times (unless plain old alphatest + sort)

to the OP, what u can do is have say a 8x8 areas around the camera (fade the grass out in the distance), each area contains ~250 quads of billboarded grass
each time the camera moves into a new quarant, create the grass for that based on the terrains height or a coveragemap etc

Share this post

Link to post
Share on other sites
In addition to ZedZ's suggestion (which works fine), you could have a couple of pre-defined sets of foliage, in case you don't want to generate random vegetation when a new quarant gets visible.

For example, make an array with quarant foliage data. This is a square filled with quads(or other shapes) with grass/other vegetation textures, eventually nicely sorted on texture. You could order the sets in the array on the vegetation thichkness, and/or category. For example:

struct TFoliageSprite
vector3 size;
vector3 position
texture tex
struct Quarant_Vegetation_DataSet
TFoliageSprite quads[0..?];
int quadCount;

const CATEGORY_FreshGreen = 0; // Relative short, green grass/flowers
const CATEGORY_WildGreen = 1; // Untamed wild high/grass
const CATEGORY_Rotten = 2; //
const CATEGORY_Jungle = 3; // Jungle vegetation
const CATEGORY_Forest = 4; // Forest vegetation, mushroom, leaves, etc.
const CATEGORY_Desert = 5; // ...
const CATEGORY_Africa = 6; // Savanne

const THICKNESS_LOW = 0; // Almost nothing growing there <10 quads
const THICKNESS_MEDIUM = 1; // Normal growth ~50 quada
const THICKNESS_HIGH = 2; // Alot of vegetation ~100 quads
const THICKNESS_EXTREME = 3; // Very dense ~150 quads

const RANDOM_COUNT = 5; // 5 random generated sets per category/thickness


In this example, you generate 7x4x5 = 140 sets of vegetation data. For example, if I generate a set for category "CATEGORY_WildGreen", "THICKNESS_MEDIUM", I generate a certain number of quads with textures from long grass, wild flowers, bushes, etc. I generate 5 sets per category in this case, to prevent you won't see the same stuff all over the place.

Your quarants on your terrain will have a pre-defined category, thickness and random number. You can assign these numbers via your level/terrain editor, or do it totally random. When you move around now, you don't have to generate new data all the time, and the vegetation won't change if you return to a part of the world you visited before.

As for the rendering part, first you calculate which quarants are visible (a circle around the camera). When rendering quarant x, use its category numbers to render the right vegetation data set. This set already has the right data, eventually sorted on texture, etc. You could even choose to make a vertex buffer object from its contents. However, you need to transform the quads:

quad.renderXZ += quad.originalXZ + quarant.offsetXZ;
quad.renderY += quad.originalY + heightMap[ quad.renderXZ ];

You can also do this in the (vertex) shader, eventually with the help of a heightmap (although you can't read textures in the vertex shader on your hardware).

Apply a fade in/out for the quads in the outer circles. You don't want vegetation sprites become suddenly (in)visible. Calcualte the distance between the quad and the camera, and adjust the overall alpha with that.


Share this post

Link to post
Share on other sites
An easy and efficient way to place grass on terrain is to use large chunks of grass polygons and then set the height in the vertex shader by using a vertex texture that matches your terrain heightmap.

This way you dont have to worry about any data managing...just move your grass chunks when they become too far away form the camera. Just do frustum culling.

Share this post

Link to post
Share on other sites
I really like the effect produced by this paper: It's all shader driven so it shouldn't affect your existing framerates too much. My only concern with doing something like that is making sure the grass around every object (specifically animated characters) looks appropriate (e.g. make sure it overlaps the feet of people so they don't appear to be floating over the grass).

Share this post

Link to post
Share on other sites
Nick Gravelyn...u r a man...Thnx all BUDDY

I am thinking of to use double queue with two dimensional the player moves ahead the new grass will be added and old grass will be deleted...dont know whether it will really works or not yet...let me try it....

thank u guys for ur concern...i be right back with results....meanwhile if any other suggestion or comments on using dqueue ...u most welcome....:)

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!