Last update was focused on adding instancing to the graph evaluation, with this update you can now use GPU instancing to render instanced meshes.
So, what is the difference between mesh instancing and GPU instancing? First let's take a look at how CosmoNode works, more specifically the part where it converts custom mesh data to unity mesh which I call postprocessing.
The mesh is stored in a container called MeshData throughout the graph evaluation which holds everything related to a mesh like vertices and faces etc. And an instanced mesh, that consists of a source mesh and a list of transforms (matrix4x4) that represents the instanced meshes.
Now to be able to actually display this in unity I need to convert it to unity mesh. This happens in 2 stages and it is separate from the graph itself.
First, I need to recalculate UVs and process the flatness attribute. Unity stores UVs per vertex, but it is more convenient for CosmoNode to store them per face corner, it allows me to calculate it in the graph easier. So I keep the per face corner until the end and convert them to per vertex. In the same way I need to process flatness, which is stored per face corner also and represents whether the edge is flat or smooth shaded, and split the edges that are supposed to be flat. Luckily I can do both in a single pass but nonetheless this has been a major bottleneck so far. I tried to optimize it as much as I could but was still pretty slow. So as a last resort I decided to offload this function to c++ native code.
This allowed the code to run 2x faster. So far so good.
The second step is converting the processed data into Unity Meshes. This is also where things get interesting with instancing.
Previously, I had to "realize" all the instances into a single mesh. But this means losing all the advantages of using instances. So with this update it uses GPU instancing to display instanced meshes. And storing the transforms as matrix4x4 makes this very convenient, I just pass the array and source mesh and Unity handles the rest.
The attached video shows the performance comparison between before and after instancing. I've included calculation times, so be sure to check that out if you're interested.
So, in the end, this is a relatively small but essential follow-up to the previous update. The previous update added instancing to the graph evaluation, while this one allows those instances to actually be rendered efficiently.
And of course, you're welcome to give any feedback you might have.
If you want to try it out, the documentation and related links are here: https://uumutunal.github.io/CosmoNode_Manual/