diff --git a/apps/openmw/mwrender/water.cpp b/apps/openmw/mwrender/water.cpp index a6479c401..bf40c9567 100644 --- a/apps/openmw/mwrender/water.cpp +++ b/apps/openmw/mwrender/water.cpp @@ -9,7 +9,7 @@ namespace MWRender Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) : mCamera (camera), mViewport (camera->getViewport()), mSceneManager (camera->getSceneManager()), mIsUnderwater(false), mReflectDistance(0), mVisibilityFlags(0), mOldCameraFarClip(0), - mReflectionTarget(0), mRefractionTarget(0), mActive(1) + mReflectionTarget(0), mActive(1) { try { @@ -28,8 +28,6 @@ Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) : mWater = mSceneManager->createEntity("water"); mWater->setVisibilityFlags(RV_Water); - mWater->setMaterial(createMaterial()); - mVisibilityFlags = RV_Terrain * Settings::Manager::getBool("reflect terrain", "Water") + RV_Statics * Settings::Manager::getBool("reflect statics", "Water") + RV_StaticsSmall * Settings::Manager::getBool("reflect small statics", "Water") @@ -48,33 +46,31 @@ Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) : // Create rendertargets for reflection and refraction int rttsize = Settings::Manager::getInt("rtt size", "Water"); - for (unsigned int i = 0; i < 2; ++i) - { - if (i==0 && !Settings::Manager::getBool("reflection", "Water")) continue; - if (i==1 && !Settings::Manager::getBool("refraction", "Water")) continue; - - TexturePtr tex = TextureManager::getSingleton().createManual(i == 0 ? "WaterReflection" : "WaterRefraction", - ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, rttsize, rttsize, 0, PF_R8G8B8, TU_RENDERTARGET); - - RenderTarget* rtt = tex->getBuffer()->getRenderTarget(); - Viewport* vp = rtt->addViewport(mCamera); - vp->setOverlaysEnabled(false); - vp->setBackgroundColour(ColourValue(0.8f, 0.9f, 1.0f)); - vp->setShadowsEnabled(false); - vp->setVisibilityMask( (i == 0) ? mVisibilityFlags : RV_All); - rtt->addListener(this); + + if (Settings::Manager::getBool("reflection", "Water")) + { + TexturePtr tex = TextureManager::getSingleton().createManual("WaterReflection", + ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, rttsize, rttsize, 0, PF_R8G8B8, TU_RENDERTARGET); + + RenderTarget* rtt = tex->getBuffer()->getRenderTarget(); + Viewport* vp = rtt->addViewport(mCamera); + vp->setOverlaysEnabled(false); + vp->setBackgroundColour(ColourValue(0.8f, 0.9f, 1.0f)); + vp->setShadowsEnabled(false); + vp->setVisibilityMask( mVisibilityFlags ); + rtt->addListener(this); rtt->setActive(true); - if (i == 0) mReflectionTarget = rtt; - else mRefractionTarget = rtt; - } + mReflectionTarget = rtt; + } + + mWater->setMaterial(createMaterial()); } void Water::setActive(bool active) { mActive = active; if (mReflectionTarget) mReflectionTarget->setActive(active); - if (mRefractionTarget) mRefractionTarget->setActive(active); mWater->setVisible(active); } @@ -146,8 +142,8 @@ void Water::preRenderTargetUpdate(const RenderTargetEvent& evt) if (evt.source == mReflectionTarget) { - mCamera->enableCustomNearClipPlane(mWaterPlane); - mCamera->enableReflection(Plane(Vector3::UNIT_Y, mWaterNode->_getDerivedPosition().y)); + mCamera->enableCustomNearClipPlane(Plane(Vector3::UNIT_Y, mTop)); + mCamera->enableReflection(Plane(Vector3::UNIT_Y, mTop)); } } @@ -166,33 +162,16 @@ void Water::postRenderTargetUpdate(const RenderTargetEvent& evt) Ogre::MaterialPtr Water::createMaterial() { - MaterialPtr mat = MaterialManager::getSingleton().create("Water", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); - mat->removeAllTechniques(); - - // shader technique - Technique* tech = mat->createTechnique(); - Pass* pass = tech->createPass(); - - - // fallback technique without shaders - // also used for minimap (because it can't have reflecting water) - Technique* old = mat->createTechnique(); - old->setSchemeName("Map"); - Pass* oldpass = old->createPass(); - oldpass->setSceneBlending(SBT_TRANSPARENT_ALPHA); - oldpass->setDepthWriteEnabled(false); - oldpass->setDiffuse(0,0,0,1); - oldpass->setSelfIllumination(0.6, 0.7, 1.0); - oldpass->setAmbient(0,0,0); - TextureUnitState* oldtus = oldpass->createTextureUnitState(); + MaterialPtr mat = MaterialManager::getSingleton().getByName("Water"); + + // these have to be set in code std::string textureNames[32]; for (int i=0; i<32; ++i) { textureNames[i] = "textures\\water\\water" + StringConverter::toString(i, 2, '0') + ".dds"; } - oldtus->setAnimatedTextureName(textureNames, 32, 2); - oldtus->setTextureScale(0.1, 0.1); - oldtus->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, 0.7); + mat->getTechnique(1)->getPass(0)->getTextureUnitState(0)->setAnimatedTextureName(textureNames, 32, 2); + return mat; } diff --git a/apps/openmw/mwrender/water.hpp b/apps/openmw/mwrender/water.hpp index c4d2189ff..61519dbb9 100644 --- a/apps/openmw/mwrender/water.hpp +++ b/apps/openmw/mwrender/water.hpp @@ -33,7 +33,6 @@ namespace MWRender { Ogre::MaterialPtr createMaterial(); Ogre::RenderTarget* mReflectionTarget; - Ogre::RenderTarget* mRefractionTarget; int mVisibilityFlags; int mReflectDistance; diff --git a/files/CMakeLists.txt b/files/CMakeLists.txt index 0a38ff8b5..56c3db862 100644 --- a/files/CMakeLists.txt +++ b/files/CMakeLists.txt @@ -7,3 +7,4 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/perlinvolume.dds "${OpenMW_BINA configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/water.compositor "${OpenMW_BINARY_DIR}/resources/water/water.compositor" COPYONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/water.material "${OpenMW_BINARY_DIR}/resources/water/water.material" COPYONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/WaterNormal2.tga "${OpenMW_BINARY_DIR}/resources/water/WaterNormal2.tga" COPYONLY) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/water.cg "${OpenMW_BINARY_DIR}/resources/water/water.cg" COPYONLY) diff --git a/files/settings-default.cfg b/files/settings-default.cfg index d9c908883..914b4019d 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -46,8 +46,6 @@ num lights = 8 reflection = false -refraction = false - rtt size = 256 # 0 unlimited diff --git a/files/water/water.material b/files/water/water.material index 673bbaf56..50dfd9379 100644 --- a/files/water/water.material +++ b/files/water/water.material @@ -18,6 +18,67 @@ fragment_program Water/GlassFP cg profiles ps_2_0 arbfp1 } +vertex_program Water_VP cg +{ + source water.cg + entry_point main_vp + profiles vs_2_x arbvp1 + + default_params + { + param_named_auto wvpMat worldviewproj_matrix + } +} + +fragment_program Water_FP cg +{ + source water.cg + entry_point main_fp + profiles ps_2_x arbfp1 +} + +material Water +{ + technique + { + pass + { + scene_blend alpha_blend + depth_write off + + vertex_program_ref Water_VP + { + } + fragment_program_ref Water_FP + { + } + + texture_unit reflectionMap + { + texture WaterReflection + } + } + } + technique + { + scheme Map + pass + { + scene_blend alpha_blend + depth_write off + diffuse 0 0 0 1 + emissive 0.6 0.7 1.0 + ambient 0 0 0 + texture_unit + { + // texture names set via code + scale 0.1 0.1 + alpha_op_ex source1 src_manual src_current 0.7 + } + } + } +} + material Water/Compositor { technique