Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

I'm trying to use cubes to simulate grass

Discussion in 'Scripting' started by C10110, Jun 1, 2015.

  1. C10110

    C10110

    Joined:
    Jan 19, 2013
    Posts:
    56
    Hello all!

    I'm in the process of making a game where everything in the game world is made out of primitive 3D shapes. It actually makes sense for the story, but I won't get into that.

    Basically I'm trying to make a more 3D grass that looks like i'ts composed out of cubes. Here is a video I recorded of some cubes I animated under empty game objects and copy + pasted around a small scene that sort of gives off the look and feel I want:

    https://www.dropbox.com/s/qrhkq666s5m6l9y/Cube Grass Test - No audio.mp4?dl=0

    The problem is doing it this way will create a massive amount of draw calls in a game world that is already going to have a ton of draw calls to begin with. I'm wondering there is a way to get this same effect via script and some how optimize it to work better than just copy and pasting cubes with an animation.

    I look forward to hearing your thoughts on this! Thanks!
     
  2. magnetix

    magnetix

    Joined:
    Apr 4, 2010
    Posts:
    102
    To reduce draw calls, you could do this by creating your own custom mesh and editing the vertices at runtime. The mesh could be constructed so that it appears to be made from cubes, but you would only have a single draw call. There is a script in Unity's Standard Assets called CombineChildren which I believe will do this, or you could refer to this post for a little further thought on the topic.

    See also the section entitled Mesh Helpers on the Unify Community page for help creating custom meshes.
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Voxels. Google it.

    It doesn't in Mine Craft, and people still love that. :)
     
  4. C10110

    C10110

    Joined:
    Jan 19, 2013
    Posts:
    56
    Thanks magnetix, I was hoping there would be some way to combine the children. I had no clue there was a script that did that in the new standard assets.

    BoredMormon, Yeah, I debated using voxels for quite some time, but in the end it doesn't give the graphical effect I'm aiming for. I do love Voxel artwork though!