Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by tommykent1210 · Oct 27, 2012 at 10:33 PM · terrainrenderinggenerationvoxelminecraft

Voxel based Terrain generation. Pointers please.

Ok, I'm new to Unity, and somewhat new to C#. I have programmed extensively in vb.NET (so I have a reasonable knowledge in .NET's core data types etc../) and also in PHP (so, other than type defining, the syntax is fairly similar when combined with vb).

Now, before I start, YES I have Googled around, but I haven't found what I'm looking for. And, NO, I'm not trying to make a minecraft clone ^_^.

What I am trying to make is a 3rd person RTS style game, but with voxel based cubic terrain. I do, however need to be able to have characters mine these blocks, so I'll need some way of knowing what type of block they are.

Now, I understand how Perlin works, and I found a good script to work from for that, so I can generate an array of smoothed noise for the terrain. However, I'm not sure how to store/draw it.

I was thinking of a 3 dimensional array (X,Y,Z) of a structure containing the block ID. The program could then look in an array of a structure containing the actual block data (texture, type, name etc...). However, my main question is how would i draw it out?

I tried simply instantiating each block, but basically it crashed Unity due to the sheer number of prefabs (and my machine is pretty beefy with 16gb RAM). So, I read that I could:

  1. Only draw visible cubes - but how would I decide which are visible to the third person camera?

  2. Draw meshes? I have no idea how you would actually implement this, as I'm not familiar with meshes and UVs (I think that was their name).

Any help, pointers, good reading etc would be appreciated.

Thanks Tom

My reading so far:

http://forum.unity3d.com/threads/63149-After-playing-minecraft...

http://forum.unity3d.com/threads/69573-MinePackage-Minecraft-starter-package/page3

http://answers.unity3d.com/questions/177931/tutorial-minecraft-chunks.html

Comment
Add comment · Show 1
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 coastwise · Nov 05, 2012 at 08:11 PM 1
Share

0 FPS has some awesome articles on the subject:

  • http://0fps.wordpress.com/2012/01/14/an-analysis-of-$$anonymous$$ecraft-like-engines/

  • http://0fps.wordpress.com/2012/06/30/meshing-in-a-$$anonymous$$ecraft-game/

  • http://0fps.wordpress.com/2012/07/07/meshing-$$anonymous$$ecraft-part-2/

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Nonakesh · Oct 28, 2012 at 10:53 AM

I think Minecraft uses a algorithm that only shows voxels if they have at least one side that is touching a transparent block, like glass, air, water and so on.

I think they are textured by placing the UVs of each block on the right place on a texture sheet.

Whatever you do I don't think you'll be able to do it without generating a mesh. Look at this class: http://docs.unity3d.com/Documentation/ScriptReference/Mesh.html

If you can't understand what is going on there, maybe you should look into a 3D modelling program. Just look at some beginner tutorials to understand the basic techniques.

Maybe this helps you as well: http://en.wikipedia.org/wiki/Marching_cubes Just search for marching cubes and you'll find the code for it. That algorithm will give you a smooth terrain.

Comment
Add comment · Show 36 · 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 tommykent1210 · Oct 28, 2012 at 11:06 AM 0
Share

Hi, thanks for the reply.

Would you recommend $$anonymous$$arching cubes over Perlin then?

Also, what exactly is a UV? I know what meshes are though :)

avatar image Nonakesh · Oct 28, 2012 at 11:15 AM 0
Share

$$anonymous$$arching cubes is just a method to display the voxels, not to generate the terrain, so you'd have to use both to get a smooth terrain.

The UV coordinates are used to tell the graphic engine which part of a texture should be used, so if you have a quad with the coordinates

(0 | 0) (0 | 1)

(1 | 0) (1 | 1)

, it will show the whole texture on this quad.

If you use this:

(0 | 0) (0 | 0.5)

(0.5 | 0) (0.5 | 0.5)

It will show the upper left quarter part of the texture.

That is exactly one of the things you could try out by using a 3D modelling program like Blender, but I think it would be quicker to just read a article about it. Like that one: http://en.wikipedia.org/wiki/UV_mapping

Just google it.. you'll definitely find out more about it!

Imagine a texture sheet with textures like Dirt, Stone, Grass and so on, ordered in a grid. You can easily set the UV coordinates to one of the textures, by using the coordinates of the grid.

avatar image tommykent1210 · Oct 28, 2012 at 12:27 PM 0
Share

ok, UV mapping is pretty simple, I didnt realise UV was just a way of saying XY (but without using X and Y :P).

So, basically, I should:

  1. Generate perlin noise to get the height maps.

  2. Iterate through each block location, if the heightmap is equal to the Y coord of the current block, generate grass. If the Y coord is smaller than the perlin height, generate a random block like dirt or stone, if the Y coord is higher than the height from perlin, generate air .

  3. Generate vertices from the block array, and use that to make a mesh?

I am still confused as to how to do step 3.

avatar image Nonakesh · Oct 28, 2012 at 12:34 PM 0
Share

I think that's the best way to do it. Although I think you shouldn't use the y coordinates to tell if it is grass or not. Just let the first block on the top be grass. For something like stone I would do something like "Every block X blocks under the top block is stone" X should be a bit random...

Step 3 is probably the complex part of the whole thing. I think you should only show blocks that have a transparent block directly touching them. If you do this the polygon count will be drastically reduced.

avatar image tommykent1210 · Oct 28, 2012 at 12:36 PM 0
Share

Any idea how I would deter$$anonymous$$e which faces should be shown? Or should I simply just iterate through the 6 faces and look for transparent blocks?

Show more comments
avatar image
0

Answer by WizzDE · May 03, 2014 at 04:46 PM

You might want to check out my voxel package I have just released in the unity assetstore. It has some interesting features like pathfinding whitch can be really usefull if you want to create an rpg type game. There is also a model editor for creating characters, weapons, items, etc. I have also provided an example scene with random terrain generation. Check it out: https://www.assetstore.unity3d.com/#/content/17470

Comment
Add comment · 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

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

14 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

Related Questions

Texture mapping procedural mesh with texture atlas? (Minecraft style terrain gen) 1 Answer

Minecraft Biomes: How to Make? 2 Answers

World Generation with Interesting Terrain 0 Answers

Tiled Terrain 0 Answers

Minecraft (Cube) Terrain 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