Posts tagged ‘engine’

Real-time thermal erosion much faster now!

Intoduction

“A picture is worth a thousand words” so I suppose a video should be much better ;-)

The real-time erosion has gained a lot from the latest optimization work, the number of FPS is passed from 1.8 to 71.4 for my first thermal erosion and from 3.1 to 71.4 for my second thermal erosion, that means that the first erosion is about 40 times faster and the second one is about 23 times faster, a huge improvement for a real-time program!

Even if the second algorithm is faster than the first one, using a small heightmap (256×256) gives the same execution time for both.

First thermal erosion

This video shows a terrain generated by the sum of 6 octaves of Perlin Noise and eroded by 100 iterations (double the number of the previous video) of my first thermal erosion algorithm.

The video is available on:

this erosion algorithm allows an average frame rate (computation + visualization) of 71.4 FPS using a 256×256 16-bits floating-point texture as heightmap.

Second thermal erosion

This video shows the same terrain generated by the sum of 6 octaves of Perlin Noise and eroded by 100 (double the number of the previous video) iterations of my second thermal erosion algorithm.

The video is available on:

this erosion algorithm allows an average frame rate (computation + visualization) of 71.4 FPS using a 256×256 16-bits floating-point texture as heightmap.

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

Real-time thermal erosion

Introduction

I’ve improved the terrain engine adding my thermal erosion shaders, now it’s possible to see a real-time erosion (from computer graphic point of view, a real erosion would take thousands years :-P) just pressing a key!

The erosion is managed in a different way respect the previous applications I’ve made, now after every iteration, the result is shown by the terrain engine, so it’s possible to see how the ground changes during the whole process.

I’ve made a couple of videos to show this new feature, enjoy.

First thermal erosion

This video shows a terrain generated by the sum of 6 octaves of Perlin Noise and eroded by 50 iterations of my first thermal erosion algorithm.

The video is available on:

this erosion algorithm allows an average frame rate (computation + visualization) of 1.8 FPS using a 256×256 16-bits floating-point texture as heightmap.

Second thermal erosion

This video shows the same terrain generated by the sum of 6 octaves of Perlin Noise and eroded by 50 iterations of my second thermal erosion algorithm.

The video is available on:

this erosion algorithm allows an average frame rate (computation + visualization) of 3.1 FPS using a 256×256 16-bits floating-point texture as heightmap.

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

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]