Friday, July 6, 2012

Trees and God Rays

Yep, another one of those posts where the title summarizes its content.
So, as far as eye-candy goes, Ruined should more than fill ones appetite - at least for an indie game.

First up it's:
Dynamic Trees - the kind with leaves.
  • You heard right, trees will appear to blow and sway in the wind. 
  • I'm also using hardware instancing for drawing trees/bushes/grass, so I should be able to have a considerable amount of vegetation on the screen at once. 
  • Trees are pretty awesome...

Followed by:
God Rays a.k.a. Light Shafts
  • God rays create the effect of sun-rays shining around sun-occluding objects.
  • In other words, it's nothing but eye candy, but delicious eye candy at that!

A word on implementation
God-rays are actually really easy to program.
  1. Draw the sky, masked by the environment into a TINY render-target (you can use your depth buffer for this)
  2. Radially blur this image into another TINY render-target, using the sun-screen-space position
  3. Additively blend the blurred image with your final output.
Here are some links where you can find out more on programming god-rays
  1. Your model needs to have certain values painted to each of it's vertices
  2. In the vertex shader you transform each vertices position taking into account it's vertex color
  3. Blender doesn't support painting a single channel of a vertex color at a time (ie Red, Green, or Blue), so a processor must be written to combine three separate vertex color channels into one. So you have to make a channel for Reds, a channel for Greens, and a channel for Blues, then you combine all three of these channels into one.
  4. I then wrote my own simple model format to allow me to hardware instance with ease
Again, here are some links that have some more information on the topic

Note: The tree model used in this post is provided as free-ware from the Loopix-Project in its original form.

No comments:

Post a Comment