From 088d5604bf6fb401338994c43516cc98b3b9ff17 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 14 Mar 2017 04:07:23 +0100 Subject: [PATCH] Use a shader if required to display the composite map Fixes composited terrain not respecting the 'clamp lighting' setting. --- components/terrain/chunkmanager.cpp | 12 +++++++----- components/terrain/material.cpp | 6 ++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/components/terrain/chunkmanager.cpp b/components/terrain/chunkmanager.cpp index 85f7e26c9..e4a7c2d68 100644 --- a/components/terrain/chunkmanager.cpp +++ b/components/terrain/chunkmanager.cpp @@ -201,12 +201,14 @@ osg::ref_ptr ChunkManager::createChunk(float chunkSize, const osg::Ve mCompositeMapRenderer->addCompositeMap(compositeMap.get(), false); - std::vector > passes2; - passes2.push_back(new osg::StateSet); - passes2[0]->setTextureAttributeAndModes(0, compositeMap->mTexture, osg::StateAttribute::ON); - geometry->setPasses(passes2); - transform->getOrCreateUserDataContainer()->setUserData(compositeMap); + + TextureLayer layer; + layer.mDiffuseMap = compositeMap->mTexture; + layer.mParallax = false; + layer.mSpecular = false; + geometry->setPasses(::Terrain::createPasses(mSceneManager->getForceShaders() || !mSceneManager->getClampLighting(), mSceneManager->getForcePerPixelLighting(), + mSceneManager->getClampLighting(), &mSceneManager->getShaderManager(), std::vector(1, layer), std::vector >(), 1.f, 1.f)); } else { diff --git a/components/terrain/material.cpp b/components/terrain/material.cpp index e3e6f6de3..8aec54835 100644 --- a/components/terrain/material.cpp +++ b/components/terrain/material.cpp @@ -81,7 +81,8 @@ namespace Terrain { stateset->setTextureAttributeAndModes(texunit, it->mDiffuseMap); - stateset->setTextureAttributeAndModes(texunit, getLayerTexMat(layerTileSize), osg::StateAttribute::ON); + if (layerTileSize != 1.f) + stateset->setTextureAttributeAndModes(texunit, getLayerTexMat(layerTileSize), osg::StateAttribute::ON); stateset->addUniform(new osg::Uniform("diffuseMap", texunit)); @@ -147,7 +148,8 @@ namespace Terrain osg::ref_ptr tex = it->mDiffuseMap; stateset->setTextureAttributeAndModes(texunit, tex.get()); - stateset->setTextureAttributeAndModes(texunit, getLayerTexMat(layerTileSize), osg::StateAttribute::ON); + if (layerTileSize != 1.f) + stateset->setTextureAttributeAndModes(texunit, getLayerTexMat(layerTileSize), osg::StateAttribute::ON); } firstLayer = false;