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 =)
Will you be using some kind diffuse light to help liven up the contours of the heightmap, or somesort of other solution?