Mesh to Billboard Pipeline
In God's Table, I needed to create a way to populate vegetation over an entire island. I was able to achieve around 5k items using brute methods of spawning individual prefabs, then around 20k-50k items using static particles, but I wanted to see if I could reach larger scales. Ideally, the solution would create 100k+ items.
I decided to approach the problem using billboards, where each item would be treated as a vertical billboard. To achieve this I created a special mesh, where each "vertex" was the location of one of these items. The quotes are because each high level vertex was actually four vertices, with each point-vertex corresponding to a different corner of the billboard I wanted to create, using the mesh's UV data to indicate which corner each point-vertex corresponded to. The mesh was created using the following builder class:
I decided to approach the problem using billboards, where each item would be treated as a vertical billboard. To achieve this I created a special mesh, where each "vertex" was the location of one of these items. The quotes are because each high level vertex was actually four vertices, with each point-vertex corresponding to a different corner of the billboard I wanted to create, using the mesh's UV data to indicate which corner each point-vertex corresponded to. The mesh was created using the following builder class:
Code Editor
A nice feature of this class is that I can define scale dynamically, meaning I can create crowds of items that look more natural. One thing that could be implemented in the future is to have separate xScale and yScale parameters. The code to create a billboard mesh using this class is very simple:
Code Editor
Finally, the shader itself takes in the UV data and stretches each set of points into the correct orientation and scale.
Code Editor
Using this framework, I was able to dynamically create forests of up to 200k trees. One complaint about this framework is that it does not look good close up. However, the product I was creating this for was a birds-eye-view experience, so graphical fidelity wasn't an issue. If I were to come back to this shader, the first thing I would do is fix the strange shadow errors that appear around the edges of billboards.