1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-02 14:36:42 +00:00

Use low-LOD heightmap for world map rendering

Add vanilla-accurate colour palette (thanks Hrnchamd)
This commit is contained in:
scrawl 2015-01-29 02:23:49 +01:00
parent 201674cd70
commit 62a32220ff
2 changed files with 64 additions and 94 deletions
apps/openmw/mwrender
components/esm

View file

@ -66,108 +66,81 @@ namespace MWRender
loadingListener->setProgressRange((mMaxX-mMinX+1) * (mMaxY-mMinY+1)); loadingListener->setProgressRange((mMaxX-mMinX+1) * (mMaxY-mMinY+1));
loadingListener->setProgress(0); loadingListener->setProgress(0);
const Ogre::ColourValue waterShallowColour(0.15, 0.2, 0.19); std::vector<Ogre::uchar> data (mWidth * mHeight * 3);
const Ogre::ColourValue waterDeepColour(0.1, 0.14, 0.13);
const Ogre::ColourValue groundColour(0.254, 0.19, 0.13);
const Ogre::ColourValue mountainColour(0.05, 0.05, 0.05);
const Ogre::ColourValue hillColour(0.16, 0.12, 0.08);
//if (!boost::filesystem::exists(mCacheDir + "/GlobalMap.png")) for (int x = mMinX; x <= mMaxX; ++x)
if (1)
{ {
std::vector<Ogre::uchar> data (mWidth * mHeight * 3); for (int y = mMinY; y <= mMaxY; ++y)
for (int x = mMinX; x <= mMaxX; ++x)
{ {
for (int y = mMinY; y <= mMaxY; ++y) ESM::Land* land = esmStore.get<ESM::Land>().search (x,y);
if (land)
{ {
ESM::Land* land = esmStore.get<ESM::Land>().search (x,y); int mask = ESM::Land::DATA_VHGT | ESM::Land::DATA_VNML | ESM::Land::DATA_VCLR | ESM::Land::DATA_VTEX | ESM::Land::DATA_WNAM;
if (!land->isDataLoaded(mask))
land->loadData(mask);
}
if (land) for (int cellY=0; cellY<mCellSize; ++cellY)
{
for (int cellX=0; cellX<mCellSize; ++cellX)
{ {
int mask = ESM::Land::DATA_VHGT | ESM::Land::DATA_VNML | ESM::Land::DATA_VCLR | ESM::Land::DATA_VTEX; int vertexX = float(cellX)/float(mCellSize) * 9;
if (!land->isDataLoaded(mask)) int vertexY = float(cellY)/float(mCellSize) * 9;
land->loadData(mask);
}
for (int cellY=0; cellY<mCellSize; ++cellY)
{ int texelX = (x-mMinX) * mCellSize + cellX;
for (int cellX=0; cellX<mCellSize; ++cellX) int texelY = (mHeight-1) - ((y-mMinY) * mCellSize + cellY);
unsigned char r,g,b;
float y = 0;
if (land && land->mDataTypes & ESM::Land::DATA_WNAM)
y = (land->mLandData->mWnam[vertexY * 9 + vertexX] << 4) / 2048.f;
else
y = (SCHAR_MIN << 4) / 2048.f;
if (y < 0)
{ {
int vertexX = float(cellX)/float(mCellSize) * ESM::Land::LAND_SIZE; r = (14 * y + 38);
int vertexY = float(cellY)/float(mCellSize) * ESM::Land::LAND_SIZE; g = 20 * y + 56;
b = 18 * y + 51;
}
int texelX = (x-mMinX) * mCellSize + cellX; else if (y < 0.3f)
int texelY = (mHeight-1) - ((y-mMinY) * mCellSize + cellY); {
if (y < 0.1f)
unsigned char r,g,b; y *= 8.f;
if (land)
{
const float landHeight = land->mLandData->mHeights[vertexY * ESM::Land::LAND_SIZE + vertexX];
if (landHeight >= 0)
{
const float hillHeight = 2500.f;
if (landHeight >= hillHeight)
{
const float mountainHeight = 15000.f;
float factor = std::min(1.f, float(landHeight-hillHeight)/mountainHeight);
r = (hillColour.r * (1-factor) + mountainColour.r * factor) * 255;
g = (hillColour.g * (1-factor) + mountainColour.g * factor) * 255;
b = (hillColour.b * (1-factor) + mountainColour.b * factor) * 255;
}
else
{
float factor = std::min(1.f, float(landHeight)/hillHeight);
r = (groundColour.r * (1-factor) + hillColour.r * factor) * 255;
g = (groundColour.g * (1-factor) + hillColour.g * factor) * 255;
b = (groundColour.b * (1-factor) + hillColour.b * factor) * 255;
}
}
else
{
if (landHeight >= -100)
{
float factor = std::min(1.f, -1*landHeight/100.f);
r = (((waterShallowColour+groundColour)/2).r * (1-factor) + waterShallowColour.r * factor) * 255;
g = (((waterShallowColour+groundColour)/2).g * (1-factor) + waterShallowColour.g * factor) * 255;
b = (((waterShallowColour+groundColour)/2).b * (1-factor) + waterShallowColour.b * factor) * 255;
}
else
{
float factor = std::min(1.f, -1*(landHeight-100)/1000.f);
r = (waterShallowColour.r * (1-factor) + waterDeepColour.r * factor) * 255;
g = (waterShallowColour.g * (1-factor) + waterDeepColour.g * factor) * 255;
b = (waterShallowColour.b * (1-factor) + waterDeepColour.b * factor) * 255;
}
}
}
else else
{ {
r = waterDeepColour.r * 255; y -= 0.1;
g = waterDeepColour.g * 255; y += 0.8;
b = waterDeepColour.b * 255;
} }
r = 66 - 32 * y;
data[texelY * mWidth * 3 + texelX * 3] = r; g = 48 - 23 * y;
data[texelY * mWidth * 3 + texelX * 3+1] = g; b = 33 - 16 * y;
data[texelY * mWidth * 3 + texelX * 3+2] = b;
} }
else
{
y -= 0.3f;
y *= 1.428f;
r = 34 - 29 * y;
g = 25 - 20 * y;
b = 17 - 12 * y;
}
data[texelY * mWidth * 3 + texelX * 3] = r;
data[texelY * mWidth * 3 + texelX * 3+1] = g;
data[texelY * mWidth * 3 + texelX * 3+2] = b;
} }
} }
loadingListener->increaseProgress();
} }
Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream(&data[0], data.size()));
tex = Ogre::TextureManager::getSingleton ().createManual ("GlobalMap.png", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D, mWidth, mHeight, 0, Ogre::PF_B8G8R8, Ogre::TU_STATIC);
tex->loadRawData(stream, mWidth, mHeight, Ogre::PF_B8G8R8);
} }
else
tex = Ogre::TextureManager::getSingleton ().getByName ("GlobalMap.png"); Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream(&data[0], data.size()));
tex = Ogre::TextureManager::getSingleton ().createManual ("GlobalMap.png", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D, mWidth, mHeight, 0, Ogre::PF_B8G8R8, Ogre::TU_STATIC);
tex->loadRawData(stream, mWidth, mHeight, Ogre::PF_B8G8R8);
tex->load(); tex->load();
@ -267,9 +240,9 @@ namespace MWRender
{ {
const ESM::GlobalMap::Bounds& bounds = map.mBounds; const ESM::GlobalMap::Bounds& bounds = map.mBounds;
if (bounds.mMaxX-bounds.mMinX <= 0) if (bounds.mMaxX-bounds.mMinX < 0)
return; return;
if (bounds.mMaxY-bounds.mMinY <= 0) if (bounds.mMaxY-bounds.mMinY < 0)
return; return;
if (bounds.mMinX > bounds.mMaxX if (bounds.mMinX > bounds.mMaxX

View file

@ -85,12 +85,9 @@ struct Land
char mColours[3 * LAND_NUM_VERTS]; char mColours[3 * LAND_NUM_VERTS];
int mDataTypes; int mDataTypes;
// WNAM appears to contain the global map image for this cell. Probably a palette-based format, // low-LOD heightmap (used for rendering the global map)
// since there's only 1 byte for each pixel. signed char mWnam[81];
// Currently unused (global map is drawn on the fly in OpenMW, takes ~1/2 second at startup for Morrowind.esm).
// The problem with using the original data is that we would need to exactly replicate the TES CS's algorithm
// for drawing the global map in OpenCS, in order to get seamless edges when creating landmass mods.
uint8_t mWnam[81];
short mUnk1; short mUnk1;
uint8_t mUnk2; uint8_t mUnk2;