- Home /
I need my meshes to use less memory
If I'm not mistaken, Unity's vertex arrays use floats. Is there any way to use a different data type? Some of my meshes store vertex data that could easily be represented with shorts instead. The meshes take up a huge amount of memory, as they have many vertices. While I could use a mesh optimization algorithm, it seems like using smaller datatypes would be the first thing to check.
Any ideas?
(Actually, they may even be able to be represented as bytes, but not sure if opengl/directx supports that).
This would be nice. 2-byte UVs would save a bit (so long as your UVs stay within 0..1).
Answer by Eric5h5 · Dec 30, 2010 at 12:17 AM
Unity already does this...you can set mesh compression to low, medium, or high in the import settings. Though the best thing to do is reduce the number of vertices used in the first place.
$$anonymous$$y apologies...I left out an important bit of information. I'm creating the meshes procedurally, it's a $$anonymous$$ecraftish terrain. Even breaking the terrain into chunks of 32x32x128 blocks, the chunks often break the 65k vertex limit. Performance is no problem at all. It's the meshes gobbling up so much memory. Also, I'm using a collision mesh for each mesh, which probably uses up quite a bit also. I could probably handle collision on my own, and drop the collision mesh...that might help out a bit. I was just looking into the quicker options first :)
Here's a screenshot for easier visualization: https://dl.dropbox.com/u/5556115/AwesomeTrees.jpg
In case anyone looks at this, no, Unity does not compress the mesh using different value types. The compression appears to just be rounding in the stored file. The documentation now also says that it does not affect runtime memory usage.
Answer by BerggreenDK · Dec 29, 2010 at 11:36 PM
I believe most 3D programs produces Vector3D coords with floats or bigger variables.
Perhaps you could rethink the meshes for low-poly and level of details (LOD) ?
Is it only a memory problem or a performance problem while rendering a frame? How big are the meshes? how many poly/vertexes are we talking about?
Answer by Ben Throop · Dec 30, 2010 at 02:41 AM
What about using instanced geometry instead of explicit mesh? You could go beyond a single cube, and determine a few patterns that repeat (2x2, 3x3, 4x4 as easy examples, but there are no doubt many, many repeating patterns to be found). You'd probably trade some CPU for the transform/material switch on these, but if memory's what you're after, it would make sense to investigate this route.
And while I'm thinking of it, it would seem that some kind of tree data structure would be helpful. So whereas a 4x4 chunk might start out as a leaf node, once it gets broken, you turn off the mesh renderer and add the appropriate children underneath that node. You would only render the leaf nodes.
If by instanced geometry you mean gpu/hardware instancing, from what I understand Unity does not support this. If you mean create meshes for patterns, and just create gameobject copies of that, wouldn't the vertex and collision information also be duplicated, or no?
Also, as far as a tree data structure...the raw terrain data doesn't use that much memory. One byte of data for each terrain means 33 megs of memory, a pittance. The meshes use several hundred megs of memory, by comparison...about 4 or 5 hundred.