Skip to content

BloodyFish/UnityVoxelEngine

UnityVoxelEngine

Image

👏 Special Thanks

Threading made possible because of Logyrac

💻 Project Uses:

  • 📈 Kickstart any voxel project for Unity
  • 📖 Learn how voxel-based games work
  • 📝 Contribute your voxel knowledge

🤔 Setting it up

There a couple of things you need to set up before a voxel world is created:

  1. Create an empty Game Object. You can call it anything, but something like GenerationManager can help with organization
  2. Add the Generation script to the empty object
  3. Set up the Block List, Contintalness To Height spline, Terrain Material, specify whether or not you want to Use Greedy Meshing (it is recommended), and then add the Main Block, Underwater Block, Stone Block , and Dirt Block
    • The terrain material, TerrainMat is in the Shaders folder
  4. (Optional) Input whatever you want for your seed in the Input Seed field! This can be a int or a string. A float will be converted to a string.
    • If left blank, a random seed will be generated
  5. Create an empty Game Object. You can call it anything, but something like AsyncHelper can help with organization
  6. Add the AsyncHelper script to the empty object (Assets > Voxels > Scripts > Dispactcher)

📋 Setting up a Block List

In the Blocks folder, right click, Create > VoxelStuff > BlockList you can name it whatever you like (Recommended: BlockList)
Now you can add block types to the Blocks field in the block list!

📋 Creating different Block types

In the Blocks folder, right click, Create > VoxelStuff > Block you can name it whatever you like (Recommended: BlockName)
As of right now, there is only one field: Vertex Color. This is the color the voxel will appear in the world

  • Create a GrassBlock, SandBlock, StoneBlock, and DirtBlock. Make sure to place these in the coresponding fields in the Generation inspector

📈 Setting up a Continentalness to Height spline (basis for terrain generation)

Fun fact: this method of generating terrain is inspired by the Minecraft way of generating terrain!
This entire project was inspired by the following talk by Minecraft developer Henrik Kniberg:
Reinventing Minecraft world generation by Henrik Kniberg

In your GenerationManager (or the object in which you placed the Generation script), you can manipulate the Contintalness To Height spline to represent how terrain height will respond to "contintalness" (the perlin noise values)

  • The spline has x-values going from 0-10, and y-values going from 0-1 (during generation, it becomes 0-100)
  • Imagine the x-value of 0 as the bottom of the ocean
  • y = 20 is coastline

In the Spline script (Assets > Voxels > Scripts) you can edit the "step" of the spline. A smaller spline value means smoother terrain. If you don't like the default look of the terrain changing height by gradually "stepping," you can change the line private const float STEP = 0.1f; to be below the default value of 0.1f.

Below is a good example for a Contentalness to Height spline:

Image

As you can see, we have flat values from x = 0 to x = ~4.9 representing the ocean floor. The sharp increase in height from x = ~4.9 to x = 5 is the transition to coast.