Monday, April 23, 2012

The Faraway Forest

One recurring question about the trees and forests I am doing is how they will show in the distance, from how far you could see them. It is a real issue.

I chose a different approach for trees than most engines I know. In traditional engines, trees are done by instancing the same tree models many times over the landscape. Each tree instance is known by the scene management and rendering engine. If a tree is sufficiently distant it can be represented by a simpler instance. This works nicely even for distant forests, but it imposes a very homogeneous look for your trees. If you want very large trees with unique branches this becomes a problem. At some level of detail the unique tree needs to be replaced by an instance. The more unique the tree, the bigger the visual jump will be.

I wanted to take a different approach to instancing. I still use it, but for much smaller elements like grass, flowers, tree leaves and small branches. This means each tree has unique geometry. Trees are fairly complex objects, a distant forest could have thousands of them. How to overcome this?

Many years ago I was flying over the Amazon rain-forest. I could see a thick layer of tree canopies below and a thick layer of clouds above me. I was amused by how similar they were. I began wondering if a forest could be rendered as a volumetric object, more like clouds.


I also wondered if I could make tree canopies opaque. After all they are often so dense you cannot really see inside them. It would really cut the number of polygons. All the branches inside the canopy could be removed, only the larger branches supporting the canopy puffs would remain. Here is one example taken form a Voxel Studio mesh render preview:


When looking at this, keep in mind there is a missing layer of instancing that goes on the crown volumes. This is rendered pretty much like grass and flowers over the ground (which you also won't see in this picture). You will be able to see a lot of detail coming out of the tree crowns. The green blobs in the picture before are the base for this instancing. This basic geometry is from where leaves and small branches get their position and -very important- their illumination.

I liked the fact that tree identities would be lost in this gigantic cloud. The geometry of several trees could be merged and simplified together, there was no need to think of tree instances beyond the generation stage. Also it would be rather easy to perform light scattering in the canopy cloud. To me proper lighting was essential to convey the scale of the trees and how it feels to be under them.

This approach had some big issues too. It does not work very well unless trees have fairly thick crowns. You can have a lot of small crown puffs to represent sparse crowns, but this could hurt your polygon budgets.

Now comes the initial question: How does it look when trees are far away? This is where this approach can shine. Since there are no individual tree instances anymore, the volume can be simplified down to the levels we know will look fine on screen. Then the instancing of leaves and branches continues to provide detail on top of the simplified clouds.

The following images show how much the trees can be simplified. You need to remember that each consecutive level appears further away. When these meshes are rendered in their proper positions, you cannot really tell the coarse level is just a weird soup of polygons.

This is LOD 1, which is shown pretty close to the camera:


This is LOD 6, which shows a few hundred meters away from the camera:


And this is LOD 10, which appears at more than one kilometer away. As you can see, the forest has entirely blended with the terrain. This means the grown polygons are not rendered anymore, only the canopy layer remains visible:


Here you can see the same progression from a different point of view. The LOD levels are the same: 1, 6 and 10.


Hopefully I have answered that forest-in-the-distance question. This looks really nice when properly illuminated and adorned with instances. In the short future I will post about that.

19 comments:

  1. That actually looks really good. I'm a little curious about whether you intend to do anything about wind/movement. A completely stationary forest, particularly at a distance, might look kind of weird.

    ReplyDelete
    Replies
    1. Leaves and small branches are instanced, they can sway in the wind, even the distant ones. I won't be moving large branches, but I don't think they move that much in real life, unless there is a lot of wind.

      Delete
  2. When you said that the tree tops looked like the clouds, I thought maybe you were going to use Turbulence to represent the distant trees. Which I think could be really cool...

    ReplyDelete
  3. Well the crown puffs are made of perlin noise with some turbulence on it. Still the puffs need to be seeded by the actual tree branches. Pure turbulence would not look right when you get up close. If you kept it only on the distant LOD then transitions into closer LOD would become a problem.

    ReplyDelete
  4. This looks really neat. I enjoy your posts a lot, congratulations, and thanks for sharing.

    One question about the individual tree generation: is it merged with the procedural language you used in late posts for generating rooms, or are the two things independent?

    ReplyDelete
    Replies
    1. It is independent. I looked at grammars and L-Systems for tree creation but I chose a different method based on space colonization. You can find more about this here: http://procworld.blogspot.ca/search/label/Space%20Colonization

      Delete
  5. Amazing as usual.
    My concern however is that this approach might force you into a specific art-style - The bulbous tree fauna lends itself to a cartoony look but your terrain is so realistically detailed.
    I really dislike the current look of the trees, which is my personal opinion of course.

    ReplyDelete
    Replies
    1. I share the same feeling. I'm counting on the extra layer of leaves and small branches to produce a more realistic look. With this layer enabled, the crown bulbs can be smaller and most of the crown will come from the instanced geometry. But of course the proof is in the pudding, I still have to get there.

      Delete
    2. Ah I see. I think the look would also benefit from transparent textures.
      To be honest though I find it very difficult to see any issues with how Crysis makes use of its instanced foliage. Its forests look amazing and almost push through the uncanny valley into realism under the correct circumstances.
      I do understand the benefits of your approach of a single uniform mesh you can LoD scale at will, but I'm undecided if its the 'best' approach.
      I think, like you say, time will tell.

      Delete
    3. Right, instancing does great and it will only get better. I suits perfectly to forests where trees are not too wide and they look mostly the same, which happens a lot in real life. But some virtual worlds may want to go beyond this. Imagine a city that is made of huge interconnected trees. In that case the forest and the city are the same thing. Instanced trees won't give you that.

      Delete
  6. I like the idea, but something about the cloud-forest does not look right to me. It looks more like a wall of green without depth than a canopy. Also, other posters mention this -- but tree variety is a problem. What about mixed coniferous and deciduous forests? Throw in a couple of spruce or hemlock trees and things will look more realistic, except they tend to stick out in real canopies vice blend in. Finally, your fourth image looks really bad (my opinion) -- way too boxy -- but the similar image (the last one) looks OK. I'm a bit critical, but I like the approach. Good job.

    ReplyDelete
    Replies
    1. I see your points, still I am not too worried. I think it can get a lot better. Proper lighting will provide a good sense of depth. Mixing species is not a problem, some trees can be very different and they will still blend.

      Last, about the boxy images. Keep in mind this is LOD 10. Those polygons will be so far away from the camera (5km or more) that will take only a few pixels on screen. You are looking at a magnification of more than a thousand times, it is normal that it won't look right up close.

      Delete
  7. Foliage in CG always look too busy and dark to me. There was a Siggraph paper that had the idea of using a moving-window average normal for shading foliage, filtering out much of the buzziness. I'll see if I can find a cite.

    ReplyDelete
    Replies
    1. Thanks, it will help.

      I have experimented with a radiosity solution that performs scattering through the crowns. Some light goes through entirely and comes out with a slight green tint. It creates a nice atmosphere under the trees.

      Delete
    2. "Simplified Tree Lighting Using Aggregate Normals", Scott Peterson & Lawrence Lee (DreamWorks Animation), Siggraph 2006

      Delete
    3. Thanks, I'll check it out tonight.

      Delete
  8. So, when do we get to see an entire forest with all the LOD at the right distance? =D.

    ReplyDelete
    Replies
    1. I probably won't post anymore about trees for a while, it will be better to wait until they are ready so nothing is left to your imagination.

      I have been "walking" under a few kilometers of dense forests for the last couple of days. I see all the pieces coming together nicely, even the streaming, but it is not ready yet. I need to work more on the light scattering in the crowns and find nice images for branches and leaves. The lighting alone is some serious work. I had most of it done, but now I need to port it into the voxel farm.

      Delete