diff --git a/components/esmterrain/storage.cpp b/components/esmterrain/storage.cpp index 3d6e521d1..1e23569b5 100644 --- a/components/esmterrain/storage.cpp +++ b/components/esmterrain/storage.cpp @@ -375,8 +375,7 @@ namespace ESMTerrain return texture; } - void Storage::getBlendmaps(float chunkSize, const osg::Vec2f &chunkCenter, - bool pack, ImageVector &blendmaps, std::vector &layerList) + void Storage::getBlendmaps(float chunkSize, const osg::Vec2f &chunkCenter, ImageVector &blendmaps, std::vector &layerList) { osg::Vec2f origin = chunkCenter - osg::Vec2f(chunkSize/2.f, chunkSize/2.f); int cellX = static_cast(std::floor(origin.x())); @@ -416,11 +415,8 @@ namespace ESMTerrain layerList.push_back(getLayerInfo(getTextureName(*it))); } - int numTextures = textureIndices.size(); - // numTextures-1 since the base layer doesn't need blending - int numBlendmaps = pack ? static_cast(std::ceil((numTextures - 1) / 4.f)) : (numTextures - 1); - - int channels = pack ? 4 : 1; + // size-1 since the base layer doesn't need blending + int numBlendmaps = textureIndices.size() - 1; // Second iteration - create and fill in the blend maps const int blendmapSize = (realTextureSize-1) * chunkSize + 1; @@ -430,10 +426,8 @@ namespace ESMTerrain for (int i=0; i image (new osg::Image); - image->allocateImage(blendmapImageSize, blendmapImageSize, 1, format, GL_UNSIGNED_BYTE); + image->allocateImage(blendmapImageSize, blendmapImageSize, 1, GL_ALPHA, 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 alpha = (layerIndex == i+1) ? 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; - pData[((realY+1)*blendmapImageSize + realX + 1)*channels + channel] = alpha; + pData[(realY+0)*blendmapImageSize + realX + 0] = alpha; + pData[(realY+1)*blendmapImageSize + realX + 0] = alpha; + pData[(realY+0)*blendmapImageSize + realX + 1] = alpha; + pData[(realY+1)*blendmapImageSize + realX + 1] = alpha; } } blendmaps.push_back(image); diff --git a/components/esmterrain/storage.hpp b/components/esmterrain/storage.hpp index 27d6232eb..613d2e218 100644 --- a/components/esmterrain/storage.hpp +++ b/components/esmterrain/storage.hpp @@ -92,14 +92,10 @@ namespace ESMTerrain /// @note May be called from background threads. /// @param chunkSize size of the terrain chunk in cell units /// @param chunkCenter center of the chunk in cell units - /// @param pack Whether to pack blend values for up to 4 layers into one texture (one in each channel) - - /// otherwise, each texture contains blend values for one layer only. Shader-based rendering - /// can utilize packing, FFP can't. /// @param blendmaps created blendmaps will be written here /// @param layerList names of the layer textures used will be written here - virtual void getBlendmaps (float chunkSize, const osg::Vec2f& chunkCenter, bool pack, - ImageVector& blendmaps, - std::vector& layerList); + virtual void getBlendmaps (float chunkSize, const osg::Vec2f& chunkCenter, ImageVector& blendmaps, + std::vector& layerList); virtual float getHeightAt (const osg::Vec3f& worldPos); diff --git a/components/terrain/chunkmanager.cpp b/components/terrain/chunkmanager.cpp index 8cfccabce..a22d43d74 100644 --- a/components/terrain/chunkmanager.cpp +++ b/components/terrain/chunkmanager.cpp @@ -119,7 +119,7 @@ std::vector > ChunkManager::createPasses(float chunk { std::vector layerList; std::vector > blendmaps; - mStorage->getBlendmaps(chunkSize, chunkCenter, false, blendmaps, layerList); + mStorage->getBlendmaps(chunkSize, chunkCenter, blendmaps, layerList); bool useShaders = mSceneManager->getForceShaders(); if (!mSceneManager->getClampLighting()) diff --git a/components/terrain/storage.hpp b/components/terrain/storage.hpp index 8a59c104c..cdde06e47 100644 --- a/components/terrain/storage.hpp +++ b/components/terrain/storage.hpp @@ -69,14 +69,10 @@ namespace Terrain /// @note May be called from background threads. Make sure to only call thread-safe functions from here! /// @param chunkSize size of the terrain chunk in cell units /// @param chunkCenter center of the chunk in cell units - /// @param pack Whether to pack blend values for up to 4 layers into one texture (one in each channel) - - /// otherwise, each texture contains blend values for one layer only. Shader-based rendering - /// can utilize packing, FFP can't. /// @param blendmaps created blendmaps will be written here /// @param layerList names of the layer textures used will be written here - virtual void getBlendmaps (float chunkSize, const osg::Vec2f& chunkCenter, bool pack, - ImageVector& blendmaps, - std::vector& layerList) = 0; + virtual void getBlendmaps (float chunkSize, const osg::Vec2f& chunkCenter, ImageVector& blendmaps, + std::vector& layerList) = 0; virtual float getHeightAt (const osg::Vec3f& worldPos) = 0;