Sign in to follow this  
Living

A problem about rendering many grasses

Recommended Posts

Hello everyone! There is a problem in our game about rendering grasses. Our game has a scene with many grasses. All the vertexes of grasses used about 300MB memory. It's too large. So we can't load them at the time loading map. Now we divide them by some rectangles on terrain, each rectangle of vertexes use a mesh. When the rectangle is in the sight, all the vertexes in the rectangle will be generated. The problem is that, it takes too much time to render grasses when all vertexes are dynamic, or it causes CPU waiting in the lockVertex() function when all vertexes are static. Does anyone have suggestions? Thanks.

Share this post


Link to post
Share on other sites
Use hardware instancing and manage level of detail yourself.

Or at least double buffer your locks. Failing that, then I guess you need to rethink the amount of grass you have.

Here's my stuff working at ~100 fps without any code optimisations at all yet. This is on DirectX 9.

Grass

Share this post


Link to post
Share on other sites
Hardware instancing is your friend. For the positions just use some sort of repeating grid offset and only render the grasses within x distance of the camera.

Share this post


Link to post
Share on other sites
A typical patch of grass can easily have hundreds of blades. Each blade is similar to the other, with slight variations in color, position, and orientation. Rendering a large number of small objects using your way is not optimal.

There are two solutions which will be faster than your method.

1. using Texture Mapping.
1) static grass: easiest. Map your grass textures, that is it.
2) dynamic grass: you need a series of grass textures(like a movie
frames), use a timer and map them one by one in a fixed/varied time interval.

2. using Geometry Instancing
Geometry Instancing refers to the practice of rendering multiple copies of the same mesh in a scene at once. This technique is primarily used for objects such as trees, grass, or buildings which can be represented as repeated geometry without appearing unduly repetitive, but may also be used for characters.

Starting in Direct3D version 9, Microsoft included support for geometry instancing. Here are 2 good articles for instancing from MSDN and INTEL

Instancing10 Sample
http://msdn.microsoft.com/en-us/library/ee416415(v=VS.85).aspx

Rendering grass with Instancing in DirectX 10
http://software.intel.com/en-us/articles/rendering-grass-with-instancing-in-directx-10/

Good luck.

[Edited by - standby01 on May 5, 2010 6:02:55 PM]

Share this post


Link to post
Share on other sites
I haven't actually gotten around to rendering grass yet but if I was going to I would like to try doing something similar to this http://www.kevinboulanger.net/grass.html with hardware instancing for the closeup 3D grass.

Share this post


Link to post
Share on other sites
Quote:
Original post by Burnt_Fyr
Rubicon, that looks great... though the sharp drop off from grass to no grass looks a bit ugly. Do you multitexture? I'd love to see your source sometime.

Thanks. :) Not sure where you see a sharp drop off though, it can be faded out as smoothly as you like. There is a path on the horizon if that's what you see.

That paper by mr Boulanger was what got me started on this tbh, though he does skip a lot of the nasty details in there, such as how to get your mipmapping to actually work!

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