Tweaking Unity 3D and Its Plugins for The Procedural Generation in Light Trail Rush

Nabi
B2Expand
Published in
5 min readJun 27, 2019

As we are making Light Trail Rush, the programming team faced many technical challenges. Jonathan, Unity developer, in charge of the procedurally generated environment, looked into Voxel technology, as it allows an easy terrain generation and editing in real time during a game.

Keep reading this first article of a series; we’d like to share with the community on how Jonathan solved the problem of procedural generation of the environment for the arena.

Creating an Arena from Scratch for Light Trail Rush

When we started working on Light Trail Rush, we first imagined space ships racing inside a spherical arena, featuring two cities: the bottom part facing the upper part. Like so:

First sketch

We set out to create cities using building sets at each new game, to avoid the monotony of playing in the same arena. Procedural generation algorithm was the solution. The first version of the algorithm was a 2D grid :

Building set blockouts
Building on 2D grid

Creating the Base Support to the City

1. Searching for the perfect tool

We had a starting point for the arena, but a basic structure to support and anchor the city on top of it was necessary. We worked on the multiplayer network side of the game. In the meantime, the game designer created a whole arena and defined the needed implementation for a first playable version of the game.

Handmade arena

For the procedural part, I looked into ways of generating the asteroid where the city would sit upon. The Unity Asset Store provided many solutions. However, while browsing multiple forums online, my attention was drawn to Voxeland: a user had made a whole planet. It couldn’t be that hard to create asteroids if someone made a whole planet!

Source: Unity forum

2. Tweaking Voxeland and Creating an in-house Generator

Voxeland’s core program uses heightmaps with noises to create realistic landscapes.

The plugin uses a custom 3D matrix to assign a byte for each block type needed for lands. Then, the matrix is used with wrappers to generate meshes and vertices data that Voxeland’s custom shader decrypts. It will finally apply textures blending from a block type to another.

The tool is great at generating mountains and hills, fulfilling its main purpose. It’s possible to edit the terrain while the game is being played, however, the generator doesn’t allow the cavity creation.

Considering the “floating” nature of an asteroid, it is impossible for the generator to render properly all the shapes and forms of the object. The Voxeland generator isn’t so apt at dealing with vertical layers.

So, I bypassed the original usage intent of Voxeland generator.

I reused Voxeland 3D matrix which is inputted into the plugin to create our own generator.

First, I combined 3D matrix coordinates with a Perlin noise to define the zones with the matter and those without. With settings set on the lower end, it would generate a core shape (basic structure) of an asteroid which needed more work on the external shape.

From there, to generate ellipsoidal asteroids, I added a distance restriction from the centre of the matrix to its extends.

I had a fractal noise on top of the Perlin which gave a less smooth surface on the asteroid: it looked more like a rock than an egg.

Texture tiling was too visible, thus I tried Voxeland’s built-in shader to get a close/far blending. Unfortunately, due to performance issues, I had to look into an alternative solution. I explored Voxeland mesh generation scripts and found texture encryptions for each terrain type.

In the plugin, the encryptions embedded in vertex tangent are decrypted into the shader used for the land. From there, I transferred the decryption into a new Amplify Shader Editor script. I used the decryption output with an Amplify triplanar node and a multiplication between close and far textures. The farther texture would have a subtle tiling and the closer texture of the land would render a more detailed look as we got closer.

The main challenge for the Amplify Shader Editor was to create a custom Amplify node in order to retrieve the vertex tangent data without Amplify altering it. This was necessary to avoid weird-looking artefacts all over the surface.

Asteroid generation

Why you too should do it

To sum up, you should definitely go for it if you are looking into procedural generation for your environment. Here’s why:

  • It’s very pleasant to explore the Voxel technology, I’ve always been always fascinated by its use in 7 days to die, No man’s sky, Minecraft, Terraria…
  • It’s an exciting challenge for any developer, it’s fun to create from scratch and see how it evolves in time.
  • It makes you work closely with your team members.
  • It opens up many options to play with for the game designer.
  • The artistic team loves you as they save a lot of time avoiding 3D modelisation.
  • It’s also extremely rewarding to see your algorithm rendering great results artistically.

So, why did we do all that you’ll ask? Well, first we needed an asteroid to base support the city. We can now finally place upon the floating asteroid the huge city.

Next week, find here our second episode about the city generation. We’ll further explore how we coded the algorithm so the result would look most natural and realistic.

For further research:

Voxeland forum : https://forum.unity.com/threads/voxeland-voxel-terrain-tool.187741/

Unity Store for Voxeland : https://assetstore.unity.com/packages/tools/terrain/voxeland-9180

Light Trail Rush is a PC game currently into six months of production by B2Expand studio.

--

--