So, i have lots of trees in my scene and i wanted to optimize them by using one material instead of 2. How can i do this? Can i do this even if the types of the materials are different? Thanks
This is the tree prefab:
Hello, this is a good question. I have a decent sized library that I created that does exactly what youāre looking to do. I have a single material atlas for all of my trees and bark.
Itās a matter of creating custom UVās with modeling software and mapping the leaves and the bark to the same material atlas. You could do this for a single tree, or like in my case, have 20+ leaf and flower types on a single material atlas. For older default render pipeline versions, I made a custom shader for this originally, but in recent unity versions using URP or HDRP, Iāve had good results using the default speedtree shaders.
The performance benefits can vary drastically doing this depending on the target platform and how well it handles overdraw of the transparencies. Also, if your trees are high poly like 15,000 vertices each, then youāre only going to be able to combine about 4 them into a single game object, which might not be as beneficial in lowering batches as combining 30 trees that are 2,000 vertices each.
If you do not know how to manually UV meshes, there are a few tools in varying complexity that will create an atlas and auto UV the meshes for you. āMesh Bakerā is one example thatās been around for a pretty long time and works. Itās a robust and complete solution.
Regardless of the route that you go to create your material atlas, you are most likely going to see better benefits by manually combining trees that are close together. It is possible to create very dense forests using combined āclumpsā of trees and then use GPU instancing to repeat those clumps over and over and varying sizes and color variations.
Very few vegetation and tree assets use atlases which is mainly due to how older hardware used to handle trees and transparency. A very rough and basic explanation, but thatās the general idea.
OWA Trees 01 is one of the only atlased tree pack that Iām aware of (there could be others but they are few and far between). Full disclosure, I am the creator of that asset and there are around 80 unique tree prefabs included that all share 1 single material, not just for bark and leaves, but 1 single material total for the entire collection.
Which way you go depends on how much you value having the skill of manually UVāing to your toolbox. Like anything whether it is worth the time for your project to do it yourself.
Last but not least, I will say that atlasing, use of batching and/or mesh combining does not usually deliver as good of performance benefits as game objects sharing a material that use opaque shading.
The benefits of sharing a material mostly affect the cpu performance by batches.
you can edit the UV of the meshes to make them share the same texture, then the same material can be set in both slot.
otherwise, using LOD or 2D impostor would improve performance a lot
Thank you for your response! im not that good with 3D modelling softwares, so i never did mesh UVs (iām making my first 3D game, so i dont have lots of experience), but iāll try to use a mesh baker for it. Thanks againš
iām already using 2D imposters at a certain distance, right now by looking only at the trees (i put occlusion culling obv) ans the batches are around 1500 and 2000. Iāll look into mesh UVās and try to edit them. Thanksš
I think imposters are great used sparingly where appropriate. What kind of view distance are you rendering on the camera? Are you using unity terrain? If, so thereās a good chance that you would actually get more batches saved by converting your terrain to mesh. The main downside to that is grass, but itās a dead simple solution for winter snow or desert terrainsā¦really depends on the level, but using meshes instead of the native terrain just might save you 1,000 batches or maybe even more in one shot.
Depending on how far your view distance is, it can be the difference between 30 fps and 200 fps on desktop. The optimization benefits of exporting terrains to mesh are extremely beneficial for lowering batches. Terrain to Mesh is a similarly priced asset as mesh baker but it does the terrain to mesh conversion. I wish there was an easy non-paid solution for that, but this asset has been very reliable for me. Full disclaimer, there are people that might disagree and mesh terrains are not perfect for every project, but when exported with the right settings, the performance gain is undeniable from a factual and quantifiable profiler stats on most platforms.
PS Youāre welcome! If you have any more questions feel free to ask
My settings are:
Camera distance:
Near ā 0.1
Far ā 300
Terrain Settings:
The assets that you linked would be great, but unfortunately i cant afford to pay for assets for now , is there another way to convert it to a mesh? Thanks
Thereās not a way that I currently have used and worked. Your view distance is pretty short (300 meters). Thatās a lot of batches for that view distance. Sorry again for only knowing of paid solutions. If you want to PM me, I can send you a couple of my personally created atlased trees so you can make sure that route is a good fit. There is a terrain to obj from the same publisher that is only $15ā¦still paid but much more affordable.
Converting to mesh is also something that I would do last when everything else is complete. The most important aspect is understanding how many batches it will save you on the CPU. That way you donāt spend time optimizing stuff thatās not your actual bottleneck. Send me a PM if you like and I can help you test and see for yourselfā¦at least check the benefits of atlasing your trees. That way when you get towards completion of your project, you can decide if itās worth it.
Donāt worry, there isnāt many free assets for this, iāll pm you so you cand send me your trees. Thank you so muchš