From b882c03adc95d5ed9a6b888d69084aff2b5bc2d2 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 2 Mar 2012 23:36:48 +0100 Subject: [PATCH 1/2] fixed terrain regions without vertexcolours, tweaked maxPixelError --- apps/openmw/mwrender/terrain.cpp | 32 +++++++++++++++--------- apps/openmw/mwrender/terrain.hpp | 3 +++ apps/openmw/mwrender/terrainmaterial.cpp | 8 +++--- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwrender/terrain.cpp b/apps/openmw/mwrender/terrain.cpp index 9cc0a9f370..ca218388f5 100644 --- a/apps/openmw/mwrender/terrain.cpp +++ b/apps/openmw/mwrender/terrain.cpp @@ -27,13 +27,12 @@ namespace MWRender Ogre::TerrainMaterialGenerator::Profile* const activeProfile = mTerrainGlobals->getDefaultMaterialGenerator() ->getActiveProfile(); - TerrainMaterialGeneratorB::SM2Profile* matProfile = + mActiveProfile = static_cast(activeProfile); //The pixel error should be as high as possible without it being noticed - //as it governs how fast mesh quality decreases. 16 was just about Ok - //when tested at the small swamp pond in Seyda Neen - mTerrainGlobals->setMaxPixelError(16); + //as it governs how fast mesh quality decreases. + mTerrainGlobals->setMaxPixelError(8); mTerrainGlobals->setLayerBlendMapSize(32); mTerrainGlobals->setLightMapSize(256); @@ -47,12 +46,11 @@ namespace MWRender //this seemed the distance where it wasn't too noticeable mTerrainGlobals->setCompositeMapDistance(mWorldSize*2); - matProfile->setLightmapEnabled(false); - matProfile->setLayerSpecularMappingEnabled(false); - matProfile->setLayerNormalMappingEnabled(false); - matProfile->setLayerParallaxMappingEnabled(false); - matProfile->setReceiveDynamicShadowsEnabled(false); - matProfile->setGlobalColourMapEnabled(true); + mActiveProfile->setLightmapEnabled(false); + mActiveProfile->setLayerSpecularMappingEnabled(false); + mActiveProfile->setLayerNormalMappingEnabled(false); + mActiveProfile->setLayerParallaxMappingEnabled(false); + mActiveProfile->setReceiveDynamicShadowsEnabled(false); mTerrainGroup = OGRE_NEW Ogre::TerrainGroup(mgr, Ogre::Terrain::ALIGN_X_Z, @@ -156,15 +154,25 @@ namespace MWRender numTextures, indexes); + // disable or enable global colour map (depends on available vertex colours) if ( store->land[1][1]->landData->usingColours ) - { + mActiveProfile->setGlobalColourMapEnabled(true); + else + mActiveProfile->setGlobalColourMapEnabled(false); + + /// \todo are we possibly generating the materials twice? + mActiveProfile->generate(terrain); + mActiveProfile->generateForCompositeMap(terrain); + + if ( store->land[1][1]->landData->usingColours ) + { Ogre::TexturePtr vertex = getVertexColours(store, x*(mLandSize-1), y*(mLandSize-1), mLandSize); //this is a hack to get around the fact that Ogre seems to - //corrupt the composite map leading to rendering errors + //corrupt the global colour map leading to rendering errors MaterialPtr mat = terrain->_getMaterial(); mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName( vertex->getName() ); mat = terrain->_getCompositeMapMaterial(); diff --git a/apps/openmw/mwrender/terrain.hpp b/apps/openmw/mwrender/terrain.hpp index 6d98655400..397c0c473f 100644 --- a/apps/openmw/mwrender/terrain.hpp +++ b/apps/openmw/mwrender/terrain.hpp @@ -2,6 +2,7 @@ #define _GAME_RENDER_TERRAIN_H #include +#include "terrainmaterial.hpp" #include "../mwworld/ptr.hpp" @@ -34,6 +35,8 @@ namespace MWRender{ Ogre::TerrainGlobalOptions* mTerrainGlobals; Ogre::TerrainGroup* mTerrainGroup; + Ogre::TerrainMaterialGeneratorB::SM2Profile* mActiveProfile; + /** * The length in verticies of a single terrain block. */ diff --git a/apps/openmw/mwrender/terrainmaterial.cpp b/apps/openmw/mwrender/terrainmaterial.cpp index 0edc23a71b..67ebf45af6 100644 --- a/apps/openmw/mwrender/terrainmaterial.cpp +++ b/apps/openmw/mwrender/terrainmaterial.cpp @@ -134,7 +134,7 @@ namespace Ogre if (enabled != mGlobalColourMapEnabled) { mGlobalColourMapEnabled = enabled; - mParent->_markChanged(); + //mParent->_markChanged(); } } //--------------------------------------------------------------------- @@ -359,7 +359,7 @@ namespace Ogre tu->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); // global colour map - //if (terrain->getGlobalColourMapEnabled() && isGlobalColourMapEnabled()) + if (isGlobalColourMapEnabled()) { tu = pass->createTextureUnitState(""); tu->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); @@ -1004,7 +1004,7 @@ namespace Ogre "uniform sampler2D globalNormal : register(s" << currentSamplerIdx++ << ")\n"; - //if (terrain->getGlobalColourMapEnabled() && prof->isGlobalColourMapEnabled()) + if (prof->isGlobalColourMapEnabled()) { outStream << ", uniform sampler2D globalColourMap : register(s" << currentSamplerIdx++ << ")\n"; @@ -1299,7 +1299,7 @@ namespace Ogre } else { - //if (terrain->getGlobalColourMapEnabled() && prof->isGlobalColourMapEnabled()) + if (prof->isGlobalColourMapEnabled()) { // sample colour map and apply to diffuse outStream << " diffuse *= tex2D(globalColourMap, uv).rgb;\n"; From a8939bc3180a8475be9dd38878228c924a31e9b0 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 4 Mar 2012 00:08:56 +0100 Subject: [PATCH 2/2] disabled the composite map, improves loading time a lot --- apps/openmw/mwrender/terrain.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwrender/terrain.cpp b/apps/openmw/mwrender/terrain.cpp index ca218388f5..a66b4ad3f0 100644 --- a/apps/openmw/mwrender/terrain.cpp +++ b/apps/openmw/mwrender/terrain.cpp @@ -51,6 +51,7 @@ namespace MWRender mActiveProfile->setLayerNormalMappingEnabled(false); mActiveProfile->setLayerParallaxMappingEnabled(false); mActiveProfile->setReceiveDynamicShadowsEnabled(false); + mActiveProfile->setCompositeMapEnabled(false); mTerrainGroup = OGRE_NEW Ogre::TerrainGroup(mgr, Ogre::Terrain::ALIGN_X_Z, @@ -160,10 +161,6 @@ namespace MWRender else mActiveProfile->setGlobalColourMapEnabled(false); - /// \todo are we possibly generating the materials twice? - mActiveProfile->generate(terrain); - mActiveProfile->generateForCompositeMap(terrain); - if ( store->land[1][1]->landData->usingColours ) { Ogre::TexturePtr vertex = getVertexColours(store, @@ -173,10 +170,10 @@ namespace MWRender //this is a hack to get around the fact that Ogre seems to //corrupt the global colour map leading to rendering errors - MaterialPtr mat = terrain->_getMaterial(); - mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName( vertex->getName() ); - mat = terrain->_getCompositeMapMaterial(); + MaterialPtr mat = terrain->getMaterial(); mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName( vertex->getName() ); + //mat = terrain->_getCompositeMapMaterial(); + //mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName( vertex->getName() ); } } }