Page 1 of 1

Springy Grass revisited

Posted: Mon Jan 09, 2006 4:30 pm
by atsakir
I was looking for a good way to animate grass and I came upon this thread (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 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)

Posted: Mon Jan 09, 2006 4:37 pm
by tuan kuranes
Good to see it finally became useful.
Thanks for releasing the code.

Posted: Mon Jan 09, 2006 4:59 pm
by atsakir
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

Posted: Mon Jan 09, 2006 5:11 pm
by tuan kuranes
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.

Posted: Wed Jan 11, 2006 10:21 am
by atsakir
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