diff --git a/components/terrain/material.cpp b/components/terrain/material.cpp index df45b6ec2..d467a9e16 100644 --- a/components/terrain/material.cpp +++ b/components/terrain/material.cpp @@ -11,7 +11,7 @@ namespace Terrain { FixedFunctionTechnique::FixedFunctionTechnique(const std::vector<osg::ref_ptr<osg::Texture2D> >& layers, - const std::vector<osg::ref_ptr<osg::Texture2D> >& blendmaps) + const std::vector<osg::ref_ptr<osg::Texture2D> >& blendmaps, int blendmapSize, float layerTileSize) { bool firstLayer = true; int i=0; @@ -36,7 +36,7 @@ namespace Terrain // This is to map corner vertices directly to the center of a blendmap texel. osg::Matrixf texMat; - float scale = (16/(16.f+1.f)); + float scale = (blendmapSize/(static_cast<float>(blendmapSize)+1.f)); texMat.preMultTranslate(osg::Vec3f(0.5f, 0.5f, 0.f)); texMat.preMultScale(osg::Vec3f(scale, scale, 1.f)); texMat.preMultTranslate(osg::Vec3f(-0.5f, -0.5f, 0.f)); @@ -57,8 +57,7 @@ namespace Terrain stateset->setTextureAttributeAndModes(texunit, tex.get()); osg::ref_ptr<osg::TexMat> texMat (new osg::TexMat); - float scale = 16.f; - texMat->setMatrix(osg::Matrix::scale(osg::Vec3f(scale,scale,1.f))); + texMat->setMatrix(osg::Matrix::scale(osg::Vec3f(layerTileSize,layerTileSize,1.f))); stateset->setTextureAttributeAndModes(texunit, texMat, osg::StateAttribute::ON); firstLayer = false; @@ -67,9 +66,12 @@ namespace Terrain } } - Effect::Effect(const std::vector<osg::ref_ptr<osg::Texture2D> > &layers, const std::vector<osg::ref_ptr<osg::Texture2D> > &blendmaps) + Effect::Effect(const std::vector<osg::ref_ptr<osg::Texture2D> > &layers, const std::vector<osg::ref_ptr<osg::Texture2D> > &blendmaps, + int blendmapSize, float layerTileSize) : mLayers(layers) , mBlendmaps(blendmaps) + , mBlendmapSize(blendmapSize) + , mLayerTileSize(layerTileSize) { osg::ref_ptr<osg::Material> material (new osg::Material); material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); @@ -80,7 +82,7 @@ namespace Terrain bool Effect::define_techniques() { - addTechnique(new FixedFunctionTechnique(mLayers, mBlendmaps)); + addTechnique(new FixedFunctionTechnique(mLayers, mBlendmaps, mBlendmapSize, mLayerTileSize)); return true; } diff --git a/components/terrain/material.hpp b/components/terrain/material.hpp index b423aa8b0..1be227b0d 100644 --- a/components/terrain/material.hpp +++ b/components/terrain/material.hpp @@ -19,7 +19,7 @@ namespace Terrain public: FixedFunctionTechnique( const std::vector<osg::ref_ptr<osg::Texture2D> >& layers, - const std::vector<osg::ref_ptr<osg::Texture2D> >& blendmaps); + const std::vector<osg::ref_ptr<osg::Texture2D> >& blendmaps, int blendmapSize, float layerTileSize); protected: virtual void define_passes() {} @@ -30,7 +30,7 @@ namespace Terrain public: Effect( const std::vector<osg::ref_ptr<osg::Texture2D> >& layers, - const std::vector<osg::ref_ptr<osg::Texture2D> >& blendmaps); + const std::vector<osg::ref_ptr<osg::Texture2D> >& blendmaps, int blendmapSize, float layerTileSize); virtual bool define_techniques(); @@ -50,6 +50,8 @@ namespace Terrain private: std::vector<osg::ref_ptr<osg::Texture2D> > mLayers; std::vector<osg::ref_ptr<osg::Texture2D> > mBlendmaps; + int mBlendmapSize; + float mLayerTileSize; }; } diff --git a/components/terrain/terraingrid.cpp b/components/terrain/terraingrid.cpp index 5afb99176..7c2395566 100644 --- a/components/terrain/terraingrid.cpp +++ b/components/terrain/terraingrid.cpp @@ -7,6 +7,8 @@ #include <components/sceneutil/lightmanager.hpp> +#include <components/esm/loadland.hpp> + #include <osg/PositionAttitudeTransform> #include <osg/Geometry> #include <osg/Geode> @@ -150,7 +152,7 @@ void TerrainGrid::loadCell(int x, int y) for (unsigned int i=0; i<2; ++i) geometry->setTexCoordArray(i, mCache.getUVBuffer()); - osg::ref_ptr<osgFX::Effect> effect (new Terrain::Effect(layerTextures, blendmapTextures)); + osg::ref_ptr<osgFX::Effect> effect (new Terrain::Effect(layerTextures, blendmapTextures, ESM::Land::LAND_TEXTURE_SIZE, ESM::Land::LAND_TEXTURE_SIZE)); effect->addCullCallback(new SceneUtil::LightListCallback);