Grass on my Terrain

Started by
12 comments, last by k00k 18 years, 7 months ago
Guys how do I go about putting grass as i guess an alphamap on my terrain so that i can cull it as you move around the terrain it would appear on the terrain. anyone have any tutorials on how to go about getting this setup ect .. thanks
Advertisement
Nvidia's developer site has a demo that shows how to do this called Nature Scene. It can be found here: http://developer.nvidia.com. However, you should know that this demo uses GL but that shouldn't be a problem.


-SirKnight
Hi,

One common way (and the way that was suggested to me) is to use a coverage map.

This is how I am implementing my own vegetation system ....

Say you have a terrain that is 257x257 verts (256x256 tiles), you create a bitmap that is 256x256 so each tile in your terrain has a corresponding pixel in the bitmap.
Then, depending on how much grass you want for a specific tile, you assign that greyscale to the bitmap. I perform a lookup on my terrain splatting blendmap to see if the texture for that tile will have some degree of grass and assign the 0-255 greyscale accordingly.

At it simplest you could have a maximum of 255 clumps of grass on each tile (but of course you can scale the 0-255 range as you want). So then you need to generate a position for each of the 0-255 clumps of grass you want ...rand() should suffice to give you a decent enough spread. I also use rand() for a scale and rotation amount.

Ok so at this point I have an array of 65536 grass patches and each grass patch can have up to 255 clumps of grass. Using my quadtree and some further distance squared calculations I can determine if I want to render one of the grass patches, and I even perform a radix sort for back to front sorting (for fillrate purposes). Then just render away.

My implementation is still very much a work in progress and I will need to speed it up a great deal more ( it is still very hard on fillrate and it really eats memory :D ). If anyone has any suggestions on how to better my own implementation I would love to hear them :)

For reference here are a couple of decent threads on gamedev that I found useful ... here and here

Regards,
ViLiO
Richard 'ViLiO' Thomasv.net | Twitter | YouTube
I like that idea ViLiO. Are you frustrum culling and sorting back to front? That might help speed things up with the fillrate.
Chris ByersMicrosoft DirectX MVP - 2005
Hi,

Yea, the grass system is built into the terrain system and so I can reuse my quadtree to cull away possible grass patches when I am deciding which nodes to render (frustum and occulusion culling). Then I also do a distance squared test on the grass patches as I wouldn't want to be rendering all the grass on all the visible quadtree nodes.

For sorting though I sort front to back. This is because I only use alpha test and not alpha blend. This has helped somewhat with the fillrate, but it still needs work :D

I'll need to study far cry some more :P
Richard 'ViLiO' Thomasv.net | Twitter | YouTube
Oops. I meant front to back in the original post. Sorry! Maybe you could reduce the texture quality as well as make larger quads the further you are from the camera. i.e. instead of 1 quad with 4 blades of grass, 1 quad that represents what 4 used to 30 units from the camera, with reduced quality texture. Or something like that anyway.

EDIT: Nevermind, that would get highly complex now that I think about it! I didn't sleep well last night...
Chris ByersMicrosoft DirectX MVP - 2005
If you have a lot of time on your hands and some good hardware you could always try my way!
Orin Tresnjak | Graphics ProgrammerBethesda Game StudiosStandard Disclaimer: My posts represent my opinions and not those of Bethesda/Zenimax, etc.
Quote:I didn't sleep well last night...

Me neither, there was a spider in my room that hid under a bookcase before I could introduce it to the sole of my shoe and I couldn't get to sleep until I had let it meet its maker :D

@lancekt ...I had previsouly read that topic and thought it looked great, however my old geforce fx5900 can't do texture lookups in the vertex shader and I am aiming my current project at geforce 3 :)

Apologies for in part hijacking this thread :P
Richard 'ViLiO' Thomasv.net | Twitter | YouTube
Quote:Original post by ViLiO
Hi,

One common way (and the way that was suggested to me) is to use a coverage map.

This is how I am implementing my own vegetation system ....

Say you have a terrain that is 257x257 verts (256x256 tiles), you create a bitmap that is 256x256 so each tile in your terrain has a corresponding pixel in the bitmap.
Then, depending on how much grass you want for a specific tile, you assign that greyscale to the bitmap. I perform a lookup on my terrain splatting blendmap to see if the texture for that tile will have some degree of grass and assign the 0-255 greyscale accordingly.

At it simplest you could have a maximum of 255 clumps of grass on each tile (but of course you can scale the 0-255 range as you want). So then you need to generate a position for each of the 0-255 clumps of grass you want ...rand() should suffice to give you a decent enough spread. I also use rand() for a scale and rotation amount.

Ok so at this point I have an array of 65536 grass patches and each grass patch can have up to 255 clumps of grass. Using my quadtree and some further distance squared calculations I can determine if I want to render one of the grass patches, and I even perform a radix sort for back to front sorting (for fillrate purposes). Then just render away.

My implementation is still very much a work in progress and I will need to speed it up a great deal more ( it is still very hard on fillrate and it really eats memory :D ). If anyone has any suggestions on how to better my own implementation I would love to hear them :)

For reference here are a couple of decent threads on gamedev that I found useful ... here and here

Regards,
ViLiO



Thanks Vilio, Im working on doing this technique now, I have my terrain setup and im reading another bitmap file into my engine called foliage do I just use the Heights from the terrain ... actually do you have some soure code to look at here that could possibly help me out because im really not sure what methods i even use to render the grass at the same heights of the terrain ect .. thanks
I reccomend buying GPU gems 2. There is a good section on virtual botany on the first chapter (which is about grass). It looks really convincing even though the textured grass quads are billboarded.

This topic is closed to new replies.

Advertisement