🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

progress

posted in A Keyboard and the Truth for project 96 Mill
Published January 01, 2006
Advertisement
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 =)
Previous Entry Map structure
Next Entry Splizat
0 likes 3 comments

Comments

HopeDagger
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?
January 01, 2006 10:13 PM
EDI
yup, I haven't yet investigated what I am going to use, but that will be implemented since without it the height gets lost =/
January 01, 2006 10:49 PM
Rob Loach
Damn that's nice. Have any plans of putting some lighting on the matter?
January 02, 2006 12:44 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement