Springy Grass revisited

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.

Springy Grass revisited

Postby atsakir » Mon Jan 09, 2006 4:30 pm

I was looking for a good way to animate grass and I came upon this thread http://www.ogre3d.org/phpBB2/viewtopic.php?t=3742 (which is quite old - hence the new topic).
I downloaded the grassdemo.rar file and built the source code only to be dissappointed to see a 15-20 fps speed and no object to move around in the grass. Since this was unacceptable for my purposes, I messed around a bit with the code, added a ball which is movable with the arrow keys, changed the material (which was handled incorrectly in the code btw), randomized the width,height and initial bend of the blades a little... and this is a screenshot of the result:

Image

...as in 10x faster! I still haven't got the material to display 100% correcty but it's much better than before. This screenshot is for 5000 grass blades.
The demo starts animating the whole 5000 blades at the same time (as in wind e.g.) The avg frame rate at this point is around 80fps on my setup. (press 'f' and see what you get for yours) after a few seconds the demo goes into "optimised" mode and animates only the blades that are collided with the sphere, hence >160fps.

Here's the full modified source code and executable for anyone interested (built with OgreSDK 1.0.6)

http://server-5.iti.gr/filippid/GrassOptimized.rar
User avatar
atsakir
Kobold
 
Posts: 36
Kudos: 0
Joined: 03 Jan 2006

Postby tuan kuranes » Mon Jan 09, 2006 4:37 pm

Good to see it finally became useful.
Thanks for releasing the code.
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
 
Posts: 2653
Kudos: 4
Joined: 24 Sep 2003
Location: Haute Garonne, France

Postby atsakir » Mon Jan 09, 2006 4:59 pm

My next task is to map it on a terrain and constrain it inside convex areas (I'm actually thinking of using a grayscale image for that (a la heightmap, using a black colour threshold to determine where grass is generated and where not) and then use different LODs to further optimize the scene (e.g. only 1000 blades handled like that based on view frustum and farther away the rest of the grass will show as simple billboards). I also intend to change the blades from the "pyramids" they are right now to quad planes so that I can use proper grass textures better
User avatar
atsakir
Kobold
 
Posts: 36
Kudos: 0
Joined: 03 Jan 2006

Postby tuan kuranes » Mon Jan 09, 2006 5:11 pm

use different LODs to further optimize the scene

At lower lod I would consider switching to the "grass blades cross" trick like in the ogre grass demo.

"pyramids" they are right now to quad planes

And you can switch to indexed tri list instead of actual blades indexed tri strip, it's now faster on modern quads.
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
 
Posts: 2653
Kudos: 4
Joined: 24 Sep 2003
Location: Haute Garonne, France

Postby atsakir » Wed Jan 11, 2006 10:21 am

Update - the version I posted has a bug that makes the grass vertices move to completely wrong positions after a while when collided with the ball (incrementaly so as time goes by). I haven't figured out where in the code this happens but it definately has to do with the step() function in conjunction with my modified update() function, because if I don't use the optimised proxy collision method and animate all the blades in each frame this doesn't happen.

Anyway, for the purpose I want to use the grass I don't really require spring dynamics but rather the grass to stay bent after an object has passed through it (as in leaving tracks) so I've removed the offending code. However, if anyone is willing to look for a way to fix the bug without hurting the framerate it will be most welcome
User avatar
atsakir
Kobold
 
Posts: 36
Kudos: 0
Joined: 03 Jan 2006


Return to Using OGRE in practice

Who is online

Users browsing this forum: No registered users and 0 guests