? Speed tree leaf wind

Started by
4 comments, last by Namethatnobodyelsetook 18 years ago
I have implemented a system very similar to Speed Tree in my D3D engine. I am using batched D3DXsprites for the leaves, and they are rendered by a vertex/pixel shader. I have got a cheap wind effect by simply moving the x position relative the to the base of the tree in the vertex shader.. this looks ok but is not the best effect. In Speedtree they move their sprites independently.. anyone have an algorithm for doing this? The sprites are rendered with billboarding, so all the additional transforms need to be in the vetesx shader i would think-- unless i shouldnt use the automatic billboarding....
Advertisement
You can use vertex shader math to compute movement as a function of time and vertex position. sin() and cos() are your friends here.

As for billboarding, I think that normal geometry could look better. Every leaf can be separate quad textured with proper texture. Some leaves will look flat at certain angles, but real leaves are flat, too.

EDIT: Fixed a typo.
that'll be like 2000polys per tree(don't forget the trunk) which is waaay to much if you want more than 10 trees in your scene. I've never seen a game which uses single quads for every single leaf.

regards,
m4gnus
"There are 10 types of people in the world... those who understand binary and those who don't."
Divide your leaves into chunks and write a Vertex Shader that can handle whole batch of leaves (say 25 or 50 quads) in one call. You`ll use all constant registers for this, but speed improvement is definitely worth it.

EDIT: Hopefully you aren`t computing sin/cos inside your current vertex shader per each leaf, right ? Either go for sincos table or compute it just once for whole batch.

VladR My 3rd person action RPG on GreenLight: http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

Each tree has several hundred sprites that represent a cluster of leaves. This is exactly like Speedtree, and i chose this method for several reasons. Using a quad for each single leaf is not an option.

In any case I'm not asking for ideas on how to make trees, but how specifically rotate an individual sprite around its own axis in a vertex shader. I dont see why i cant calculate sin/cos in the shader, as this seems reasonably fast..

Since the sprites are batched, i dont see a way to use a constant to this, unless i use smaller batches.. is this what you are suggesting Vlad?
You can put a number into the vertices of each "leaf bunch" quad, and use this to index into constants that define translation, rotation, a full matrix transform, or whatever you want.

It's possible to get decent results without that much effort though. For Raze's Hell we simply stored two amounts per vertex, and had two independant wind vector directions.

The two vectors were modulated by time and world position of the object, ensuring each object swayed independantly from the ones around it.

The two vertex values were a wind amount, controlling how much things should sway, and blend amount. The second value controlled a lerp between the two wind vectors. Now each leaf swayed by a correct amount, in a direction between our two extreme wind vectors, with each object swaying out of sync with each other.

The two wind vectors were modulated by time and position differently from each other, so not everything swayed to 100% at once, as the swaying of the two vectors were out of sync.

This topic is closed to new replies.

Advertisement