TerraVol v2

DOCUMENTATION


This documentation will be updated over the time. Remember to check it sometimes for new tips & info.

If you encounter any problem using TerraVol, if you find a bug, or anything else, please do not hesitate to contact me at terravol.unity@gmail.com


What is TerraVol?

What is a voxel/volumetric terrain?

Why do you need TerraVol?

Main features:

In-Editor Builder Tool features:

What do you get when you buy TerraVol?

Feedback and requests

Getting started

Understanding the basics

How to use TerraVol in your existing project?

Setting-up parameters

TerraMap parameters

TerraMapGenerator parameters

BlockSet parameters

In-Editor Builder Tool

Save and load your terrain

Edit the terrain in your scripts

Typical examples of actions

Customizing TerraVol without modifying the source code

Using RTP3 with TerraVol

Making biomes

Define areas for your biomes

Adding the new blocks

Making transitions between biomes

Frequently asked questions

How do I resize the terrain?

Can I change the size of digging/building brush?

Can I change the speed of digging/building?

Does TerraVol support multiple materials on a single terrain?

Where can I find better shaders for terrain texturing?

Can I use normal mapping on the terrain?

Is there any API reference?



What is TerraVol?

TerraVol is a voxel terrain engine made with and for Unity 3d. It handles real time creation & modification of true volumetric terrains using voxel data and Marching Cube algorithm.

It also comes with a simple Editor Tool directly integrated inside Unity’s editor and allows you to edit your terrains in the scene view.

What is a voxel/volumetric terrain?

Unlike standard terrains in Unity (and in most video games), voxel/volumetric terrains allow the creation of holes, caves, overhanging cliffs, etc. This means that terrain geometry isn't defined by a height map but is instead stored in a more complex 3D structure.

Possibilities offered by a true volumetric terrain are fabulous and will make your game even more enjoyable for the players. This is the future of terrains in video games.

You probably know Minecraft. Minecraft uses a basic and simple kind of voxel terrain. Everything is made with cubes, but still, you can create caves, dig holes, generate material, etc. TerraVol allows you to do the same thing in a realistic world. In other words, TerraVol gives you the power of Minecraft with the graphic quality of a standard terrain.

Why do you need TerraVol?

Simple: to make your game better!

More seriously, it will depend on your needs. Some kind of games won't require TerraVol at all… But a lot of them will! To give you a better idea of what you could do with TerraVol, see the list of its features below.

Main features:

In-Editor Builder Tool features:

What do you get when you buy TerraVol?

Feedback and requests

If you find a bug, if you think something is missing, or want to give some feedback, please do not hesitate to contact me.

I will continue to update, fix, and improve TerraVol, and free updates will be provided through the Asset Store. You will pay only once!

Also, please tell me if anything is missing in the documentation.

You can contact me at: terravol.unity@gmail.com

If you appreciate the product and want to support it, I would be extremely thankful if you rate TerraVol on the Asset Store and maybe write a comment. This will definitely help. Thank you in advance!

Getting started

It is strongly recommended to get a look to the example scenes given with TerraVol. It contains all stuff needed to start using TerraVol and can make a good starting point for a new project.

One scene contains the editor builder tool while the other one will be prefered to make purely procedurally generated worlds.

Understanding the basics

You won’t need to know a lot of things to work with TerraVol, but you should know this:

How to use TerraVol in your existing project?

If you want to integrate TerraVol in an existing project/scene, follow these instructions:

  1. Create a GameObject in your scene (GameObject -> Create empty) and name it “BlockSet”.
  2. Select the previously created game object and add the BlockSet component to it (Add Component -> TerraVol -> BlockSet).
  3. Inside the BlockSet component, add a Block named “Default” with a material index of 0 and add a material to the “materials” array (see Using BlockSet component section).
  4. Create another GameObject in your scene (GameObject -> Create empty) and name it “Map”.
  5. Select the previously created game object (Map) and add the Terra Map Generator component (Add Component -> TerraVol -> Map Generator) and the Map component (Add Component -> TerraVol -> Map).
  6. The Map component should be already populated with working values. You will see later how these values can be modified to do exactly what you want.
  7. Now select your BlockSet object and drag it to the “Block Set” property of the TerraMap component.
  8. Select the player’s camera and drag it to the “Player Camera” property of the TerraMapGenerator component.
  9. If you want the player to be able to edit the terrain in real-time, add the In-Game Builder Tool component to it (Add Component -> TerraVol -> In-Game Builder Tool).
  10. That’s all. Press play and see the magic!
  11. Wait… you may also want to edit your terrain inside the Unity editor! To be able to do that, you have to add the Terra Builder component to your Map object (Add Component -> TerraVol -> In-Editor Builder Tool).
  12. Now you are ready to use the power of TerraVol directly inside the editor.

Setting-up parameters

TerraMap parameters

TerraMapGenerator parameters

BlockSet parameters

Block Set  gives you control over terrain texturing.

Blocks array contains all type of blocks (ie. voxels) you want to use in your terrain:

Materials array contains all materials you want to use on your terrain. The property “material index” of blocks refers to the index of the material in this array.

In-Editor Builder Tool

TerraVol allows to model and texture voxel terrains directly inside the editor. The Terra Builder component is the component that makes it possible. To use it, just add it to your Map game object (i.e. the object on which you added the TerraMap component).

This tool is very simple to use. You have only a few parameters that make it possible to sculpt the terrain and paint textures on the ground.

Here is a description of each parameter:

Save and load your terrain

TerraVol Maps can be saved & loaded through files. It uses a very fast serialization technology.

You will need to save Unity’s scene separately. To save your map, use map.Save(string path) method where path is the full path of the file (name included) where you want to save it. To load your map, use map.Load(string path) method where path is the full path of the file (name included) from which you want to load it.

With the in-editor tool, you can save the terrain thanks to the “Save Map” button.

Edit the terrain in your scripts

You may want to let your player edit the terrain and so, you would like to know how to edit it from scripts.

To see the full API documentation, see http://terravol.com/api_v2/

This is actually extremely simple. Any modification must be done through the “action system”, using WorldRecorder.Instance.PerformAction(new ActionData( ….. )).

ActionData represents an action performed on the terrain. Its constructor takes several parameters:

Typical examples of actions

You should get a look to the Builder.cs script. This is a very good starting point to start using TerraVol in your scripts.

Here is an example of how you could dig into the ground:

WorldRecorder.Instance.PerformAction(new ActionData(Chunk.ToTerraVolPosition(position), radius * Vector3.one, block, ActionDataType.Dig, BrushType.Sphere));

Customizing TerraVol without modifying the source code

TerraVolEnhance script is made for that. You can do a lot only by modifying this script.

See API Reference for more information.

Using RTP3 with TerraVol

If you find that TerraVol’s default shader isn’t advanced enough, and want to obtain better looking terrain with parallax mapping and other nice things, you can use RTP3 (you will find it on the Asset Store).

This is extremely easy to use it with TerraVol. Follow these steps:

  1. Open the file ReliefTerrainVertexBlendTriplanar.shader and comment the line #define LOCAL_SPACE_UV
  2. Replace the terrain material in the BlockSet component by the one you will find in ReliefPack/Shaders/ReliefTerrain/VertexControl
  3. Open Chunk.cs and uncomment the line #define TERRAVOL_RTP3
  4. You will probably have to change the vertex color of your blocks in the BlockSet component because RTP3 map it differently. For example, ‘Default’ block should be red (with alpha value equals to 0).
  5. That’s all.

Making biomes

TerraVol allows to use multiple materials on a same terrain thanks to the BlockSet component. This feature makes possible to have different biomes on a map.

This tutorial will show you how to define biome areas and how to make a soft and nice transition between them.

Define areas for your biomes

You will have to make your own "region" system to handle the creation of biomes. This can be either very simple or very complex depending on your needs. This section gives a basic example, but once you'll have read it you'll be able to make your own region system to fit your needs.

The best way to do that is to customize TerraVolEnhance script. We are going to see how you can define two different regions thanks to the OnBlockGenerateBeforeInThread method.

This method allows you to tell TerraVol which type of block to use depending on its position.

To keep it simple, we will define two regions like this:

  1. all blocks which have an x coordinate below 50 will be in the region n°1
  2. all blocks which have an x coordinate above 50 will be in the region n°2

So we're going to have a straight border between our regions. This is a bit basic but it gives you the idea. If you want to make it more sophisticated, you could use a splatmap for example, but it won't be explained here as it is another topic.

To make our regions defined above, we're now going to implement the OnBlockGenerateBefore method like this:

if (position.x > 50)

return "WinterDefault"; // WinterDefault block will be used

else

return null: // Default block will be used

Adding the new blocks

The second thing to do is to add a "WinterDefault" block to our BlockSet.

First, create a new terrain material and set a snow texture instead of a grass texture.

Then, select the BlockSet object of your scene and add a new material to the materials array. Drag & drop the previously created material to the second index of the array.

Finally, add a new block to the blocks array. Name it "WinterDefault", change the color to black (and no Alpha), and set its material index to the index of the material you've just added before (ie. 1)

.

Here we go. If you press play you should see the two biomes (grass/snow) on your terrain.

Making transitions between biomes

Currently, there is no transition between our biomes and it's really ugly.

Let's see how to handle it.

The best way is to share a same texture between the two materials.

Select your first material and add a half-snow half-grass texture on the green channel.

Select your second material and add the same texture on the green channel too.

Create a new type of block, name it "Transition", set the material index to your first material and the vertex color to green.

Create a new type of block, name it "WinterTransition", set the material index to your second material and the vertex color to green.

Now, modify the OnBlockGenerateBefore method like this:

if (position.x > 60)

return "WinterDefault"; // WinterDefault block will be used

else if (position.x > 50)

return "WinterDefaultTransition"; // WinterDefaultTransition block will be used

else if (position.x > 40)

return "Transition"; // Transition block will be used

else

return null: // Default block will be used

Done! You should now have a smooth transition between your biomes.

Frequently asked questions

How do I resize the terrain?

Terrain can be resize thanks to the Map parameters. Do not use scale property of the Map object. For more details, you should get a look to the “Setting Map parameters” section, it will tell you exactly what parameters you need to modify.

Can I change the size of digging/building brush?

Sure you can! See “Edit the terrain in your scripts” section for more information.

Can I change the speed of digging/building?

Again, you can! See “Edit the terrain in your scripts” section for more information.

Does TerraVol support multiple materials on a single terrain?

Yes! Thanks to the materials array of the BlockSet component, you can use as many materials as you want with your terrain. See “BlockSet parameters” for more details.

Where can I find better shaders for terrain texturing?

On the Asset Store. There are some very good terrain shaders. I strongly recommend RTP3 (see “Using RTP3 with TerraVol” section).

Can I use normal mapping on the terrain?

Yes but you will have to buy a better shader on the Asset Store or make on by yourself. I strongly recommend RTP3 (see “Using RTP3 with TerraVol” section).

Is there any API reference?

Yes, right there: http://terravol.com/api_v2/