Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by iRaaptorDEV · Aug 02, 2016 at 12:09 PM · procedural-generationstatic batchingvoxelsterrain gen

Why is StaticBatchingUtility not completely combining all of my meshes?

I'm trying to create a 3d procedural voxel terrain generator.. I've seen things on how batching will allow for optimization. I've tried the SetActive(); fix that a couple people have suggested, it does not work. Although it does batch, it separates them in to four parts instead of one static mesh. Everything is static, It's in a empty game object called terrain_container. I've tried disabling shadows, lighting, etc.. and I've heard that shaders might be breaking the batching, but I haven't put in any of my own shaders. alt text

This is what it looks like, the combined mesh. As you can see there are 4 separate meshes.. Why?

alt text

This is what I'm trying to batch. And my code;

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class GenerateTerrain : MonoBehaviour {
     
     public static GameObject vox_blank = Resources.Load("Voxels/vox_blank") as GameObject;
     public static List<GameObject> Blocks = new List<GameObject>();
     public static int Voxels;
     public static GameObject[] vv;
 
 
     public static void Generate(int size_x, int size_y, int size_z){
         float voxelScale = vox_blank.transform.localScale.x;
         Voxels = 0;
 
         vv = new GameObject[size_x * size_y * size_z];
 
         GameObject terrain_container = new GameObject();
         if (GameObject.Find ("Terrain"))
             Destroy (GameObject.Find ("Terrain"));
 
         terrain_container.name = "Terrain";
         terrain_container.isStatic = true;
         terrain_container.tag = "blankVoxel";
 
         for (float x = 0; x < size_x; x += 1) {
             for (float y = 0; y < size_y; y += 1) {
                 for (float z = 0; z < size_z; z += 1) {
                     GameObject newVoxel = GameObject.Instantiate (vox_blank);
                     newVoxel.transform.SetParent (terrain_container.transform);
                     newVoxel.transform.position = new Vector3 (x, y, z);
                     newVoxel.name = "vox_blank";
                     newVoxel.tag = "blankVoxel";
 
                     vv [Voxels] = newVoxel;
                     Voxels++;
                 }
             }
         }
 
 
 
         print (vv.Length + " voxels");
         print ("Done terrain");
 
 
         foreach (GameObject obj in vv) {
             obj.SetActive (false);
             obj.SetActive (true);
         }
 
         StaticBatchingUtility.Combine (vv, terrain_container);
 
 
         //StaticBatchingUtility.Combine (Blocks.get);
     }
 }
 


9e876d8cba88ac18051c3bc3aadc73f4.png (39.6 kB)
be1e11e786d2e82a9fe7faf5169a6e5a.png (65.0 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Aug 02, 2016 at 12:40 PM

A Mesh in Unity can only have 64k vertices as Unity uses a 16-bit index buffer. So you can't reference more than 64k vertices in a single mesh.

Creating a gameobject for each voxel is total overkill. You should create the mesh manually. When you create the mesh you also want to remove faces of opaque voxels which are next to each other. Minecraft for example generates chunks of 16x16 which itself is split into 16 sections (16x16 ==256 height). This won't work in Unity since the worst cast vertices count for a single 16x16x16 section that is filled with transparent cubes is 98k vertices. So you would need to use smaller chunks in Unity.

Furthermore MC allows other "meshes" as voxels which might have more than 24 vertices.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image martinasenovdev · Dec 06, 2018 at 03:27 AM 0
Share

I am having the same problem as the OP. I am combining ~600 meshes with the StaticBatchingUtility.Combine. The drawn triangles in the Stats window are not reduced, I even get more draw calls than before. When I look at the Editor view the combined mesh clearly doesn't have its faces weld together, and it is obvious since it will not result in so many tris and verts. All tiles are instances of the very same prefab.

alt text

screenshot-36.png (36.9 kB)
avatar image Bunny83 martinasenovdev · Dec 06, 2018 at 04:10 AM 0
Share

You have 626 submeshes. You should make sure that equal instances should use the same material. $$anonymous$$eep in $$anonymous$$d that you should never touch the ".material" or ".materials" property of a renderer. Only read the shared$$anonymous$$aterial / shared$$anonymous$$aterials. If you read the .material property Unity will automatically create an instance of the material for this instance. In that case you can't batch the instance since it has a unique material.


Note that batching has nothing to do with "welding" vertices, removing vertices or removing faces. Batching is only about combining several meshes with the same material into a single mesh. The batched mesh will have the exact same amount of vertices and triangles, but usually with fewer drawcalls as long as there are instances which use the same shared material.

avatar image martinasenovdev Bunny83 · Dec 06, 2018 at 04:30 AM 0
Share

Thank you, meanwhile after I posted the comment I tried with $$anonymous$$esh.Combine$$anonymous$$eshes and mergeSubmeshes=true which on first glance achieves the same as what the StaticBatchingUtility does. At this point I am not sure if merging submeshes does provide performance boost. However now I don't have any submeshes.

I was wondering if there is a technique of merging (welding) vertices as obviously wherever there are flat surfaces, the triangles can be unified. Triangle count seems to be the biggest performance killer on low-end Android devices.

Thank you!

alt text

screenshot-37.png (52.2 kB)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Get Terrain material / Set splat maps 1 Answer

Voxel terrain - NOT MINECRAFT - Digging and creating with resources 0 Answers

Help with randomly generated terrain! 1 Answer

Batching object with script that chooses random diffuse texture? 1 Answer

Texture Atlasing only beneficial with Batching? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges