Windy Trees

Downloads

WindyTrees.rar [7.4Mb] – VB.Net 2005 project with shader and sample media

Description

I was asked by Hawthorne to make a shader for tree meshes that would make them swing in the wind. I liked the idea so I tried it out…

The environment is a basic landscape with skybox, and a parametrizable amount of trees sitting on it. Most screenshots have about 250 trees and there is no optimization for non-viewed trees. The method for making them swing is very simple, yet looks fairly good; more details below.

Features

  • The swaying uses a sinus function based on the elapsed time (the TIME semantic). The resulting offset is added to the vertices’ world-space position
  • The swaying offset is modulated by a squared “height factor”, so that the top of the tree sways much more than the more solid base trunk
  • The wind direction and speed can be modified with effect parameters
  • There are also “random offsets” for speed and direction that can be set on a per-tree basis so that the forest doesn’t sway in a very uniform way. The samples shows how this is implemented.
  • Uses per-pixel diffuse lighting for one directional and one point light, and uses the POINTLIGHT_NUM semantic to make sure the mesh isn’t lit by a disabled point light
  • Supports any type of fog using the newly added semantics
  • It’s Shader Model 2.0 minimum, like most of my shaders
  • Alpha blending of the tree texture (for the leaves) is supported

Known Problems/Future Work

  • The TIME semantic is a tad unstable, moreso at low FPS; so the trees sometimes “jump” which makes it look very unnatural
  • There is no wind accumulation, the trees will always swing at the same rate and velocity. The reason for that is that I wanted to use velocity and acceleration, calculate all this in the Tree class and send them at the shader every loop, but a SetEffectParam for 200 trees every loop is very slow… Perhaps if a only a chosen number of trees would be feeded params (based on their distance to the camera), this solution would be acceptable

Licensing Restrictions

This sample uses media that Hawthorne provided me : the tree texture and model. These should NOT be used in a commercial project. Everything else is public domain.

Videos

AnimatedTrees.avi [11Mb] – First video of it in action
AnimatedTrees2.avi [12Mb] – Second video, from a newer build

Screenshots


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.