top of page

Terrain Generation

  • Writer: Lewis Bailey
    Lewis Bailey
  • Feb 12, 2024
  • 6 min read

Required Packages

Universal Render Pipeline (Available from the Package Manager)


How To Use


Main Scripts


Map Preview

This generates a preview of what the world would look like. Useful for debugging what a world would look like when changing settings.


Texture Renderer

This is just a Plane that is used to preview the noise texture and fall off texture.


Mesh Filter

This is just a GameObject with a mesh filter and mesh renderer that allows you to preview what the mesh will look like. Useful for debugging what the land will look like without needing to play the game.


Mesh Renderer

This is the same GameObject mentioned in the Mesh Filter as this will allow you to apply a material to the mesh being rendered.


Draw Mode

This just allows you to change what mode you have the preview on.

  • Noise Map - Renders a preview of the noise map on the Texture Renderer

  • Draw Mesh - Creates a preview of the mesh with the Terrain Material so you can see what the mesh/land will look like.

  • Fall Off Map - Renders a preview of the fall off map. Useful to see how large the area is thats creating islands.


Mesh Settings

This holds a reference to a scriptable object of type Mesh Settings.


Height Map Settings

This holds a reference to a scriptable object of type Height Map Settings.


Terrain Material

This holds a reference to a material that will be used to texture the mesh.


Editor Preview LOD

The slider changes what LOD the preview uses, so you can see what the mesh looks like at different detail levels. Useful to see if there are any bugs or artifacts with the way the mesh renders.


Terrain Generator

This is what makes the world when you click play, its what you would need if you were creating a infinite world. Or a world when you click start that is static and doesn't change size.


Collider LOD Index

This is what LOD the collider will use for collisions, depending how many Detail Levels you have you can change this, but it isn't recommended unless you know you need something specific and should just be left at 0 as it can cause issues with floating objects or clipping.


Detail Levels

This is a list of all the different LOD levels you can change this to have more or less in it, but 5 is the recommended max due to the amount of LOD's. You could set the number to 2 and have one set to 0 and one to 3. This would cause a more noticeable jump in detail in the meshes.


Mesh Settings

This holds a reference to a scriptable object of type Mesh Settings.


Height Map Settings

This holds a reference to a scriptable object of type Height Map Settings.


Is Endless

If this is ticked it means that the world will be endless and will generate new chunks when the player moves. If its false it will stay at the set size.


Viewer

This is just a reference to the player, so the world knows where the player is and can load and unload chunks when necessary.


Map Material

This holds a reference to a material that will be used to texture the mesh.


Threaded Data Requester

This holds data on the data that's been requested and updates data queues for the different threads when creating the worlds.


Editor Scripts

This overrides the standard inspector and allows buttons to be drawn to the inspector.


Height Map Settings Editor

These are used for updating the map and generating new seeds for the level.


Map Generator Editor

This adds the generate button, which allows you to quickly generate the mesh with the current settings.


Updateable Data Editor

This adds in a button called Update which allows you to update a mesh that's already been generated with the new values in the inspector. It calls the function `NotifyOfUpdatedValues` which invokes a event. This only works in the editor and won't be in the built game.


Scriptable Objects


Height Map Settings

This holds all of the relevant data for the Terrain Generator.


Auto Update

Should the map auto update when values are changed in the inspector. (Can cause the inspector to slow down)


Normalize Mode

If the map should normalize from the local or global coordinates. Local means that it will only look at the coordinates in that chunk, and each chunk could have different heights as they aren't uniform. Global will look at every point and then normalize them in every chunk equally.


Scale

This is the scale of the noise map it will use. Larger values will smooth out the noise more, where as if the value is smaller it will a lot more jagged and not very realistic.



Scale of 10


Scale of 100

Octaves

This controls the number of levels of detail you want the perlin noise to have. 1 being really smooth and 6 having more detail.

Octaves of 1


Octaves of 1

Persistence

This is what determines how much each octave contributes to the overall noise shape 0 having no influence and 1 being the last layer is the only one that will show.


Persistence of 0


Persistence of 0.6


Persistence of 1

Lacunarity

The number that determines how much detail is added or removed at each octave (adjusts frequency).

Lacunarity of 2


Lacunarity of 4

Offset

This is where on the noise map you are starting at, 0,0 would be the middle, but as you change the values of X and Y it will scroll around.



Seed

This is the value that will influence the random values used for the noise. If the seed is the same every time, the noise map will stay the same as its feed the same seed. But if this changes the noise will look different.


Use Falloff

If the map should use the falloff map or not. If its true it will create island like noise maps which are just surrounded by water.


Height Multiplier

This changes how tall certain points are. The noise map shows a value between 0 which is black, and 1 which is white. These are then passed through the Height Curve and remapped to a different value. These values are then timed by the height multiplier to get the final height. So if height multiplier was 60. A point was 1 would become 60 and be the top of a mountain. Where as a point with 0.2 would only become 12 and be a lot lower.


Height Curve

This is a animation curve that takes the points from the noise and depending on their value gets remapped to a new value depending on where they fall on the animation curve line. For instance but not recommended you could remap 0 to 1 and the sea would become a mountain.


This give lots of control over how high certain values are, as you can move them around on the graph until you are happy with the results it is producing.


Mesh Settings


Auto Update

Should the map auto update when values are changed in the inspector. (Can cause the inspector to slow down)


Mesh Scale

This changes how lage the mesh is 1 being its default. If this is increased the map will increase in size so when you play the game it will take longer to move around. If you decrease this, the map will appear smaller.


Chunk Size Index

This changes how big each chunk is, 1 being the smallest and 8 being the largest. Default for this is 3, but can be changed very easily.


Updateable Data

This class inherits `ScriptableObject` and adds a couple of functions, `OnValidate` and `NotifyOfUpdatedValues`. OnValidate is called whenever a value changes in the inspector and if you have autoUpdate on it will automatically call `NotifyOfUpdatedValues` which unsubscribes to the event, and if there is anything listening it will invoke it.


Both Mesh Settings and Height Map Settings inherit this class, meaning when the function gets called it will update the data which will update the mesh.


Other Scripts


Hide On Play

All this script does id hide the current gameObject that it is on.


Fall Off Noise Generator

This just holds a static class that can be called anywhere which will generate a fall of noise map, given a size.


Height Map Generator

This creates a heightmap based on the values it gets from the GenerateNoiseMap in the Noise script. It then creates a copy of the height curve as this will all be done on a new thread. It then loops through all the values and returns them as a height map to be used.


MeshData

This holds all the data for the mesh with several arrays for vertices, triangles, and UVs. It also holds methods used to add vertices and triangles to specific points in the arrays.


Mesh Generator

This contains a static method called GenerateTerrainMesh which returns MeshData. Which is called every time it needs to generate a new mesh for a chunk.


Noise

This generates a noise map that is used for the meshes. Using a width, height, and noise settings.


Terrain Chunk

This stores the information about each chunk, from the coordinates of the chunk to the Mesh Setting and LODs.


Texture Generator

This holds a couple methods. One which creates a texture from a colour map that is passed into it. The other being a method which takes a height map and generates a texture from it.

Recent Posts

See All
Day & Night System

A day night system, like the one in Stardew Valley where you have seasons and days that can be linked up to a weather system or events that

 
 
 
Item / Weapon System

This system enables users to create custom items and weapons using a custom inspector built with Unity's new UI Builder Toolkit.

 
 
 
Crafting System

Physically based crafting system requiring your to place items onto the crafting table and select a recipe from the book that you would like

 
 
 

Comments


Subscribe for News and Updates

Thanks for subscribing!

  • Discord
  • itchio-textless-black
  • X
  • linkedin-square-logo
© 2024 by Bopbop Studios. All Rights Reserved.
bottom of page