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 spartacuss1011 · Sep 04, 2019 at 09:11 PM · meshmeshrenderer

Rendering invisible objects

Hi,

I have a cube that i rendering the faces of based off of weather or not there is a cube next to it (im attempting to make a mine craft clone). Now, I have gotten this visibly working, however, it is still running rather slow. To test, i hid all the faces on all the cubes. This visually renders nothing, however, the lag is still there and the CPU profiler is suggesting that the renderer calls are what is slowing everything down.

I am still new to modifying meshes, so is there possibly a step i have missed when modifying the mesh? Or is there something I need to set in the unity editor etc? Or is this just expected when rendering each cube separately, as opposed to proper voxel "chunk" like rendering?

i have attached the script I am using to modify the mesh. This code is only being called once on startup.

Please let me know if any more information is needed.

Thanks in advance

     public void UpdateBlockRender()
     {
         //From list of touching blocks, figure out which sides to render
         Mesh mesh = GetComponent<MeshFilter>().mesh;
         
         List<Vector3> VertToAdd = new List<Vector3>();
 
         if (visibleFaces.ShowNorth) VertToAdd.AddRange(Misc.FaceVerticiesOrderedToMatch[BlockDirection.North]);
         if (visibleFaces.ShowSouth) VertToAdd.AddRange(Misc.FaceVerticiesOrderedToMatch[BlockDirection.South]);
         if (visibleFaces.ShowTop) VertToAdd.AddRange(Misc.FaceVerticiesOrderedToMatch[BlockDirection.Top]);
         if (visibleFaces.ShowBottom) VertToAdd.AddRange(Misc.FaceVerticiesOrderedToMatch[BlockDirection.Bottom]);
         if (visibleFaces.ShowWest) VertToAdd.AddRange(Misc.FaceVerticiesOrderedToMatch[BlockDirection.West]);
         if (visibleFaces.ShowEast) VertToAdd.AddRange(Misc.FaceVerticiesOrderedToMatch[BlockDirection.East]);
 
         List<int> TriToAdd = new List<int>();
 
         int faceCounter = 0;
         if (visibleFaces.ShowNorth)
         {
             TriToAdd.AddRange(new int[] { 2,3,0,3,1,0 }.Select(x => x + faceCounter*4));
             faceCounter++;
         }
         if (visibleFaces.ShowSouth)
         {
             TriToAdd.AddRange(new int[] { 0, 2, 1, 1, 2, 3 }.Select(x => x + faceCounter * 4));
             faceCounter++;
         }
         if (visibleFaces.ShowTop)
         {
             TriToAdd.AddRange(new int[] { 0, 2, 1, 1, 2, 3 }.Select(x => x + faceCounter * 4));
             faceCounter++;
         }
 
         if (visibleFaces.ShowBottom)
         {
             TriToAdd.AddRange(new int[] { 1,2,0,2,3,0 }.Select(x => x + faceCounter * 4));
             faceCounter++;
         }
         if (visibleFaces.ShowWest)
         {
             TriToAdd.AddRange(new int[] { 2, 0, 1, 2, 3, 0 }.Select(x => x + faceCounter * 4));
             faceCounter++;
         }
         if (visibleFaces.ShowEast)
         {
             TriToAdd.AddRange(new int[] { 2,3,1,3,0,1 }.Select(x => x + faceCounter * 4));
             //faceCounter++;
         }
 
 
         mesh.Clear();
         mesh.SetVertices(VertToAdd);
         mesh.triangles = (TriToAdd.ToArray());
 
         mesh.RecalculateBounds();
 
         //mesh = newMesh;
 
         Vector2[] UVs = new Vector2[mesh.vertices.Length];
         int index = 0;
         
         if (visibleFaces.ShowNorth) // Front
         {
             UVs[index++] = new Vector2(0.0f, 0.0f);
             UVs[index++] = new Vector2(0.333f, 0.0f);
             UVs[index++] = new Vector2(0.0f, 0.333f);
             UVs[index++] = new Vector2(0.333f, 0.333f);
         }
         if (visibleFaces.ShowSouth) // Back //For some Reason, back renders upside down. values have been changed to reflect that
         { 
             UVs[index++] = new Vector2(1.0f, 0.333f);
             UVs[index++] = new Vector2(0.667f, 0.333f);
             UVs[index++] = new Vector2(1.0f, 0.0f);
             UVs[index++] = new Vector2(0.667f, 0.0f);
         }
         if (visibleFaces.ShowTop) // Top //For some reason, top renders right to left, values have been changed to reflect that
         {
             UVs[index++] = new Vector2(0.666f, 0.333f);
             UVs[index++] = new Vector2(0.334f, 0.333f);
             UVs[index++] = new Vector2(0.666f, 0.0f);
             UVs[index++] = new Vector2(0.334f, 0.0f);
         }
         if (visibleFaces.ShowBottom) // Bottom //For some Reason, Bottom renders upside down. values have been changed to reflect that //Might actually render right, who knows
         {
             UVs[index++] = new Vector2(0.333f, 0.666f);
             UVs[index++] = new Vector2(0.333f, 0.334f);
             UVs[index++] = new Vector2(0.0f, 0.334f);
             UVs[index++] = new Vector2(0.0f, 0.666f);
         }
         if (visibleFaces.ShowWest) // Left
         {
             UVs[index++] = new Vector2(0.334f, 0.334f);
             UVs[index++] = new Vector2(0.334f, 0.666f);
             UVs[index++] = new Vector2(0.666f, 0.666f);
             UVs[index++] = new Vector2(0.666f, 0.334f);
         }
         if (visibleFaces.ShowEast) // Right  
         {
             UVs[index++] = new Vector2(0.667f, 0.334f);
             UVs[index++] = new Vector2(0.667f, 0.666f);
             UVs[index++] = new Vector2(1.0f, 0.666f);
             UVs[index++] = new Vector2(1.0f, 0.334f);
         }
         mesh.uv = UVs;
 
         mesh.Optimize();
     }

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

Answer by JonPQ · Sep 04, 2019 at 09:21 PM

if all the faces are removed from cube, you can turn off the whole gameobject for that cube. process nothing. at a minimum, disable the meshRenderer component. Also make sure you only construct the mesh when something changes... not every frame.

You might want to try combining many cubes in an area into one mesh, so you can send them all in one draw-call, one mesh together. to reduce overhead. Maybe combine them by material type... use same shader / material on all/most of the cubes if you can. but Just with different uv's / vertex color

Comment
Add comment · Show 2 · 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 spartacuss1011 · Sep 04, 2019 at 11:04 PM 0
Share

So even if the are no sides rendered, I.E 0 vertices, 0 triangles etc, the mesh renderer component still creates overhead just by being enabled? Yes i probably will eventually end up doing a proper voxel solution by joining meshes together, but I'm just trying to understand why it is going so slow. For instance, I am generating around 44000 cubes, with only about 3000 cubes visible (side and bottom blocks of the "chunk" aren't being rendered at the moment) but still getting 20 fps when i put all of them in the camera frame at once

avatar image JonPQ spartacuss1011 · Sep 05, 2019 at 04:29 PM 1
Share

pretty much anythign in the scene is going to cost some kind of overhead. only an empty scene with no cameras could be considered to have 0 overhead. So.... 40,000 objects in a scene is a huge number of objects.... even if they have nothing much in their mesh. if its all enabled, that forces unity to transform them all, and do a frustrum check for each camera (per object) to see if it is on screen. Thats a lot of math... Then for each object on screen, process the meshes to do polygon culling... granted yours are empty... but if you have 3000, empty cubes it will still do 3000 checks to deter$$anonymous$$e they are empty... for the cubes that have meshes in them... Unity will try to batch and draw them (if you have batching enabled) it does all this every frame.... If your cubes are all individual meshes or with many materials materials etc... they may not batch well, (and its also a lot of objects to batch)... before drawing anything. Try turning on the "stats" window in top right corner... for mobile 3d.. I usually aim for <100 draw calls, and < 50,000 vertices total. (aim for <20k verts if you want to support older devices.) What do you have ?
Try to further arrange your cubes in a hierarchy, so that you can completely turn off large sections of the hierarchy, or know if they are obscured.

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

121 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can you manually set the layer order for triangles inside a mesh? 2 Answers

Why The shareMesh isn't full load when i load a prefab with SkinnedMeshRenderer in unity? 1 Answer

Why does adding cloth component to skinned meshrenderer move the bounds away from the mesh? 2 Answers

My mesh isnt creating any shadows 1 Answer

Mesh Resolution Problem 1 Answer


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