Skip to content

Latest commit

 

History

History
137 lines (98 loc) · 8.85 KB

README.md

File metadata and controls

137 lines (98 loc) · 8.85 KB

TerrainGenerator: A Procedural 3D Terrain Generator

A simple procedural 3D terrain generator made using Processing Language , meant as a project for a Computer Graphics class. However, it has been extended with functionalaties like Texture Mode, WholeImage mode and Recording (see: Usage.)

License Latest release

Table of contents

Introduction

A simple procedural 3D terrain generator made using Processing Language, meant as a project for a Computer Graphics class. The initial goal was to learn how to turn a basic 2D grid into a moving 3D terrain, but it later evolved into displaying pictures and textures on the grid.

The program offers a UI that allows the user to tweak various parameters such as the width/height of the grid, movement speed/direction ...etc. The changes are reflected in the rendered scene immediately.

The program also demonstrates the importance of having a good organic noise generating algorithm, as the pseudo-random algorithm that comes with most programming languages just does not make it.

Installation

After you download or clone the repository the directory structure should look like this :

Project Directory Structure

The only prerequisite needed to launch the app is having java (v.17+) installed on your machine. After that you can just run the executable in the [application.windows](application.windows) folder!\ Alternatively, you can also use processing editor to compile the code and bundle the java installation with it, which will eliminate the need to install java seperately.

Usage

Nothing special needed for starting the app, just launch the executable. After that you should be greeted with a screen lik below :

Start screen

Basic operation

The program offers various features to try:

  1. Noise Algorithm : Perhaps one of the most important point about the program, as the entire idea of the project is to draw a 2D grid and then give it a 3D illusion by rotating the x axies of the scene and giving the points random Z values between a given range. As mentioned above the progranm demonstrates the need for organic noise generating algorithms (sometimes even dedicated hardware), as normal pseudo-random algorithms does not make it.\

The program uses Perlin Noise algorithm -a type of gradient noise developed by Ken Perlin- and will allow you to compare it with the normal pseudo-random algorithm provided with Java. The scene in the gif below starts with the perlin noise algorithm, and then changes to the normal random algorithm, see the difference for your self:

Start screen

  1. Width/Height, Rotation Angles, Fill, Stroke, Speed, Direction and other parameters :
  2. Mesh Type :
  3. Lightning :
  4. Texture Mode : Processing comes with a built-in texture() function, which just require you to provide the vertices and the uv wrap will be done automaticly :

Start screen

In our case, adding a texture to the terrain allows us to give it a more natural feeling. However, you can do better if you linear enterpolat the texture color based on the Z coordinates of that point.
7. WholeImage Mode : Take a look at the gif below. Remember scenes like this?

Start screen

Credit: Flightking14

I think this is where I was inspired to come up with this idea of using the terrain as a screen and then projecting an image of your choice into it.

Start screen

  1. Recording : Ok, you did all sort of magic with tha app, and then? Would't it feel nice to be able to at least get some solid results after all of this? That is why 'Recording Mode' is here. As the name indicates, it allows you to record the terrain scene you are running right now. However,it only captures the frames. You will have to use other programs to combine them and turn them into a video.

You can start recording by checking the box 'Record' at the bottom :

Record Check Box

After you start the recording, the circle at the bottom of the scene is going to turn red, indicating that recording has started :

RecordingMode

Once finished, simply uncheck the box and the recording should stop. The frames are saved to a folder named 'output' in the project directoy :

recordingOutput

However, since the capturing is done internaly, it affects perfomance in a noticable way, as you should have noticed from the gif above.

Known issues and limitations

  • Camera Issue : You should have noticed that whenever you press and the drag the mouse on the left side of the app the scene inside also gets affected, despite you not touching the scene screen at all. The camera mode is enabled by the PeasyCam module for Processing sketches. The PeasyCam module usually takes the current window as an argument to apply the camera effects to it. The terrain scene is a seperate scene inside the main window, and I believe that is the source of the problem.
    Update : I have been able to solve the issue by removing the PeasyCam module I added manually and instead used the option provided by the G4P builder directly.
  • UI elements going over the screen : Specially apparent in laptops, the main window is not big enough to contain the UI elements, and some sliders' lables are not showing correctly. You may try to set a better layout by editing the source code using Processing and G4P ( a Drag and Drop gui builder for processing sketches).
  • Wrong vertex selection for some mesh types : When you change the mesh type to QUADS or TRIANGLES for example, the terrain drawn is not correct. That is due to the wrong selection of vertecies coordinates internally. In Processing, you can create shapes by using default functions (e.g. ellipse()) or by using the beginShape() function that allows you to create arbitray shapes by selecting the vertecies and some other properties. You can see beginShape() , you have to choose the vertecies correctly for each shape type, else aribitrary shapes may be drawn.
  • Sliders initial values : The default values for some properites are different from the default sliders' values. As a result, when trying to change the values via the sliders, the scene may change drasticlly even if you just touched the slider slightly.

License

This program is distributed under the terms of the MIT License (MIT). The license applies to this file and other files in the GitHub repository hosting this file.

Authors and history

  • Esam Bashir : The original author.
  • Daniel Shiffman : Even though I did the project alone, it's core idea was taken from Daniel's youtube channel

Acknowledgments

As mentioned above, the main part of the project(drawing the terrain) was taken from Daniel Shiffman's channel. You can find the video below.