Gloomy endless woods...

Started by
3 comments, last by solenoidz 13 years, 3 months ago
[size=2]Hi guys.<br /> [size=2]I&#39;m trying to implement big forest over a terrain, but I&#39;m not really sure how to approach such a problem. Here are some thought floating around my head.<br /> [size=2]I wonder am I on the right track here, or I&#39;m completely lost..<br /> [size=2]<br /> <br /> [size=2]<br /> <br /> [size=2]-make a mesh, containing several tree models. Lets say - 10x10 trees in a single mesh.<br /> [size=2]-on a grid pattern around the camera and way ahead the camera view, position that mesh and render it several times on the grid patches that fall in view frustum. <br /> [size=2]-in order to position the trees in the mesh above the terrain height, use vertex texture fetch in the vertex shader and offset the Y position of the vertices, according to the terrain height sampled under that vertex.<br /> [size=2]-Of course, I need to skip rendering tree of there are roads, rocks, buildings and such bellow.<br /> [size=2]-I can sample a distribution map to see where on the terrain I need to place trees. If there shouldn&#39;t be trees, I can move the vertices bellow the ground for example to hide the tree. But on the road edge for example if there is a tree, that would lead to annoying distortions, when I hide the vertices that fall over the road and show those that fall over the nearby terrain. <br /> [size=2]Maybe I need to hide the entire tree, if any of it&#39;s vertices are above the road. But in the vertex shader, all the 10x10 trees are in a single mesh, and there is no separate tree to hide.<br /> [size=2]It all seems ugly and wrong to me.<br /> [size=2]I have a feeling, that I need to use instancing. How can I render a bunch of trees in one draw-call, position every one of them over the terrain (VT fetch again?) and skip those trees, that fall over a road, rocks, buildings etc ?<br /> [size=2]<br /> <br /> [size=2]Thank you for your time.<br /> <br /> <br /> <br /> <br /> [size=2]<br />
Advertisement
Trees (good looking ones anyway) are probably a really tough thing to get right. I don't think you're going to get away with just one mesh, you probably need a LOD scheme to do different things from distance to the player. A close up tree with a lot of leaves and branches could probably take up a big chunk of rendering time, and if you just blindly stamp this in 1000 places it's not going to run at interactive rates.

I would probably not use a "grid of trees" as your base mesh, as this is going to be very noticeable and repetitious from ingame. I would probably create a handful of different tree models at different level of detail, from close up (detailed mesh + detailed leaves), medium distance (low poly mesh with maybe a couple billboard leaf chunks), to distant (flat billboard). And then use some noise algorithm to sprinkle these randomly around your terrain.

As far as instancing, that can be a performance boost dependent on the API you're using, but I feel like you've got a lot more thinking to do before you get to the point where you really need to hone the performance.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
One approach for the position of trees I do remember is in the Nvidia OpenGL SDK 10 - the demo called "Cascaded shadow Maps".

The author used a top down render of the terrain, prepared offline in greyscale, then positioned where they wanted trees by placing a white pixel(s), using photoshop or similar.
Then testing for this when initialising the program and storing the position by scaling the pixels position to the actual dimensions of the terrain.

So when they render the scene they iterate through the stored position vectors, and draw a tree at that position.
This could be extended perhaps to test for other specific colours to indicate different tree types. Red = ..., etc, and store this with position.

You would want to make it more efficient since they dont have many trees in this demo, so perform a visibility test for each position to see if its within frustum before bothering to draw etc.

Anyway just thinking on my feet, no experience of this :)

Another recent article comes to mind which discusses the merits of Imposters for trees, i.e. LOD as mentioned above.
http://www.gamasutra.com/blogs/DavidRosen/20101004/6126/Imposters.php
I haven't implemented this yet but it's a goal of mine.

As a preliminary plan I'm looking at generating details procedurally for the nearest LOD. It seems to model an accurate forest environment will require specifying 'interior' and 'edge' zones because trees grow differently and usually grow together to form a solid canopy.

For medium LOD some kind of combination of procedural followed by imposters may be used. At far enough distance eventually it might become generic (non-procedural) billboards.

The furthest LOD ie miles distant could be simple polygons.with clever texturing.

I would love to see some implementations so send me a message if you make a demo you could show off :)
Thank you guys.

This topic is closed to new replies.

Advertisement