From a727bcd4a405c1d9007b00d609114cb39b7c98cd Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 11 Apr 2012 20:13:15 +0200 Subject: [PATCH] override nif transparency settings (part 1) --- CMakeLists.txt | 4 ++ apps/openmw/engine.cpp | 8 +++ components/CMakeLists.txt | 4 ++ components/nifogre/ogre_nif_loader.cpp | 19 ++++-- components/nifoverrides/nifoverrides.cpp | 37 ++++++++++ components/nifoverrides/nifoverrides.hpp | 23 +++++++ files/transparency-overrides.cfg | 86 ++++++++++++++++++++++++ 7 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 components/nifoverrides/nifoverrides.cpp create mode 100644 components/nifoverrides/nifoverrides.hpp create mode 100644 files/transparency-overrides.cfg diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b87e35447..21de30bac8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -227,6 +227,9 @@ endif (APPLE) configure_file(${OpenMW_SOURCE_DIR}/files/settings-default.cfg "${OpenMW_BINARY_DIR}/settings-default.cfg") +configure_file(${OpenMW_SOURCE_DIR}/files/transparency-overrides.cfg + "${OpenMW_BINARY_DIR}/transparency-overrides.cfg") + configure_file(${OpenMW_SOURCE_DIR}/files/openmw.cfg.local "${OpenMW_BINARY_DIR}/openmw.cfg") configure_file(${OpenMW_SOURCE_DIR}/files/openmw.cfg @@ -308,6 +311,7 @@ if(DPKG_PROGRAM) #Install global configuration files INSTALL(FILES "${OpenMW_BINARY_DIR}/settings-default.cfg" DESTINATION "../etc/openmw/" PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ COMPONENT "openmw") + INSTALL(FILES "${OpenMW_BINARY_DIR}/transparency-overrides.cfg" DESTINATION "../etc/openmw/" PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ COMPONENT "openmw") INSTALL(FILES "${OpenMW_BINARY_DIR}/openmw.cfg.install" DESTINATION "../etc/openmw/" RENAME "openmw.cfg" PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ COMPONENT "openmw") INSTALL(FILES "${OpenMW_BINARY_DIR}/plugins.cfg" DESTINATION "../etc/openmw/" PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ COMPONENT "openmw") diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 1adcf8dcac..d5ff165f82 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -349,6 +350,13 @@ void OMW::Engine::go() mFpsLevel = settings.getInt("fps", "HUD"); + // load nif overrides + NifOverrides::Overrides nifOverrides; + if (boost::filesystem::exists(mCfgMgr.getLocalPath().string() + "/transparency-overrides.cfg")) + nifOverrides.loadTransparencyOverrides(mCfgMgr.getLocalPath().string() + "/transparency-overrides.cfg"); + else if (boost::filesystem::exists(mCfgMgr.getGlobalPath().string() + "/transparency-overrides.cfg")) + nifOverrides.loadTransparencyOverrides(mCfgMgr.getGlobalPath().string() + "/transparency-overrides.cfg"); + mOgre->configure(!boost::filesystem::is_regular_file(mCfgMgr.getOgreConfigPath()), mCfgMgr.getOgreConfigPath().string(), mCfgMgr.getLogPath().string(), diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index b48c50640c..8a1875d0fb 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -6,6 +6,10 @@ add_component_dir (settings settings ) +add_component_dir (nifoverrides + nifoverrides + ) + add_component_dir (bsa bsa_archive bsa_file ) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 02e4e5447e..6f51427968 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -26,6 +26,7 @@ #include "ogre_nif_loader.hpp" #include +#include typedef unsigned char ubyte; @@ -282,11 +283,21 @@ void NIFLoader::createMaterial(const String &name, // other values. 237 basically means normal transparencly. if (alphaFlags == 237) { - // Enable transparency - pass->setSceneBlending(SBT_TRANSPARENT_ALPHA); + NifOverrides::TransparencyResult result = NifOverrides::Overrides::getTransparencyOverride(texName); + if (result.first) + { + pass->setAlphaRejectFunction(CMPF_GREATER_EQUAL); + pass->setAlphaRejectValue(result.second); + } + else + { + // Enable transparency + pass->setSceneBlending(SBT_TRANSPARENT_ALPHA); - //pass->setDepthCheckEnabled(false); - pass->setDepthWriteEnabled(false); + //pass->setDepthCheckEnabled(false); + pass->setDepthWriteEnabled(false); + std::cout << "alpha 237; material: " << name << " texName: " << texName << std::endl; + } } else warn("Unhandled alpha setting for texture " + texName); diff --git a/components/nifoverrides/nifoverrides.cpp b/components/nifoverrides/nifoverrides.cpp new file mode 100644 index 0000000000..1c8fefd24a --- /dev/null +++ b/components/nifoverrides/nifoverrides.cpp @@ -0,0 +1,37 @@ +#include "nifoverrides.hpp" + +#include + +#include + +using namespace NifOverrides; + +Ogre::ConfigFile Overrides::mTransparencyOverrides = Ogre::ConfigFile(); + +void Overrides::loadTransparencyOverrides (const std::string& file) +{ + mTransparencyOverrides.load(file); +} + +TransparencyResult Overrides::getTransparencyOverride(const std::string& texture) +{ + TransparencyResult result; + result.first = false; + + std::string tex = texture; + boost::to_lower(tex); + + Ogre::ConfigFile::SectionIterator seci = mTransparencyOverrides.getSectionIterator(); + while (seci.hasMoreElements()) + { + Ogre::String sectionName = seci.peekNextKey(); + if (sectionName == tex) + { + result.first = true; + result.second = Ogre::StringConverter::parseInt(mTransparencyOverrides.getSetting("alphaRejectValue", sectionName)); + break; + } + seci.getNext(); + } + return result; +} diff --git a/components/nifoverrides/nifoverrides.hpp b/components/nifoverrides/nifoverrides.hpp new file mode 100644 index 0000000000..c9b711df67 --- /dev/null +++ b/components/nifoverrides/nifoverrides.hpp @@ -0,0 +1,23 @@ +#ifndef COMPONENTS_NIFOVERRIDES_H +#define COMPONENTS_NIFOVERRIDES_H + +#include + +namespace NifOverrides +{ + + typedef std::pair TransparencyResult; + + /// \brief provide overrides for some model / texture properties that bethesda has chosen poorly + class Overrides + { + public: + static Ogre::ConfigFile mTransparencyOverrides; + void loadTransparencyOverrides (const std::string& file); + + static TransparencyResult getTransparencyOverride(const std::string& texture); + }; + +} + +#endif diff --git a/files/transparency-overrides.cfg b/files/transparency-overrides.cfg new file mode 100644 index 0000000000..7750e98347 --- /dev/null +++ b/files/transparency-overrides.cfg @@ -0,0 +1,86 @@ +# Bethesda has used wrong transparency settings for many textures +# (who would have guessed) +# This is very unfortunate because objects with real transparency: +# - cannot cast shadows +# - cannot receive advanced framebuffer effects like depth of field or ambient occlusion +# - cannot cover lens flare effects (the lens flare will just shine through) + +# This file lists textures that should be using alpha rejection instead of transparency +# basically these are textures that are not translucent (i.e. at one spot on the texture, either transparent or opaque) + +# Note: all the texture names here have to be lowercase + +[textures\tx_flag_imp_01.dds] + alphaRejectValue = 128 + +[textures\tx_ivy_02.dds] + alphaRejectValue = 128 + +[textures\tx_ivy_01.dds] + alphaRejectValue = 128 + +[textures\tx_sail.dds] + alphaRejectValue = 128 + +[textures\tx_saltrice_04.dds] + alphaRejectValue = 128 + +[textures\tx_black_lichen_01.dds] + alphaRejectValue = 128 + +[textures\tx_leaves_01.dds] + alphaRejectValue = 128 + +[textures\tx_leaves_02.dds] + alphaRejectValue = 128 + +[textures\tx_leaves_03.dds] + alphaRejectValue = 128 + +[textures\tx_ai_heather_01.dds] + alphaRejectValue = 96 + +[textures\tx_goldkanet_01.dds] + alphaRejectValue = 128 + +[textures\tx_goldkanet_02.dds] + alphaRejectValue = 128 + +[textures\tx_plant_tails00.dds] + alphaRejectValue = 128 + +[textures\tx_vine_01.dds] + alphaRejectValue = 128 + +[textures\tx_comberry_01.dds] + alphaRejectValue = 128 + +[textures\tx_willow_flower_02.dds] + alphaRejectValue = 128 + +[textures\tx_cork_bulb_02.dds] + alphaRejectValue = 128 + +[textures\tx_v_b_telvanni_01.dds] + alphaRejectValue = 128 + +[textures\tx_green_lichen_01.dds] + alphaRejectValue = 128 + +[textures\tx_roobrush_01.dds] + alphaRejectValue = 128 + +[textures\tx_bittergreen_02.dds] + alphaRejectValue = 128 + +[textures\tx_chokeweed_01.dds] + alphaRejectValue = 128 + +[textures\tx_de_banner_book_01.dds] + alphaRejectValue = 128 + +[textures\tx_bannerd_w_a_shop_01.dds] + alphaRejectValue = 128 + +[textures\tx_banner_temple_02.dds] + alphaRejectValue = 128