Merged pull request #1739

0.6.3
Marc Zinnschlag 7 years ago
commit 8d0f717e72

@ -430,13 +430,16 @@ namespace ESMTerrain
// Second iteration - create and fill in the blend maps // Second iteration - create and fill in the blend maps
const int blendmapSize = (realTextureSize-1) * chunkSize + 1; const int blendmapSize = (realTextureSize-1) * chunkSize + 1;
// We need to upscale the blendmap 2x with nearest neighbor sampling to look like Vanilla
const int imageScaleFactor = 2;
const int blendmapImageSize = blendmapSize * imageScaleFactor;
for (int i=0; i<numBlendmaps; ++i) for (int i=0; i<numBlendmaps; ++i)
{ {
GLenum format = pack ? GL_RGBA : GL_ALPHA; GLenum format = pack ? GL_RGBA : GL_ALPHA;
osg::ref_ptr<osg::Image> image (new osg::Image); osg::ref_ptr<osg::Image> image (new osg::Image);
image->allocateImage(blendmapSize, blendmapSize, 1, format, GL_UNSIGNED_BYTE); image->allocateImage(blendmapImageSize, blendmapImageSize, 1, format, GL_UNSIGNED_BYTE);
unsigned char* pData = image->data(); unsigned char* pData = image->data();
for (int y=0; y<blendmapSize; ++y) for (int y=0; y<blendmapSize; ++y)
@ -449,13 +452,17 @@ namespace ESMTerrain
int blendIndex = (pack ? static_cast<int>(std::floor((layerIndex - 1) / 4.f)) : layerIndex - 1); int blendIndex = (pack ? static_cast<int>(std::floor((layerIndex - 1) / 4.f)) : layerIndex - 1);
int channel = pack ? std::max(0, (layerIndex-1) % 4) : 0; int channel = pack ? std::max(0, (layerIndex-1) % 4) : 0;
if (blendIndex == i) int alpha = (blendIndex == i) ? 255 : 0;
pData[(blendmapSize - y - 1)*blendmapSize*channels + x*channels + channel] = 255;
else int realY = (blendmapSize - y - 1)*imageScaleFactor;
pData[(blendmapSize - y - 1)*blendmapSize*channels + x*channels + channel] = 0; int realX = x*imageScaleFactor;
pData[((realY+0)*blendmapImageSize + realX + 0)*channels + channel] = alpha;
pData[((realY+1)*blendmapImageSize + realX + 0)*channels + channel] = alpha;
pData[((realY+0)*blendmapImageSize + realX + 1)*channels + channel] = alpha;
pData[((realY+1)*blendmapImageSize + realX + 1)*channels + channel] = alpha;
} }
} }
blendmaps.push_back(image); blendmaps.push_back(image);
} }
} }

@ -25,6 +25,9 @@ namespace Terrain
matrix.preMultTranslate(osg::Vec3f(0.5f, 0.5f, 0.f)); matrix.preMultTranslate(osg::Vec3f(0.5f, 0.5f, 0.f));
matrix.preMultScale(osg::Vec3f(scale, scale, 1.f)); matrix.preMultScale(osg::Vec3f(scale, scale, 1.f));
matrix.preMultTranslate(osg::Vec3f(-0.5f, -0.5f, 0.f)); matrix.preMultTranslate(osg::Vec3f(-0.5f, -0.5f, 0.f));
// We need to nudge the blendmap to look like vanilla.
// This causes visible seams unless the blendmap's resolution is doubled, but Vanilla also doubles the blendmap, apparently.
matrix.preMultTranslate(osg::Vec3f(1.0f/blendmapScale/4.0f, 1.0f/blendmapScale/4.0f, 0.f));
texMat = new osg::TexMat(matrix); texMat = new osg::TexMat(matrix);

Loading…
Cancel
Save