Jump to content
  • Advertisement
  • entries
    503
  • comments
    1888
  • views
    335593

progress

Sign in to follow this  
EDI

113 views

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.

HeightMap.h

#pragma once
#include "common.h"

class HeightMap
{
private:
unsigned long size;
unsigned char* data;
public:
float sample(float u,float v);
HeightMap(string rawFile);
~HeightMap(void);
};



HeightMap.cpp

#include "HeightMap.h"
#include
#include
#include "Message.h"
HeightMap::HeightMap(string rawFile)
{
std::ifstream in;
size=0;
data=null;
in.open(rawFile.data(),std::ios::in|std::ios::binary);
if(in.is_open())
{
in.seekg(0,std::ios::end);
unsigned long length=in.tellg();
size=(unsigned long)sqrtf(length);
data=new unsigned char[length];
in.seekg(0,std::ios::beg);
in.read((char*)data,length);
in.close();
}
else
{
Message::showProblem("Unable to load height-map '"+rawFile+"'.");
}
}

HeightMap::~HeightMap(void)
{
SAFE_DELETE_ARRAY(data);
size=0;
}

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  


3 Comments


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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!