diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 2f85d3599..362a04ca5 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -61,8 +61,12 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const CompositorManager::getSingleton().setCompositorEnabled(mRendering.getViewport(), "gbuffer", true); CompositorManager::getSingleton().addCompositor(mRendering.getViewport(), "gbufferFinalizer"); CompositorManager::getSingleton().setCompositorEnabled(mRendering.getViewport(), "gbufferFinalizer", true); + CompositorManager::getSingleton().addCompositor(mRendering.getViewport(), "Underwater"); + } + else + { + CompositorManager::getSingleton().addCompositor(mRendering.getViewport(), "UnderwaterNoMRT"); } - CompositorManager::getSingleton().addCompositor(mRendering.getViewport(), "Water"); // Turn the entire scene (represented by the 'root' node) -90 // degrees around the x axis. This makes Z go upwards, and Y go into diff --git a/apps/openmw/mwrender/water.cpp b/apps/openmw/mwrender/water.cpp index 89b40cf63..615a24a76 100644 --- a/apps/openmw/mwrender/water.cpp +++ b/apps/openmw/mwrender/water.cpp @@ -1,6 +1,7 @@ #include "water.hpp" #include #include "sky.hpp" +#include "renderingmanager.hpp" using namespace Ogre; @@ -68,6 +69,8 @@ Water::Water (Ogre::Camera *camera, SkyManager* sky, const ESM::Cell* cell) : mReflectionTarget = rtt; } + mCompositorName = RenderingManager::useMRT() ? "Underwater" : "UnderwaterNoMRT"; + createMaterial(); mWater->setMaterial(mMaterial); } @@ -118,7 +121,7 @@ void Water::checkUnderwater(float y) if ((mIsUnderwater && y > mTop) || !mWater->isVisible() || mCamera->getPolygonMode() != Ogre::PM_SOLID) { try { - CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false); + CompositorManager::getSingleton().setCompositorEnabled(mViewport, mCompositorName, false); } catch(...) {} // tell the shader we are not underwater @@ -137,7 +140,7 @@ void Water::checkUnderwater(float y) if (!mIsUnderwater && y < mTop && mWater->isVisible() && mCamera->getPolygonMode() == Ogre::PM_SOLID) { try { - CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", true); + CompositorManager::getSingleton().setCompositorEnabled(mViewport, mCompositorName, true); } catch(...) {} // tell the shader we are underwater diff --git a/apps/openmw/mwrender/water.hpp b/apps/openmw/mwrender/water.hpp index 855dd3b18..b5aa29a5b 100644 --- a/apps/openmw/mwrender/water.hpp +++ b/apps/openmw/mwrender/water.hpp @@ -34,6 +34,8 @@ namespace MWRender { SkyManager* mSky; + std::string mCompositorName; + void createMaterial(); Ogre::MaterialPtr mMaterial; diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 80035df14..0d86d36ca 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -585,8 +585,8 @@ void WeatherManager::update(float duration) int facing = (mHour > 13.f) ? 1 : -1; Vector3 final( - (1-height)*facing, - (1-height)*facing, + -(1-height)*facing, + -(1-height)*facing, height); mRendering->setSunDirection(final); @@ -606,13 +606,13 @@ void WeatherManager::update(float duration) float moonHeight = 1-std::abs((night-0.5)*2); int facing = (mHour > 0.f && mHour<12.f) ? 1 : -1; Vector3 masser( - (1-moonHeight)*facing, - (1-moonHeight)*facing, + -(1-moonHeight)*facing, + -(1-moonHeight)*facing, moonHeight); Vector3 secunda( - (1-moonHeight)*facing*0.8, - (1-moonHeight)*facing*1.25, + -(1-moonHeight)*facing*0.8, + -(1-moonHeight)*facing*1.25, moonHeight); mRendering->getSkyManager()->setMasserDirection(masser); diff --git a/files/water/water.cg b/files/water/water.cg index dfb1972ae..85c86f3b6 100644 --- a/files/water/water.cg +++ b/files/water/water.cg @@ -19,9 +19,9 @@ void main_vp oDepth = oPos.z; float4x4 scalemat = float4x4( 0.5, 0, 0, 0.5, - 0, -0.5, 0, 0.5, - 0, 0, 0.5, 0.5, - 0, 0, 0, 1 ); + 0, -0.5, 0, 0.5, + 0, 0, 0.5, 0.5, + 0, 0, 0, 1 ); float4 texcoordProj = mul(scalemat, oPos); oScreenCoords = float3(texcoordProj.x, texcoordProj.y, texcoordProj.w); diff --git a/files/water/water.compositor b/files/water/water.compositor index 67bf90896..8d9c3cb39 100644 --- a/files/water/water.compositor +++ b/files/water/water.compositor @@ -1,4 +1,4 @@ -compositor Water +compositor UnderwaterNoMRT { technique { @@ -6,6 +6,30 @@ compositor Water target rt0 { input previous } + target_output + { + // Start with clear output + input none + + pass render_quad + { + material Water/CompositorNoMRT + input 0 rt0 + } + } + } +} + + +compositor Underwater +{ + technique + { + texture_ref scene gbuffer mrt_output + texture rt0 target_width target_height PF_R8G8B8 + + target rt0 { input previous } + target_output { // Start with clear output @@ -15,7 +39,8 @@ compositor Water { material Water/Compositor input 0 rt0 + input 3 scene 1 } } } -} +} diff --git a/files/water/water.material b/files/water/water.material index cf7a414cf..3afbaacd5 100644 --- a/files/water/water.material +++ b/files/water/water.material @@ -1,21 +1,21 @@ vertex_program Water/GlassVP cg { - source GlassVP.cg - entry_point glass_vp - profiles vs_1_1 arbvp1 - - default_params - { - param_named_auto worldViewProj worldviewproj_matrix - } + source GlassVP.cg + entry_point glass_vp + profiles vs_1_1 arbvp1 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } } fragment_program Water/GlassFP cg { - source GlassFP.cg - entry_point main_ps - profiles ps_2_0 arbfp1 + source GlassFP.cg + entry_point main_ps + profiles ps_2_0 arbfp1 } vertex_program Water_VP cg @@ -104,45 +104,92 @@ material Water } } +material Water/CompositorNoMRT +{ + technique + { + pass + { + depth_check off + vertex_program_ref Water/GlassVP + { + param_named_auto timeVal time 0.25 + param_named scale float 0.1 + } + + fragment_program_ref Water/GlassFP + { + param_named tintColour float4 0 0.35 0.35 1 + } + + texture_unit RT + { + tex_coord_set 0 + tex_address_mode clamp + filtering linear linear linear + } + + texture_unit + { + texture WaterNormal2.tga 2d + tex_coord_set 1 + //tex_address_mode clamp + filtering linear linear linear + } + texture_unit + { + texture caustic_0.png 2d + tex_coord_set 2 + //tex_address_mode clamp + filtering linear linear linear + } + } + } +} + material Water/Compositor { - technique - { - pass - { - depth_check off - vertex_program_ref Water/GlassVP - { - param_named_auto timeVal time 0.25 - param_named scale float 0.1 - } - - fragment_program_ref Water/GlassFP - { - param_named tintColour float4 0 0.35 0.35 1 - } - - texture_unit RT - { - tex_coord_set 0 - tex_address_mode clamp - filtering linear linear linear - } - - texture_unit - { - texture WaterNormal2.tga 2d - tex_coord_set 1 - //tex_address_mode clamp - filtering linear linear linear - } - texture_unit - { - texture caustic_0.png 2d - tex_coord_set 2 - //tex_address_mode clamp - filtering linear linear linear - } - } - } + technique + { + pass + { + depth_check off + vertex_program_ref Water/GlassVP + { + param_named_auto timeVal time 0.25 + param_named scale float 0.1 + } + + fragment_program_ref Water/GlassFP + { + param_named tintColour float4 0 0.35 0.35 1 + } + + texture_unit RT + { + tex_coord_set 0 + tex_address_mode clamp + filtering linear linear linear + } + + texture_unit + { + texture WaterNormal2.tga 2d + tex_coord_set 2 + //tex_address_mode clamp + filtering linear linear linear + } + texture_unit + { + texture caustic_0.png 2d + tex_coord_set 3 + //tex_address_mode clamp + filtering linear linear linear + } + + texture_unit DepthMap + { + } + } + } }