Merge pull request #2278 from Capostrophic/blendmap

Remove unused and unfinished blendmap packing feature
pull/541/head
Bret Curtis 6 years ago committed by GitHub
commit 115f12823a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -375,8 +375,7 @@ namespace ESMTerrain
return texture;
}
void Storage::getBlendmaps(float chunkSize, const osg::Vec2f &chunkCenter,
bool pack, ImageVector &blendmaps, std::vector<Terrain::LayerInfo> &layerList)
void Storage::getBlendmaps(float chunkSize, const osg::Vec2f &chunkCenter, ImageVector &blendmaps, std::vector<Terrain::LayerInfo> &layerList)
{
osg::Vec2f origin = chunkCenter - osg::Vec2f(chunkSize/2.f, chunkSize/2.f);
int cellX = static_cast<int>(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<int>(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<numBlendmaps; ++i)
{
GLenum format = pack ? GL_RGBA : GL_ALPHA;
osg::ref_ptr<osg::Image> 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; y<blendmapSize; ++y)
@ -443,18 +437,16 @@ namespace ESMTerrain
UniqueTextureId id = getVtexIndexAt(cellX, cellY, x+rowStart, y+colStart, cache);
assert(textureIndicesMap.find(id) != textureIndicesMap.end());
int layerIndex = textureIndicesMap.find(id)->second;
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 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);

@ -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<Terrain::LayerInfo>& layerList);
virtual void getBlendmaps (float chunkSize, const osg::Vec2f& chunkCenter, ImageVector& blendmaps,
std::vector<Terrain::LayerInfo>& layerList);
virtual float getHeightAt (const osg::Vec3f& worldPos);

@ -119,7 +119,7 @@ std::vector<osg::ref_ptr<osg::StateSet> > ChunkManager::createPasses(float chunk
{
std::vector<LayerInfo> layerList;
std::vector<osg::ref_ptr<osg::Image> > blendmaps;
mStorage->getBlendmaps(chunkSize, chunkCenter, false, blendmaps, layerList);
mStorage->getBlendmaps(chunkSize, chunkCenter, blendmaps, layerList);
bool useShaders = mSceneManager->getForceShaders();
if (!mSceneManager->getClampLighting())

@ -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<LayerInfo>& layerList) = 0;
virtual void getBlendmaps (float chunkSize, const osg::Vec2f& chunkCenter, ImageVector& blendmaps,
std::vector<LayerInfo>& layerList) = 0;
virtual float getHeightAt (const osg::Vec3f& worldPos) = 0;

Loading…
Cancel
Save