# ? Speed tree leaf wind

This topic is 4443 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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....

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
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. Youll use all constant registers for this, but speed improvement is definitely worth it.

EDIT: Hopefully you arent 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.

##### Share on other sites
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?

##### Share on other sites
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.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 37
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
631414
• Total Posts
2999947
×