I’m working on a poor man’s terrain replacement project. It creates a mesh from a heightmap, has lod handling, all that.
Here’s some screenshots, if you look at them on another tab and zoom in you can see that the distant trees are very dense, and very distant. I haven’t been able to get this kind of distance and density using Unity’s billboard trees.
http://forum.unity3d.com/threads/188495-Procedural-Terrain-with-Dense-Forests/page3
The way I handle distant trees is, they are just tall grass basically. It’s two bisecting planes. 8 Vertices, 4 polygons. There is no “billboard” rotation to always face the camera. I create patches of trees, and combine them into one mesh. The performance is great, in my opinion. Obviously, there are some “gotchas”, but it works well for my needs. The upside is, I don’t have to manage each individual tree polygon, just the mesh patches. I suspect Unity draws and calculates its billboard trees on an individual basis.
Ok, here is what I need to know.
I want to just use billboard trees, locked to the Y axis.
But the challenge is…each tree quad would be part of a mesh of other tree quad polygons.
The trick as I see it is, each vertex needs to store the vertex offset from the pivot, AND the location of the pivot itself. This would allow you to rotate each vertex around the pivot to face the camera. Why not have each vertex coordinate the actual pivot, and the UV2 data be the offset data?
So, four vertices. A tree polygon, 5 meters wide, 10 meters tall. Pivot is in the center at 0.0 (local to the polygon vertices, NOT the mesh vertices).
This quad is to be positioned at 12.0, 10, 3.5 in world coordinates.
Vert 1 (bottom left, on the ground) - UV2 would be new vector2(-2.5f, 0)
Vert 2 (top left) - UV2 would be new vector2(-2.5.0f, 10.0f)
Vert 3 (top right) - UV2 would be vector2(2.5f, 10.0f)
Vert 4 (bottom right) - UV2 would be vector2 (2.5f, 0.0f)
Each vertex coordiante would actually be the quad pivot coordinate…12.0, 10, 3.5.
Again, I want this to be locked to the Y axis. So, it would only be adjusting the vertex X and Z positions, to avoid the “tilting” or bowing effect when you are nearby and tilt the camera. I could probably do this in C# or something pretty easily, but I don’t know how to do it in a vertex shader.
So, in summary…with the UV2 coordinates for a quad holding offsets of each vertex from the quad pivot, would it be possible for a vertex shader to use this to rotate those to face the camera. Even if the polygons are part of a larger mesh. This way, even a giant mesh of polygons could be used for distant billboards. Maybe this is how the particle system works, I don’t know.
Really hoping for some advice or direction on this.
Thanks,
JC

