Posts tagged ‘generation’

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]

My second thermal erosion - 3D renderings

Introduction

I’ve made several 3D renderings with Blender to show how my new thermal erosion algorithm affects real terrains.

In order to appreciate the effects of the erosion, I suggest to open the images of each group in different tabs and view them in sequence, enjoy!

Fault formation

The following image shows how the original map (top-left square), generated by 1500 iterations of the fault formation algorithm, is modified by 25, 50 and 100 iterations of thermal erosion:

These are the 3D renderings from the SOUTH-EAST view:

          
          

As it’s possible to notice, the erosion algorithm changes the “block of rocks” in a mountain chain.

Circles

The following image shows how the original map (top-left square), generated by 1000 iterations of the circles algorithm, is modified by 25, 50 and 100 iterations of thermal erosion:

These are the 3D renderings from the NORTH-WEST view:

          
          

Terrains generated by the circles algorithm are usually smoother than terrains generated by another algorithm, so the new erosion algorithm modifies less the shapes, anyway 100 iterations give the same a good result.

Perlin Noise

The following image shows how the original map (top-left square), generated by the Perlin Noise algorithm (6 octaves), is modified by 25, 50 and 100 steps of thermal erosion:

These are the 3D renderings from the SOUTH-EAST view:

          
          

As in previous images, more iterations means a lower terrain.

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

Thermal erosion 2 3D renderings

Introduction

I’ve made several 3D renderings with Blender in order to show how the second thermal erosion affects real terrains.

This time I’ve used more erosion steps because this erosion produces less visible changes than the first one.

In order to appreciate the effects of the erosion, I suggest to open the images of each group in different tabs and view them in sequence, enjoy!

Fault formation

The following image shows how the original map (top-left square), generated by the fault formation algorithm, is modified by 50, 100 and 150 steps of thermal erosion:

These are the 3D renderings from the SOUTH-EAST view:

          
          

Circles

The following image shows how the original map (top-left square), generated by the circles algorithm, is modified by 50, 100 and 150 steps of thermal erosion:

These are the 3D renderings from the NORTH-WEST view:

          
          

Perlin noise

The following image shows how the original map (top-left square), generated by the Perlin noise algorithm, is modified by 50, 100 and 150 steps of thermal erosion:

These are the 3D renderings from the SOUTH-EAST view:

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

Thermal erosion 3D renderings

Introduction

I’ve made several 3D renderings with Blender in order to show how the developed thermal erosion affects real terrains, I’m really satisfied by the results and I hope you’re going to agree with me ;-)

In order to appreciate the effects of the erosion, I suggest to open the images of each group in different tabs and view them in sequence, enjoy!

EDIT 05/02/2008 - I’ve updated all the images with new renderings because the old ones had some visual “bugs” fixed by the subsurf modifier ;-)

Fault formation

The following image shows how the original map (top-left square), generated by the fault formation algorithm, is modified by 25, 50 and 100 steps of thermal erosion:

These are the 3D renderings from the SOUTH-EAST view:

          
          

Circles

The following image shows how the original map (top-left square), generated by the circles algorithm, is modified by 25, 50 and 100 steps of thermal erosion:

These are the 3D renderings from the NORTH-WEST view:

          
          

Perlin noise

The following image shows how the original map (top-left square), generated by the Perlin noise algorithm, is modified by 25, 50 and 100 steps of thermal erosion:

These are the 3D renderings from the SOUTH-EAST view:

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

Perlin noise 3D renderings

Introduction

I’ve improved my Blender skills a lot from my first posts about 3D renderings, of course I’m still a newbie and my renderings are more “experiments” than real works, but I hope you’re going to enjoy the new images ;-)

3D renderings

This is the base map I’ve generated summing 8 octaves:

and these are the 3D views from NORTH-EAST and SOUTH-EAST:

          

This is the same map after 2 iterations of blur (blur radius = 10.0):

And the same 3D views:

          

This is the original map modified by the abs() function followed by 2 iterations of blur (blur radius = 10.0):

and these are the 3D views from NORTH-WEST and SOUTH-WEST:

          

As it’s possible to notice in the previous images, the abs() function acts like a simple hydraulic erosion generating riverbeds among the mountains.

Instead this is the original map modified by the sqrt() function followed by 2 iterations of blur (blur radius = 10.0):

and these are the 3D views from NORTH-EAST and SOUTH-WEST:

          

From these images it’s possible to notice what I’ve just wrote in the post about the Perlin noise algorithm, it’s possible to generate different terrains from a single map using filter functions and it’s possible to do that in a real short time (about 2-3 ms.), this is a great feature of this algorithm!

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