From 6277f5511c4346a4038dda8401edf241b8a88b51 Mon Sep 17 00:00:00 2001 From: wareya Date: Fri, 8 Jun 2018 17:52:46 -0400 Subject: [PATCH 1/3] fix #3876 and #3993 --- components/esmterrain/storage.cpp | 34 ++++++++++++++++++++++++------- components/terrain/material.cpp | 3 +++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/components/esmterrain/storage.cpp b/components/esmterrain/storage.cpp index dc144d119..a1b4856e1 100644 --- a/components/esmterrain/storage.cpp +++ b/components/esmterrain/storage.cpp @@ -430,15 +430,23 @@ namespace ESMTerrain // Second iteration - create and fill in the blend maps 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; + + + const bool largeImage = true; for (int i=0; i image (new osg::Image); - image->allocateImage(blendmapSize, blendmapSize, 1, format, GL_UNSIGNED_BYTE); + if(!largeImage) + image->allocateImage(blendmapSize, blendmapSize, 1, format, GL_UNSIGNED_BYTE); + else + image->allocateImage(blendmapImageSize, blendmapImageSize, 1, format, GL_UNSIGNED_BYTE); unsigned char* pData = image->data(); - for (int y=0; ysecond; int blendIndex = (pack ? static_cast(std::floor((layerIndex - 1) / 4.f)) : layerIndex - 1); int channel = pack ? std::max(0, (layerIndex-1) % 4) : 0; - - if (blendIndex == i) - pData[(blendmapSize - y - 1)*blendmapSize*channels + x*channels + channel] = 255; + + int alpha = (blendIndex == i) ? 255 : 0; + + if(!largeImage) + pData[((blendmapSize - y - 1)*blendmapSize + x)*channels + channel] = alpha; else - pData[(blendmapSize - y - 1)*blendmapSize*channels + x*channels + channel] = 0; + { + int realY = (blendmapSize - y - 1)*imageScaleFactor; + int realX = x*imageScaleFactor; + if(true) + pData[((realY+0)*blendmapImageSize + realX + 0)*channels + channel] = alpha; + if(realY+1 < blendmapImageSize) + pData[((realY+1)*blendmapImageSize + realX + 0)*channels + channel] = alpha; + if(realX+1 < blendmapImageSize) + pData[((realY+0)*blendmapImageSize + realX + 1)*channels + channel] = alpha; + if(realY+1 < blendmapImageSize && realX+1 < blendmapImageSize) + pData[((realY+1)*blendmapImageSize + realX + 1)*channels + channel] = alpha; + } } } - blendmaps.push_back(image); } } diff --git a/components/terrain/material.cpp b/components/terrain/material.cpp index 640f2932b..56ace0e5a 100644 --- a/components/terrain/material.cpp +++ b/components/terrain/material.cpp @@ -25,6 +25,9 @@ namespace Terrain matrix.preMultTranslate(osg::Vec3f(0.5f, 0.5f, 0.f)); matrix.preMultScale(osg::Vec3f(scale, scale, 1.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); From 8f45b0d53a3c398df88d83681c24a25863b910ba Mon Sep 17 00:00:00 2001 From: wareya Date: Sat, 9 Jun 2018 10:11:43 -0400 Subject: [PATCH 2/3] remove unnecessary conditions --- components/esmterrain/storage.cpp | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/components/esmterrain/storage.cpp b/components/esmterrain/storage.cpp index a1b4856e1..fd04d90b9 100644 --- a/components/esmterrain/storage.cpp +++ b/components/esmterrain/storage.cpp @@ -434,19 +434,14 @@ namespace ESMTerrain const int imageScaleFactor = 2; const int blendmapImageSize = blendmapSize * imageScaleFactor; - - const bool largeImage = true; - for (int i=0; i image (new osg::Image); - if(!largeImage) - image->allocateImage(blendmapSize, blendmapSize, 1, format, GL_UNSIGNED_BYTE); - else - image->allocateImage(blendmapImageSize, blendmapImageSize, 1, format, GL_UNSIGNED_BYTE); + image->allocateImage(blendmapImageSize, blendmapImageSize, 1, format, GL_UNSIGNED_BYTE); unsigned char* pData = image->data(); + for (int y=0; y Date: Sat, 9 Jun 2018 10:31:51 -0400 Subject: [PATCH 3/3] remove indentation from blank lines --- components/esmterrain/storage.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/esmterrain/storage.cpp b/components/esmterrain/storage.cpp index fd04d90b9..dadc64f57 100644 --- a/components/esmterrain/storage.cpp +++ b/components/esmterrain/storage.cpp @@ -433,7 +433,7 @@ namespace ESMTerrain // 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 image (new osg::Image); image->allocateImage(blendmapImageSize, blendmapImageSize, 1, format, GL_UNSIGNED_BYTE); unsigned char* pData = image->data(); - + for (int y=0; ysecond; int blendIndex = (pack ? static_cast(std::floor((layerIndex - 1) / 4.f)) : layerIndex - 1); int channel = pack ? std::max(0, (layerIndex-1) % 4) : 0; - + int alpha = (blendIndex == i) ? 255 : 0; - + int realY = (blendmapSize - y - 1)*imageScaleFactor; 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;