Search Unity

Community Driven voxel terrain engine(All New version)

Discussion in 'Works In Progress - Archive' started by dudester, Sep 22, 2015.

  1. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    Hello all this is the new and improved version of my voxel engine.



    thanks for reading hope to hear from you guys and girls soon.

    regards Dudster.
    Feature Requests:
    in Editor terrain creation of static size:Will do research into this .
    in Editor editing of terrain:Working On it right now!
    Level Of Detail system: being worked on .
    Bugs Fixed:
    Null reference exceptions relating to no grass or trees in the inspector .
    Array length errors with regards to above and in regards to chunks array being to small etc.
    Null reference exceptions when there is no windzone attached to terrain inspector ( now throws error saying there is no windzone detected will attempt to find one in the scene).
    many other null reference exceptions fixed.

    features:
    set the terrain voxel size(min lod size) to a number from 1 to 9 in the inspector .
    assign textures directly from the inspector (normal maps and textures ) up to 4 support currently.
    runtime editing of terrain with saving and loading .
    infinite in the x and z coordinates .
    supports trees and grass on terrain using built in features.
    weighting of grass on terrain, can set different weights for grass so some grass appears more on terrain then others , working on a feature where you can set different weights for different textures.

    I've also fixed numerous bugs , although there's still the occasional array length error , kinda hard to track this one down as i do all the necessary checks , but as far as i can tell the error is fixed .

    Link to new version:
    https://drive.google.com/file/d/0B3IMm5D_EAKOeDVWUml0RTJuZU0/view?usp=sharing
     
    Last edited: Feb 9, 2016
    mgear likes this.
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Got a link to a git repo? I've done some infinite terrain stuff before, with the Unity terrain stuff. I'm curious to see what you've done.
     
  3. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    hi thanks for your interest , id like to get more feedback from the community before sharing any files , ill be sure to send a link once ive got some interest .

    its good to know theres some interest thanks , will keep you in mind if theres no more interest maybe we can work together to make something.
     
  4. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    Seems interesting man. Keep at it. There is always room for improvement with the Unity terrain stuff.
    Heck the day someone can make a REAL TUNNEL system with caves and CLIFFS. is the day the Terrain system has left the days of old tech to the future.

    I understand the whole heightmap based terrain system. But somethings gotta give. ANd perhaps I might make a new terrain system now sense this lol.

    But I'd be interested and following more in what you're making!
     
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Fair enough. Let me know when you are willing to share. I'm not interested in downloading files, that is typically a sign of an amateur project doomed to fail. But let me clone your repo and I might just send a couple of pull requests your way.
     
    Ryiah likes this.
  6. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    fair enough @BoredMormon , i just haven't got around to using all those features yet , ill get right on that though , @N1warhead well my current system can make tunnels and caves and cliffs , any terrain you can think of even spherical terrains if you know the math for it you can use it in this system , its just not as optimized as id like and its a bit of a memory hog , but other then that it works fine so long as you dont mind the 1000 view distance limit , although if you would like to go higher like say 8000 then you need 8gb of ram for that distance the system can handle it easily so long as you have the memory for it.

    Edit: Going to upload a video of the terrain in action so people can get a feel for how it runs
     
  7. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    Oh nice.
    Well, do like that one video game called Fuel did. It's like a real life 900 square mile level.
    In reality no computer on earth except maybe the NSA could handle that. So make it where users can create a terrain, do what they want to do with that terrain, then let them technically *Prefab* it, so it can be loaded and unloaded later at another time. That's how Fuel did it. And it worked wonders.But it's just making it all piece together that's hard lol.
     
  8. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    well this terrain doesnt do prefabs its all procedural(made on the fly) , and you could technically travel as far as you wanted , terrain in the distance is unloaded , and new terrains spawn in so its completly infinite , although ive only gone to about 15000 units from origin (the floating point inaccuracy was to bad to continue ) im sure you can go forever . but i like the idea of prefabbing it although its gonna be quite tricky.
     
    Last edited: Sep 22, 2015
  9. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    That's what I was trying to say, make the terrains a default size on creation, however. Make each terrain randomly generate a perlin noise to make whatever they want, but make it *learn* the outside area to match the vertices on the edges of other terrains, and to either make the mountain or make a dip and go down.

    It would be tricky, but idk, seems even more than what I'd want to even try and make on my own.
    But yeah, I even confused my self with what I just put above this, so I may be out there with what I said lol.
     
  10. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    yeah no lol , i got what you were saying , this terrain does exactly that , its kinda like minecraft but smooth,
     
  11. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    Yeah, the only reason I mentioned prefabbing it all, is because then it's already procreated, meaning less calculations.
    However, make it where there is an editor version and an in-game version.

    The editor version will allow users to either create or generate terrains or both, make a save button, prefabs it into some folder, and allow the user to create/generate on the fly. Then have the in-game version that will place these terrains in the proper places, but have the only calculations messing with the outter edges to properly fit the surrounding terrains.
     
  12. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    thats a good idea, like a non infinite one in editor and then an infinite one with noise , i already have saving to a file done so creating it in editor should be easy might need some help with it though as its quite a bit of work and im not very good with editor stuff but i can learn it ,
     
  13. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    Yeap yeap non-infinite in editor, that way you can create the pieces or generate the pieces to your liking, then when it game, make it pick one at random as it comes time to create it, then just figure out how to make them match, that's the hardest part. Don't want a cliff that's 600 meters high with a dip in the middle that goes back down to 0 lol.
     
  14. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    well i wouldnt really pick one at random id probably load them in order so that they match doing it randomly would be difficult as like you say they wont quite line up right , but i like the idea ill start learning about editor code .
    heres the video its very laggy (slow proccessor) .
     
  15. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    Oh nice, looks good!
     
  16. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Maybe this can still be used for the top-most layer? Or maybe you can have several heightmaps and the one you use is based on your xyz position?
     
  17. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    That is true.
     
  18. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    @N1warhead thanks it was really laggy but usually i get around 30fps.
    heightmaps are good in a way , for normal terrains that dont need overhangs or caves , most fps games dont need stuff like that , but games are changing and so should terrains , voxel terrains are the future , its just most popular game engines havent been working on them , if they did it would be brilliant , even though unity terrain gets called bad and all that , its actually really good it uses virtually no memory and its highly optimized , if unity could create a voxel terrain imagine how nice itd be.
     
  19. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    If you ask me, tunnels and stuff should be necessary, I can't count how many times I've seen games with caves, cliffs, etc. I shouldn't have to 3d model and hide vertices in the terrain to make a tunnel work.. If you ask me, tunnels, etc are a very big thing for terrains. I've just never had the patients to make a new terrain system. Even though I know it would be worth it.
     
  20. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
  21. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    Oh I've seen them all, but all of them lack something in which is important. Whether that be good documentation, a feature, performance, etc. The only true way to get one worth having is if Unity does it that way it's hardcoded into Unity with all the special stuff we can't have.
     
  22. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    agreed unity would make it best , fully intergrated fully featured with all the optimizations you can think of , just a pitty that they focusing so much on graphics and not on creating new features . perhaps we should start a thread with a feature request and a poll to see how many people actually would need such a feature , maybe if we get enough people together unity would consider it more of a necessity.
     
    N1warhead likes this.
  23. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    I've also noticed some things seem to perform unusually well when the engine handles more. Like sphere casting in unreal or using triggers in unity.
     
  24. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    I've never used Unreal, well that's a lie, I downloaded it, got to the menu and deleted it haha. So I can't really speak for Unreal or anything.

    I do love triggers and stuff though.
    But I would assume though that terrain would be something better suited for the engine its self handles better when it's hard-coded into it with all their fancy optimizations we don't get.

    But I could be wrong.
     
    theANMATOR2b likes this.
  25. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    well C++ will do that , thats why unity can have a terrain size of like 32000 units all loaded at once c++ memory management is amazing.
     
    Tomnnn likes this.
  26. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Sounds like UE4's journey on my work computer. It ran at like 3fps while unity ran fine.

    So maybe terrain in the future, if not done by UT, should be done as a plugin with some C++ stuff?
     
  27. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    Haha, I just didn't feel like figuring out how to get things going.

    I love Unity for the sake it gets you right where you need to go.

    (Project Menu > In Engine).

    Unreal > (Download Installer > Open Unreal > Download Engine > Download Help Files > Hard to Start > Loads > No good UI).
     
  28. PandawanFr

    PandawanFr

    Joined:
    Nov 27, 2013
    Posts:
    68
    I think this is a great idea, not only because this is community driven meaning anyone can improve it and make custom versions of it (variants). But also because I'm pretty sure a lot of people are searching for that kind of thing, I used to work on a project like that and was searching for a way to make random terrain generation that would have been voxel based but I couldn't find one. Anyways, I think you should do it!


    [Edit] Forgot to mention, I was later able to find a tutorial to make voxel based terrains, but they were only cubic terrains (like Minecraft) which can be useful for some games, but not all.
     
  29. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    good to see some responses here , im going to start adding comments to the code as well as write a short bit of documentation so users can understand the code as well as set up a git hub repository , once thats all done ill post a link to it
     
    Kiwasi and N1warhead like this.
  30. HeadClot88

    HeadClot88

    Joined:
    Jul 3, 2012
    Posts:
    736
    @dudester - I would be interested in a open source voxel engine. :)

    Mostly in making some contributions and some advisory :)
     
    PandawanFr likes this.
  31. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    ok code is now commented but if you have any questions as to what does what just ask ,i know the code well as i created most of it , not all though , @scrawk also created a good chunk of the code , im busy creating a github repo right now , just waiting for the download and then gonna watch a few tutorials on how to set it all up , then ill post a link,
    also @HeadClot88 thanks hopefully we can make this voxel engine great and have something for the community to use , i know there are lots of voxel terrains on the assetstore but they are quite expensive and most dont have all the features we need.
     
    Last edited: Sep 24, 2015
  32. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    @PandawanFr thanks for the interest , i agree it is sorely needed , the only downside to this terrain is that its marching cubes and can only be smooth , cubic style could be made i guess with the same engine , thats up to the community to add if they want it and can implement it , theres also a marching tetrahedra version although i dont think it works anymore , i could add it to the terrain engine as an option , it creates alot of unnecessary triangles though .
     
  33. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    Update:link removed.
     
    Last edited: Oct 4, 2015
  34. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    also if you all could all let me know how the performance is with grass and trees ,
    as my system is quite old id like to know how modern hardware performs .
    Also just a note to remember grass meshes must be in scene to work , its part of an optimization so that the meshes batch properly.thats all thanks.
     
  35. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    It would be cool, if aside generating terrain on the fly, you could sculpt pre-determined terrain and make it in enclosed space, like with Unity's one.

    As for other things, Dual Counturing would be good to have, as DC allows for both "sharp" (e.g. Minceraft's blocks) and smooth voxels and anything in between. AFAIK this is what VoxelFarm and Blockscape are using.
     
  36. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    it would be fairly trivial to implement such a system , ive never made an editor script before , only normal [executeInEditor] stuff , so doing that would be super easy , although i dont know how threads react to running in editor , and saving is already implemented , i could throw something together might take a day or 2 .
    dual contouring is interesting but i havent been able to figure out how it works and how to implement it in unity.
     
  37. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Awesome! Too bad doing DC isn't as easy.

    Is there any way to increase voxel resolution of the terrain (e.g. instead of 1x1x1m blocks like in Minecraft blocks that are 25x25x25cm)
     
  38. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    no not at the moment you could scale the parent transform down thatd decrease the distance between the voxels, havent tested it if you find any errors let me know , ill fix it up.
    Edit: the above doesn't work seems you have to offset the position based on scale ill keep working on it i think i have a solution.

    Id like to implement a lod system but so far , i have no idea how to go about adding it to the current system , what id like to create is an occlusion culling system in the engine , ive found that not drawing stuff behind other meshes greatly reduces the amount of triangles .

    but that being said at 1000 view distance the framerate is fine , although loading is slow so its hard to know .
     
    Last edited: Sep 25, 2015
  39. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So I think this is a very cool idea and useful. Not to nitpick, but my OCD wouldn't even let me contribute to this right now. Code mixed with other assets, no namespacing, some stuff is camel cased correctly other stuff not. Line widths need to be appropriate for git. And if you include dll's in an open source project at a minimum you need to say where they came from. I also don't see a license attached to this?


    My thought on this is that what's most useful is the voxel engine itself. There are a lot of uses for that outside of being a terrain replacement. And it's a pretty high bar to meet before it can viably replace standard unity terrain. Does it work with RTP? Why would I give up terrain composer to use this? That's what people making real games are going to be asking.

    And procedural generation is cool and all but not that useful in the majority of cases.

    My conclusion on voxel terrains after working on a fairly large complicated dynamic world building tool is that you don't need voxels for everything. And you often need voxels for things other then the terrain. Being able to use voxels when and where you want them, alongside standard unity terrain, is IMO a huge win.

    So regarding your resource limitations. On my system I'm using a very ghetto voxel system, I just need to dig underground not use voxels for everything, so I just use standard cubes actually. I handled the performance issue by building a system that combines meshes, and can combine/uncombine on the fly and on demand. For my use case I need stuff near the player to be uncombined because it's destructable. I use a spatial grid to manage that part. I was thinking about open sourcing this system anyways. It's smart enough to group materials and stuff.

    Even for a more traditional voxel approach I think mesh combining makes sense. What I did was with the spatial grid I can break up the world into chunks of a user definable size. How many meshes per chunk is dependent on the vertice count and number of materials being used. Each chunk can only have a single material, and the vertices per mesh limit built into unity limit you also. But for example with 100k cubes on my system that gets combined into no more then a dozen combined meshes. The vertice counts are still high which is bad but it lets the rendering system be much more efficient.

    One thing I haven't done yet is to optimize the chunks by removing vertices not necessary for rendering on the combined meshes. That's completely doable and would make a big impact.
     
    Ryiah likes this.
  40. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    Its good to nit pick , lets me know the small things i can do to fix it up so thanks , sorry if i didnt quite get the just of what you saying but , there is a namespace on the terrain its called VoxelEngine and should be included at the top by saying using VoxelEngine .

    Im not sure what camel cased means could you elaborate?
    Line widths ? sorry im still quite new to coding so all these things i havent read before .

    EDIT:Ill get right on neatening the code up so its easier to read and add camel Casing asap.

    As far as i understand the DLL included is an opensource implementation of Simplex Noise which i got from quixel voxel terrain engine .

    I agree but many people have already implemented voxel stuff for mesh creation such as buildings and models etc .
    this is just for terrain and something the community can help make awesome , if they dont want to help thats perfectly fine ,
    but i thought itd be nice to atleast have some sort of starting point for making a voxel terrain .

    Hope this isnt coming off as bad cause its not intended that way.

    If you could point me to where ive made some mistakes besides those listed above id be very grateful as im still learning , i started coding in unity so been at it for under a year .

    also i wasnt sure which licence to choose?

    wanted an opensource licence but couldnt find it under the licences of github .

    Sounds interesting Id llike to take a look at it , if you do share it do let me know itd be educational to me .
    my Terrain is made up of chunks as well which can be defined by the user .

    i tried to create a multilayer chunk system that was infinite but failed so i used a double key dictionary for the x and z coords to store the chunks .

    this is exactly why i wanted to post this on here so i could figure out where i went wrong and where improvments could be made as well as give the comunity something to work on.

    Thanks for your response.
     
    Last edited: Sep 25, 2015
  41. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    When you create a repo they give you a drop down to select a license. They also have this great little site for choosing a license and then you can just copy the one you want and add it to your repo.

    http://choosealicense.com/

    Personally I normally use MIT or Apache2 for my projects. GPL is bad for code that will be used in a game client, basically making it unusable in any published game. GPL is OK for server side stuff, but so many people misunderstand it that you will have a lot of people not use your software if it's GPL, even though half the time they are flat wrong on their reasoning.


    I'll put my chunking stuff up on github as soon as I can get the time. It's mostly self contained but still a couple of application specific pieces in it I need to take out.

    Ya some of your code had namespaces some didn't. The reason following coding standards is import in a team/open source setting is that if everyone is doing it differently it just causes constant merge issues and plays havoc with your IDE. Line widths are important on github and most everyone uses 80 columns. That's so you can actually read the code on github and it doesn't go out of the margins.

    Again Kudos for putting this out there. Regardless of my 'nitpicking' I love to see more game related open source stuff going out.
     
  42. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    Thanks for the tips .
    im busy re-organising the code now making it neater and more rreadable as well as ensuring the line width is no more then 80 columns .

    never even knew you could read code on github.

    Yes i was going to use Gpl glad i didnt .

    Ill change the files so it inludes the licence and a Readme which explains each file and its functions and where i got some of it from ill add namespaces to all files, as an asside i completly forgot to include namespaces on the double key dictionary and all that , ill be sure to do that .

    Again thanks for the tips.
     
    HeadClot88 likes this.
  43. PandawanFr

    PandawanFr

    Joined:
    Nov 27, 2013
    Posts:
    68
  44. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    the other github repo was a mistake thought i deleted it but apparently not , im almost done with the documentation as well as fixing up the code , ill update once done.
     
  45. PandawanFr

    PandawanFr

    Joined:
    Nov 27, 2013
    Posts:
    68
    Will you post the documentation in the Wiki tab of the GitHub? Or put it as a Readme?
     
  46. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    readme but i can also post it on the wiki
     
  47. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    GitHub Update : Added Camel Casing as well as neatened up the code.
    create a readme of sorts only 50% done with it , ill add more later on .
    adding licence now file now.Edit:Added license to github.
     
    Last edited: Sep 28, 2015
  48. PandawanFr

    PandawanFr

    Joined:
    Nov 27, 2013
    Posts:
    68
    Weird, it doesn't show any new commits on GitHub... Are you sure you uploaded and synced your project?
     
  49. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    go to the development branch , cant seem to update the main branch for some reason ill keep trying , anyone have any idea how to do it?
     
  50. dudester

    dudester

    Joined:
    Oct 25, 2014
    Posts:
    371
    Sorry for the long delay , been busy with school and life , ill be continuing my work on the scripts neatening them up as well as completing the manual / readme , hope to hear from you all soon to let me know how its all going .