Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

After playing minecraft...

Discussion in 'General Discussion' started by jc_lvngstn, Oct 8, 2010.

Thread Status:
Not open for further replies.
  1. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    I'm glad you've had so much success with Block Story! I seem to be held back again by math problems with my terrain generator. I'll figure it out eventually. lol
     
  2. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    We just released 7.0 of block story , we added MOGA support, and made a new trailer:

     
  3. GenericGame

    GenericGame

    Joined:
    Nov 26, 2012
    Posts:
    206
    wow, thanks for your comment. I'm a long way from generating an engine like block story has. The game is actually not creative nor can you even break blocks in the actual game. I'm still working on our voxel engine before actually releasing the game. In the game mode, you simply traverse the obstacles you created in creative mode, or play other levels created by other people. Yes we have live combat.
     
  4. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    goldbug, can you share your terrain generation algorithm? And what noise you use? Simplex? Chunk?
     
  5. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    I don't really do that, since this is a commercial product.

    That said, I do offer some basic description of how it works in my block engine demystified series, here:

    http://www.blockstory.net/blog/block-engine-demystified-vii-word-world

    http://www.blockstory.net/blog/block-engine-demystified-viii-terrain-generator

    I will probably add a little more detail some time, feel free to add comments and requests there.
     
  6. F3lko

    F3lko

    Joined:
    May 15, 2013
    Posts:
    2
    Sup guys, I have little question about voxels and animations. For an example: Let's pretend I have voxel terrain, and ingame Voxel Character Editor with different body parts like right\left legs and hands, torso and head (separately) and grouped by prefab.
    Can I Apply skeletal animation on it, or not?
     
  7. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    Your Voxel Character Editor needs to provide for a way to link voxels to the skeleton. A simple way can be to link it automatically to the closest bone. I would predefine the skeleton if I were you. I think it is completely doable.
     
  8. zsa

    zsa

    Joined:
    Jun 6, 2013
    Posts:
    3
    OK
     
  9. F3lko

    F3lko

    Joined:
    May 15, 2013
    Posts:
    2
    Thanks for reply! I'll dig into that
     
  10. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    Sorted out (or worked around) the math for my terrain generator. 32x32x32 chunks don't seem to be much of a problem anymore when I'm not using MeshColliders. All sized chunks still seem to take a few noticeable milliseconds to regenerate which I can hopefully fix. Also the chunks leave mesh holes in them. I'm sure it happens because I'm changing blocks as it's generating but I'm working on a fix for that. Later I'll try to make it infinite again but I may have problems.

    I also want to reduce the drawcalls by only using materials on a chunk that it requires. Like if a chunk only has dirt blocks around the outside edge then it should only need the dirt material and one drawcall. As it is, each chunk will get 4 drawcalls no matter what. Now that I think about it, even the chunks without any blocks in them are getting drawcalls too!
     
  11. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Are you using high res textures for your materials? If not, you atlas them, you can have several textures and still one draw call.
     
  12. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    They're just the individual minecraft textures of grass, dirt, stone and sand. I have to use separate materials or else I can't optimize the mesh per block type, unless you know of some way to stretch uvs across a single part of an atlas.
     
  13. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    Block Story is being demoed in the PowerA booth for MOGA in E3
     
  14. chronos78

    chronos78

    Joined:
    Dec 6, 2009
    Posts:
    154
    So after a couple years since my last voxel engine I thought I'd give it another go for fun. This time though I completely implemented the data storage infrastructure before even attempting to draw blocks. Turns out this is a much smarter way to work even if you have to forgo the instant gratification of rendered geometry. Of course having built a dozen or so failed prototypes does tend to help in terms of knowing what needs to be saved and what does't. But what fun would a Minecraft clone be without blocks so here's where I'm at 48 hours in.

    $voxelWorld01.jpg

    The image shown represents a volume of 256x1024x1024 which is over 268 million blocks and takes 16MB of disk space. Definitely pleased with it so far. In a real game though there will be a about 1/4th the amount of blocks on the screen depending on how much performance is gained from mesh optimizations and of course the speed of the host machine. I just wanted to see how far I could push Unity before it broke and I found out. Unity will run with the terrain in editor as shown but when you stop the player it crashes.

    Need to put together a greedy mesher for the chunk sections but I wanted to thoroughly test the data structure first. It was also important to make sure that both the data storage and terrain generator systems could span seamlessly across section, chunk, and region borders, especially when crossing the x and z axises. Which it does beautifully now, after spending most of today hunting down a ton of bugs.

    As much as I'd like to take the credit it is only fair to point out that my storage solution is modeled in part on the Anvil file format that is used in Minecraft found here.

    Specs:
    • Multi-threaded terrain generation
    • Virtually endless, you'll probably run out of hard drive space before running into precision errors
    • Sections are 16x16x16 blocks
    • Chunks are 16 sections tall or 256x16x16 blocks
    • Regions are 32x32 chunks
     
  15. GenericGame

    GenericGame

    Joined:
    Nov 26, 2012
    Posts:
    206
    good job on getting in E3. I'm just around the corner from the convention center, would love to go see booth if I had an invite to event and could get in. Being a small indie dev doesn't help much.
     
  16. GenericGame

    GenericGame

    Joined:
    Nov 26, 2012
    Posts:
    206
    Considering it took you only 48 hours to get there, great job. =D

    I hear many people talk about how minecraft is a simple game, but in reality, the mechanics behind are very, very tedious to make everything happen together at the right time and with speed. But to the casual programmer, I can see the misleading behavior when someone looks at the game and says "hmmm, I could program that". lol

    Unity locking up on you, I would guess that you have some threads running in the background that weren't terminated properly or resources still in a running thread that have not been moved to the main thread or still contained in a lock? At least this has happened to me on many occasions while exiting and it's what turned out to be the problem.

    Good call on getting chunk storage up and running first, many less headaches in future. =D

    I've now got infinite up/down in KonCraft, polished off today, w00t! The world is nothing but dungeon blocks now, no sky, no land, no pit at the bottom, just pure random castle stone everywhere in all directions. Our plans are the following:

    Underground dungeon, troposphere, stratosphere, mesosphere, thermosphere, exosphere, then space. Where we go from there in a dungeon crawler, well, that's TBD.
     
  17. chronos78

    chronos78

    Joined:
    Dec 6, 2009
    Posts:
    154
    Thanks, it's not my first go round with Minecraft clones so that helps. My first attempts lead to a fully playable game however the structure of the code was so abysmal due to "make it playable now and design later" coding practices, that making additions became a nightmare which led to its abandonment and why this time I'm focusing on the code base first.

    Nope not locking up, crashing to the desktop. My thread manager is very stable and has been battle tested over the years. In this particular case with the millions of allocations in my stress test the problem I hit is the dreaded Fatal error in GC too many heap sections bug. Which has been a problem for years and Unity has yet to fixed it. Maybe some day when they update to a newer version of mono with a better garbage collector it will get fixed. Luckily the problem is avoidable and only seems to manifest itself when previewing in the editor and the problem goes away altogether when I use a more reasonable number of chunks and don't purposefully try to blow Unity up. ;)

    Unfortunately I'll be traveling for a few days so it's going to be about a week before I'll be able to work on the next part of this project which will be the greedy mesher. I'll post more progress shots once it's working.
     
  18. GenericGame

    GenericGame

    Joined:
    Nov 26, 2012
    Posts:
    206
    ah yes, now I understand your issue. One of the many pitfalls of 32 bit applications. I bet Unity64 would solve a lot of those issues or make them easier for the Unity team to overcome. That is an insane amount of data you have going on there.

    are you using a int64 or double or float chunk maps for the endlessness? I was thinking about going away from int32.

    ChunkPos(9223372036854775807, 9223372036854775807, 9223372036854775807)

    seems a lot more fun than

    ChunkPos(2147483647, 2147483647, 2147483647)

    I was concerned about doubling the data storage size, so I chose not to use int64 or doubles. If you are, what about in memory data, I would imagine each block would be double the 4 byte size basically instantly making the app double memory size?
     
  19. chronos78

    chronos78

    Joined:
    Dec 6, 2009
    Posts:
    154
    Using standard int32 that gives me 4,294,967,295 regions across when you factor in both the positive and negative sides of the axis. Since each region is 512 blocks across that means the world is roughly 2.2 trillion on a side. Theoretically this would give me a world volume of 1,237,940,038,708,919,522,662,809,600 blocks. I'd say that's more than big enough and since all positioning is relative, block position is relative to section position, section position relative to chunk position, and chunk position is relative to region position the only thing I even need int32 for is for the regions. Block, section, and chunk positions are all saved as bytes and I calculate world positions on the fly. This allows me to save a ton of space when saving out to disk.
     
  20. DavidWilliams

    DavidWilliams

    Joined:
    Apr 28, 2013
    Posts:
    522
    Hi guys,

    As far as I can tell this is the main thread for discussing voxel-related stuff in Unity, so I wanted to show of what I've been working on. I'm the main developer of PolyVox (perhaps you have heard of it?) and have spent some time over the last few months turning it into a plugin for Unity. It's still very early days but I'd like to show it off :)

    The video below shows the integration in action. You can drive the tank around the arena and blast holes in the walls and floor:



    There is a demo available if you read this blog post: http://www.volumesoffun.com/a-very-early-test-build-of-the-unity3d-integration-is-now-available/

    That was from a couple of weeks ago, and since then I've been working on some nicer physics (spawning physics boxes to replace destroyed voxels). No video of that yet but here's some pics:





    There is also a dedicated thread you can follow if interested in updates: http://forum.unity3d.com/threads/184599-Cubiquity-A-fast-and-powerful-voxel-plugin-for-Unity3D

    Also:
    Let me know if you have any questions!
     
    Last edited: Jun 13, 2013
  21. GenericGame

    GenericGame

    Joined:
    Nov 26, 2012
    Posts:
    206

    What is the benefit of using your closed source library over using an engine written in unity script? Are you getting better hardware access than Unity already provides or is it just for the simple fact that your engine has been tested for a couple of years so you are just hooking unity to a time tested solution?
     
  22. DavidWilliams

    DavidWilliams

    Joined:
    Apr 28, 2013
    Posts:
    522
    The expected benefits are that a native code implementation will allow:
    • Higher performance of volume processing operations (mesh extraction, resampling, etc).
    • More direct control over memory management, hopefully leading to larger worlds.
    At the moment it remains to be seen whether these benefits are really delivered because the integration is at a very early stage, but so far the results look promising.
     
  23. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    I've been following PolyVox for awhile now and I'm glad to see it making it's way to Unity. Good luck!
     
  24. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    can you give example usage of PolyVox in C# ?
     
  25. Mohamad Farid

    Mohamad Farid

    Joined:
    Jun 22, 2013
    Posts:
    5
    $sdsdsdsad.PNG Here's my game project and its 10x10 grid.But there's still buggy with the items and im trying to figure that out.
     
  26. DavidWilliams

    DavidWilliams

    Joined:
    Apr 28, 2013
    Posts:
    522
    Actually this project isn't using the PolyVox C# bindings. Instead we have a higher level library (Cubiquity) which is written in C++ and built on top of PolyVox, and then Cubiquity is loaded into Unity as a native code plugin and called through the P/Invoke API.

    But to answer your question, you're actually better off asking on our forums as the SWIG wrapper was implemented by my brother/team-mate Matt. He's done more work with Python but I think we at least have a unit test for C#. The principles are similar anyway.

    Assuming it works then I think you should be able to call PolyVox from Unity. You'll have to experiment a bit but we'll help where we can :)
     
    Last edited: Jul 7, 2013
  27. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    I'm making progress on my terrain generator. I posted about it on my facebook page, here's the link.
    https://www.facebook.com/permalink.php?story_fbid=434939293270322&id=338181696279416

    Also here's a link to the build of what I've got working so far. I'd post the webplayer version but it crashes fairly easily and I'm not sure why.
    http://www.mediafire.com/download/ej6mlwrmustj96s/InfiChunk.rar

    Left Mouse - Remove block
    Right Mouse - Set as dirt
    Mouse 4 - Set as grass
    Shift + Mouse button - Add block

    Middle Mouse - Toggle mouse lock
     
    Last edited: Jun 23, 2013
  28. Mohamad Farid

    Mohamad Farid

    Joined:
    Jun 22, 2013
    Posts:
    5
    Wow looking great!
     
  29. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    Thanks to this at 24:05


    I've learned how I can use a SerlializedObject to make database of blocks. What I'll do with that is when it comes time to generate mesh, it will tell the generator how to generate that block. So for now I can only think of two block types, a Cube and a Entity block (such as a lever, torch, door, etc.). If it's set to be a Cube it will generate the cube mesh for that block. I'm also thinking about how the greedy meshing should work. Using the information from the database, it theoretically should no longer need to know what type of block is next to it but just its material and a few other rules. Like let's say you have a dirt block such as the one in Minecraft. The top of it is grass, the sides are a grass/dirt mix and the bottom is dirt. That would mean you would need 3 materials, not just one dirt material like I've been using. So therefore you would generate greedy mesh based on the material(s) and not on the block type alone.

    To facilitate that I'll make an option for the cube style blocks to choose 6 materials, one for each side. The mesh generator will decide what to do with each material and set up submeshes automagically. Those materials should then be applied to the GameObject's MeshRenderer in the right order. If you were to use an Entity/Instance/Special block, it would completely bypass all of that and would need some sort of special Instantiation code to create the block.

    I also want to add my block deformation code in as a toggleable option for cube based blocks so that the greedy mesh generator will completely skip them and give them the standard block mesh.
     
    Last edited: Jun 29, 2013
  30. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    I know this does not apply for mobile so it is useless to me, but has anyone tried using geometry shaders to generate the mesh? I would be curious to know what performance would be like using a geometry shader vs generating the triangles on the CPU.
     
  31. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144

    Attached Files:

  32. GenericGame

    GenericGame

    Joined:
    Nov 26, 2012
    Posts:
    206

    as far as i know, the gpu shader would need to have a list of vertices BEFORE being able to process them. So you will still have to pre-process your chunk meshes prior to sending to the gpu.
     
  33. GenericGame

    GenericGame

    Joined:
    Nov 26, 2012
    Posts:
    206
    I found this great college research video from a student investigating voxel games. it's a great watch, and you can tell the guy did a lot of research. I only noticed a few things that he got wrong, but overall, it's a great view if you have the time or if you are making a voxel game of any sort.

     
  34. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    No, the geometry shader can generate vertices and triangles. What you are thinking of is Shader model 3.0 or below, that only have vertex shader and fragment shader. With direct X 11, you can have geometry shaders, which are capable of generating geometry in the gpu. It looks very possible to do the triangles we are all doing using a geometry shader.
     
  35. DavidWilliams

    DavidWilliams

    Joined:
    Apr 28, 2013
    Posts:
    522
    As far as I know there's basically two options for using the geometry shader, though I haven't tried either of them. The first is to provide the data as a 3D texture from which the geometry shader can then build the mesh entirely on the GPU. This is basically a variation of what the "Generating Complex Procedural Terrains Using the GPU" article does.

    The alternative is to perform 'surface extraction' on the CPU but just generate a single point for each cuboid. The geometry shader can then take this list of points and expand them into cuboids. It seems possible that this approach would mean storing a smaller amount data in GPU memory compared to the usual surface extraction approach, but of course there'll be other trade-offs.

    It's interesting, and there was also some discussion about it on Reddit here: http://www.reddit.com/r/VoxelGameDev/comments/1efh6l/i_made_a_video_summarizing_the_big_programming/
     
  36. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    Just found this


    It comes with the source project too!
     
    Last edited: Jun 29, 2013
  37. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
  38. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    Maybe you will be interested:

    1) block.Type == BlockType.Air (f.e air type) is 20% faster than block.IsAir()

    2) direct access to the block array in chunk in 3 times faster thank using method

    int index = /*calculate x, y, z 1d array index*/
    Block block = Chunk.Blocks[index]; is faster thank Block block = Chunk.GetBlock(int x, int y, int z) with the same code inside

    I was very surprised to hear this yesterday


    add:

    My not optimised mesh generator - 1.36ms to generate 16x64x16 block - six IsTransperent call per iteration - for checking neighbors block
    After optimisation (IsTransperent to block.Type == BlockType.Air || block.Type == Block) it took 1.1ms
     
    Last edited: Jul 1, 2013
  39. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    My game - "My World"
     
  40. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    So I've managed to get my material-based submesh grouping working.
    $1053092_439884916109093_728794336_o.jpg

    Which uses a loverly block database system that I designed myself.
    $1063733_439884852775766_3236440_o.png
     
  41. GenericGame

    GenericGame

    Joined:
    Nov 26, 2012
    Posts:
    206
    can you post a web player?
     
  42. GenericGame

    GenericGame

    Joined:
    Nov 26, 2012
    Posts:
    206
    Which uses a loverly block database system that I designed myself.
    View attachment 59107 [/QUOTE]

    this is great. I use something similar in the inspector, then save it to xml and load at game start. solves many problems and I have been able to expand on it dramatically adding all kinds of metadata to blocks. The users can now even modify the xml themselves to change what blocks have what properties.
     
  43. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    ZorNiFieD, why not use texture atlas? There will be no loss of speed at the combine of the sub meshes?


    I can't, i use several thread for worker. I can post stand alone, but only tomorrow
     
  44. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    because:
    - With multiple submeshes you can use different shaders (specular for example)
    - When you use a non-blocky type mesh generation (marching cubes), you can't really use UV coordinates and have to use a triplanar shader with a single texture (as far as I know)
     
  45. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    ZorNiFieD, how a mesh rendered component recognizes that submesh number X should use the material Y from mesh renderer material list?
     
  46. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    That's just how it works in Unity.

    Array - MeshFilter -> MeshRenderer
    0 - Submesh0 -> Material0
    1 - Submesh1 -> Material1
    2 - Submesh2 -> Material2
     
  47. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    GibTreaty, i have a giant loss of speed only on mesh building

    Before - texture atlass - 32x32 chunk, 0.7ms - average, max 8ms
    Now - 1 material\per submesh - 32x32 chunk, 20ms - average, max 26ms

    think the loss on the memory allocation
     
    Last edited: Jul 5, 2013
  48. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    Hello, i have some errors with texture

    Erorrs:
    $texture_bug.JPG

    Texture (grass and stone) settings
    $stone_texture_settings.JPG $grass_texture_settings.JPG
     
  49. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    Those are pixel bleeding problems, it has been discussed several times earlier in this thread (just take your time to look through all the pages ;) )
    It's not really something you can overcome with a texture atlas, but there are some ways to reduce it's obviousness.

    That by the way, is another advantage of using triplanar texturing with seperate textures and submeshes, compared to texture atlases
     
  50. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    I want to optimize mesh builder by keeping all blocks in one array. But i really don't know how to translate world block coord ((ChunkBlockWidth*Chunk.X + x), (ChunkBlockWidth*Chunk.Z) + z) into array index.
    The slowest point is getting chunk from chunk collector, when we need to look up some information (block type) during the building of the mesh
     
Thread Status:
Not open for further replies.