Archive for the ‘Terrain Engine’ Category.

A (simple) terrain engine - day 6

Introduction

In the last days of work I’ve merged the 3D engine with the Perlin Noise generator, now I can see a new 3D terrain just pressing a key, so cool! :-P

The current version of the program is quite “rough”, mostly because the program is more a proof of concept than a real application, so I’m not wasting many time thinking about how to manage everything, all you’re going to read above it’s just a description of how the things are at the moment and not a guide about how things should be in a “perfect” engine.

The generation Process

In order to get a textured terrain I’ve created a kind of “generation pipeline”, the main steps are the following:

  • the heightmap is generated by the Perlin Noise shader
  • the texture is normalized by the normalization shader
  • the height values are dumped from the texture and stored in the array passed to the 3D rendering function
  • the color texture is generated by the procedural texture generation shader

Everything is done using a single Ping-Pong Texture (a couple of texture attached to a FBO).

Computation and Visualization

Using the same program for GPGPU computing and for 3D visualization requires a bit of code to manage the change from one status to the other one. Above there are the two methods I’ve added to the Screen class to accomplish this change.

The first one is called before the GPGPU phase:

void graphic::Screen::StartComputationMode(GLint w, GLint h)
{
    glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);

    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0.0, w, h, 0.0, -1.0, 1.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glViewport(0, 0, w, h);
}

the main purpose of this method is setting the orthogonal projection and disabling everything that can interfere with the computation, furthermore it updates the viewport to the texture dimension.

It’s important to notice how all the changes are made after matrix pushes, that means it’s possible to restore the GL context just with a couple of matrix pops, like showed in the following method:

void graphic::Screen::EndComputationMode()
{
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    glViewport(0, 0, _width, _height);

    glPopAttrib();
}

After this method is called, the visualization can restart with no problems.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

A (simple) terrain engine - day 5

Introduction

The new version of the engine comes with a couple of interesting new features… texturing above all!

I see the colors!

As I’ve already introduced, the main feature in this new version of the engine is the use of textures for coloring the terrain

The previous images shows a terrain with no color texture (top left panel) and the same terrain rendered in the 3 different polygonal modes with texture.

Now, if no texture file is passed to the CLI, the program uses the heightmap as texture.

A change related to the use of color textures is the new color of the fog:

now it’s gray, giving a more realistic look.

The last new feature is a minimap drawn on the top left corner of the window, it’s useful to show the heightmap image and compare it with the 3D rendering:

I’ve also fixed a bug in the terrain rendering, now the terrain is drawn according to the right orientation (as showed by the image above).

Source code

The source code of this version is available here: 3D_terrain-0.5.1.tar.gz

UPDATED on 2008/06/19 replaced the file with a new version that fixes some bugs and adds frame rate control.

In order to compile the code you need: SDL, SDL_image and scons.

To know options and commands run:

3D_terrain -h
[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

A (simple) terrain engine - day 4

Introduction

This day I’ve introduced another new feature to the engine: fog!

Misty days

OpenGL offers 3 different models for fog, the new version of my terrain engine allows to test them all just pressing a key:

The top left panel shows the terrain with no fog, the top right panel shows GL_LINEAR fog, the bottom left shows GL_EXP fog and the bottom right panel shows GL_EXP2 fog.

Of course the last one is the more realistic, but fog generated with GL_LINEAR is quite similar and it’s faster to compute.

Another news that it’s possible to notice from the previous image is that now the background color of the scene is blue, similar to the default background of Blender, this is not just a “tribute” to the 3D program, but it’s a way to have a better contrast between the terrain and the background.

Instead the color of the fog is totally a tribute to the fog used in “Warhammer 40k, Dawn of War“, a game I’m playing with in this period :-)

Source code

The source code of this version is available here: 3D_terrain-0.4.0.tar.gz

In order to compile the code you need: SDL, SDL_image and scons.

To know options and commands run:

3D_terrain -h
[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

A (simple) terrain engine - day 3

Introduction

Another improvement of the terrain engine, now it can render something more than simple points!

New features

Now the program is more an engine (even if really simple and not optimized) than a simple demo as in the previous version, the main news is the replacement of points with polygons (triangles, to be precise).

In this version is possible to render the terrain using points, not filled triangles (lines) and filled triangles, as showed in the following screenshots:

          

Using triangles instead of points allows also to notice better how the sampling level affect the rendering:

Source code

The source code of this version is available here: 3D_terrain-0.3.0.tar.gz

In order to compile the code you need: SDL, SDL_image and scons.

To know options and commands run:

3D_terrain -h
[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

A (simple) terrain engine - day 2

Introduction

I’ve improved the first version of the terrain engine, now it can be considered a “real” demo about 3D rendering of heightmaps.

Improvements and new features

There are several improvements and new features respect the first version of te engine, this is a list that summarizes the most relevant:

  • it’s possible to control all the parameters of the rendering routine and other stuff using command line options
  • all the rotations are done around the axes having the center of the map as origin
  • it’s possible to increment/decrement the sampling level of the map (look at the image below)
  • it’s possible to change visualization to fullscreen/window
  • movement and rotation are continuous holding keys down

Source code

I’ve decided to release the source code of this demo in my website (under construction at the moment), so I’m doing the same here, this is the file: 3D_terrain-0.2.1.tar.gz

In order to compile the code you need: SDL, SDL_image and scons.

To know options and commands run:

3D_terrain -h

EDIT 04/03/2008 - replaced 3D_terrain-0.2.0 with 3D_terrain-0.2.1, the new version fixes a bug with rotations.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]