13
Procedural Terrain with Stochastic Trees. WITH MAX MORRIS, CORY GAGEL, MARK WOULFE

Procedural Terrain with Stochastic Trees. WITH MAX MORRIS, CORY GAGEL, MARK WOULFE

Embed Size (px)

Citation preview

Procedural Terrain with Stochastic Trees.WITH MAX MORRIS, CORY GAGEL, MARK WOULFE

The Finished Product

Overview

Problem: Create a procedural terrain using perlin noise, with stochastic trees with leaves.

Task 1: Use perlin noise to generate a terrain.

Task 2: Figure out where to place the trees.

Task 3: Create the stochastic trees.

Task 4: Populate trees with leaves.

Task Division

Max: Tasked with using perlin noise to generate terrain, and figuring out where the trees are supposed to go in the world.

Cory: Tasked with creating the stochastic trees and initial leaf generation.

Mark: Tasked with populating the trees with leaves, and helping with the initial perlin noise theory research.

Summary of Perlin Noise

The whole theory of Perlin Noise is based around being able to send off a variable or set of variables and getting the same results every time.

A very common way of generating terrain.

Easily customisable with Frequency (length of the wave) and Amplitude (height of the wave) values.

How we implement it

We set up our voxel world as a 256x256 grid.

We loop through all our X and Z co-ordinates and send the co-ordinates to the noise to generate the noise value.

We get the noise value of each corner of the current voxel.

This noise however is not very smooth, so we take the current neighbour and get its neighbours we then average the values together to smooth out the values.

We then interpolate these values to calculate a height which is then returned to create how high we need to build the current X,Y co-ordinate.

Its then a simple case of building voxels from the ground up to the height value returned between 0-128.

The trees are then placed randomly in the world on top of grass blocks.

The finished terrain

Stochastic Tree Generation

Once the terrain is generated, we determine at random if an X/Y coordinate should have a tree.

If a tree is to be added, the main program uses the tree generator class to add a tree.

The tree generator takes the coordinates where the tree is to be placed and the type of tree desired to generate the vertices for the tree.

Each branch is a formed cone with a bark texture.

The tree generator class will hold the vertices, texture coordinates, and normals of all the trees requested by the main program.

Once all the trees are added, the main program asks the tree generator to prepare the trees by placing all the data into buffers.

What did it take to make that?

The Lindenmeyer system built during the first maths assignment was enhanced.

A stochastic tree system is read into the tree generator class.

Using constrained random angles and a constrained random iteration, the tree is built from the ground up.

Each section of the branch is subdivided into quads.

The height of the branch will determine how many quads will be generated per branch.

We defined the number of quads per height section which allowed us control over how smooth the branches are around.

How we added trees to terrain

Once the tree information is buffered, the main program simply calls the tree generator render function to draw all the trees in one draw call.

Leaf Generation

First we go through every tree that has been generated by the tree generator and decide what textures should be used if any. (Alive = green textures, dying = brown textures, dead = no leaf textures.)

From the tree generator we pass in the size and position of each branch along with the number of quads we want to use for the leafs.

Depending on the number of quads we take that value, multiply it by 2 and then divide that value from 360 to determine what rotation they should use when being placed.

Leafs are then translated to the end of the branch (based on base position, orientation and length of branch all passed by the tree generator)

The texture used comes from a random call between 0-2 for the relative tree type.

Leaf Textures

Top down view of leaf quads

12

3

4

Leaf Placement

We do some additional checks before actually placing our leaves depending on the height and size of the branch.

If the branch size is less than 1 (a tiny branch barely see able with the human eye) then we ignore that branch and don’t draw leaves on it.

If the branch does not start at least halfway up the tree then no leaves are drawn (leads to more realistic trees.) This is done by having a constant check for each branch to determine the longest branch which is always the main trunk of the tree.

When drawing the leaves we scale them to the size of the branch (20 / size of the branch) and also insure that it is of a minimum height as to not draw tiny leaves.

Tree following rules defined

Tree without

rules defined

Demonstration