• Advertisement
  • entries
  • comments
  • views


Sign in to follow this  


I am making a bit of forward progress, I got hung up for a while on deciding the layout for my tiles in the monolithic vertex buffer. The original idea was to keep the vertex buffer as a grid of the entire map, and the use indices to group them into tiles. However this meant that drawing each tile required a large span of the vertex buffer to be processed uselessly each time it was renderd. So instead i structure each tile as it's own rectangular grid linearly in the vertex buffer, this allows me to render a tile by simply specifying a vertex buffer offset. Since splatting it going to require me to render tiles in multiple passes I feel it is important to reduce needless vertex processing.

Flat map, dirt and grass texture

Height map, snow texture

I took a smarter approach to height this time around, I created a HeightMap class, which can load an 8 bit raw image file (like the kind that terragen exports and that photoshop can read) this file format is very very simple, AND with photoshop has good tool support so I chose to use it as our heightmap source.

this class loads and manages the heightmap, and provides a 'sample' method, which allows you sample part of the heightmap via u,v coords (0 to 1) and returns a 0 to 1 value.

I am going to offer this class as freeware to any who would like to use it; it will require a bit of modification to fit your needs but it should be minimal.


#pragma once
#include "common.h"

class HeightMap
unsigned long size;
unsigned char* data;
float sample(float u,float v);
HeightMap(string rawFile);


#include "HeightMap.h"
#include "Message.h"
HeightMap::HeightMap(string rawFile)
std::ifstream in;
unsigned long length=in.tellg();
size=(unsigned long)sqrtf(length);
data=new unsigned char[length];
Message::showProblem("Unable to load height-map '"+rawFile+"'.");


float HeightMap::sample(float u,float v)
unsigned int x=(u*(float)(size-1));
unsigned int y=(v*(float)(size-1));
unsigned char s=data[y*size+x];
return (float)s/255.0f;

Now that I have a well-developed tiled terrain the next step is to add splatting, which I will document when I have it working.

Enjoy =)
Sign in to follow this  


Recommended Comments

Looks good so far. :)

Will you be using some kind diffuse light to help liven up the contours of the heightmap, or somesort of other solution?

Share this comment

Link to comment
yup, I haven't yet investigated what I am going to use, but that will be implemented since without it the height gets lost =/

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement