Archived

This topic is now archived and is closed to further replies.

Waving trees and grass

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

Wondering what the best way to create animated vegetation in a game. I wan''t trees that wave a small amount and maybe some grass lumps here and there that also wave, not from interaction of the character just waving in the wind. Should i animate my models in an external program like maya and then load them as animation or is Vertex Blending an better option? which one will be most effective?

Share this post


Link to post
Share on other sites
It depends on the animation capabilities and costs for your engine.

Pre-canned animations in something like Maya would probably "look" the best (assuming they''re animated by a skilled animator), and could match the style of your game better. You could get the most complex animations for the lowest amount of work with them.

HOWEVER, a pre-canned animation wouldn''t be interactive or able to change depending on environmental things - e.g. if you''ve got a strong swirling wind affecting your particle systems (smoke from the chimney on the cottage roof swirling around etc) and the grass is running through a "calm summer''s day" animation it might look out of place, particularly if the grass was moving against the wind.

"animation in Maya" versus "vertex blending" isn''t comparing like with like. WHAT TYPE OF ANIMATION IN MAYA? For example if you were doing bone style animation in Maya, then the playback of that animation in your engine would also be "vertex blending". Which would be the same cost, same implementation work etc. The only difference would be the animation controller.

If your Maya animation used morph targets or similar, then unless you could implement the playback inside a vertex shader/program, then that''d imply accessing and modifying individual vertices with the CPU. Whether that''s ok depends entirely on YOUR engine and how much spare CPU resource YOUR app has.

Implementing a simple "wave" along the Y axis of an object inside a vertex shader would be simple enough - however, the need for randomness and a decent enough controller/simulation to make it not look totally artificial.

Obviously the more complex the controller, the better things will look, but the more expensive it''s likely to be - there''s lots of ways you can cheat, fake and hack to get decent results. But of course that does also take development time (more tradeoffs - which are best for you depends on your exact situation).

One idea might be to combine the two. Have a set of pre-canned animations in Maya, then:
a) blend different animation loops together at runtime
b) alter them at runtime (e.g. multiply the strength of them)


BTW: the plants section at www.vterrain.org might have some stuff to interest you too.

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Thanks for the detailed reply, good points there.
Could you please elaborate this

Implementing a simple "wave" along the Y axis of an object inside a vertex shader would be simple enough - however, the need for randomness and a decent enough controller/simulation to make it not look totally artificial.

That sounds really interesting and im not that picky about it looking unrealistic since the world im building is pretty cartoonish

Share this post


Link to post
Share on other sites
Consider the following mesh representing a plant, blade of grass etc. As you can see it has 8 vertices, it''s being viewed from the front:


1--2
| /|
|/ |
3--4
| /|
|/ |
5--6
| /|
|/ |
7--8



Now let''s say that all the grass starts at Y=0 (i.e. the ground) and Y increases as you move up the blade.


+--+
| |
| |
+ +
| |
| |
+ +
| |
| |
+--+ <--- Y=0



The vertex shader will run for each of the 8 vertices, so we can implement a function in shader that applies an offset to each vertex. For example the simplest possible thing to do in the shader would be:

x'' = x + y
y'' = y
z'' = z


So the further up the blade of grass you get (as y increases), the further that blade tilts in the x direction (i.e. the offset added to x increases):


+--+
/ /
/ /
+ +
/ /
/ /
+ +
/ /
/ /
+--+



Now say we add an "amount" parameter to the above function:

x'' = x + (y*amount)
y'' = y
z'' = z

If "amount" is passed in as a shader constant, we can vary it over time through the range -1.0 and 1.0 to get the blade to sway from left to right


That function is just for illustration purposes, the grass sway produced by it would look like cardboard rather than grass .

For actual grass you''d use a higher order function that produced a much more curved result, and you''d probably add in more than just the "amount" as a control variable.



--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites