From 499f3ac0d18165cdf0079fa5c711aa390993fd42 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 5 Feb 2013 16:40:41 +0100 Subject: [PATCH] Slightly better ripple normal blending. Not physically accurate at all, but looks good. --- apps/openmw/mwrender/ripplesimulation.cpp | 10 +++++++--- apps/openmw/mwrender/ripplesimulation.hpp | 2 ++ apps/openmw/mwrender/water.cpp | 3 ++- files/materials/water.shader | 7 ++++--- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwrender/ripplesimulation.cpp b/apps/openmw/mwrender/ripplesimulation.cpp index 043757e88..249397005 100644 --- a/apps/openmw/mwrender/ripplesimulation.cpp +++ b/apps/openmw/mwrender/ripplesimulation.cpp @@ -20,7 +20,8 @@ RippleSimulation::RippleSimulation(Ogre::SceneManager* mainSceneManager) mTextureSize(512), mRippleAreaLength(1000), mImpulseSize(20), - mTexelOffset(0,0) + mTexelOffset(0,0), + mFirstUpdate(true) { Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); @@ -106,7 +107,7 @@ void RippleSimulation::update(float dt, Ogre::Vector2 position) // try to keep 20 fps mTime += dt; - while (mTime >= 1/20.0) + while (mTime >= 1/20.0 || mFirstUpdate) { mPreviousFrameOffset = mCurrentFrameOffset; @@ -130,7 +131,10 @@ void RippleSimulation::update(float dt, Ogre::Vector2 position) heightMapToNormalMap(); swapHeightMaps(); - mTime -= 1/20.0; + if (!mFirstUpdate) + mTime -= 1/20.0; + else + mFirstUpdate = false; } sh::Factory::getInstance().setSharedParameter("rippleCenter", sh::makeProperty( diff --git a/apps/openmw/mwrender/ripplesimulation.hpp b/apps/openmw/mwrender/ripplesimulation.hpp index 72ff3dbd8..c792a3214 100644 --- a/apps/openmw/mwrender/ripplesimulation.hpp +++ b/apps/openmw/mwrender/ripplesimulation.hpp @@ -34,6 +34,8 @@ private: float mRippleAreaLength; float mImpulseSize; + bool mFirstUpdate; + Ogre::Camera* mCamera; // own scenemanager to render our simulation diff --git a/apps/openmw/mwrender/water.cpp b/apps/openmw/mwrender/water.cpp index 433aa8af8..4ff8945ac 100644 --- a/apps/openmw/mwrender/water.cpp +++ b/apps/openmw/mwrender/water.cpp @@ -401,7 +401,8 @@ void Water::update(float dt, Ogre::Vector3 player) mRendering->getSkyManager ()->setGlareEnabled (!mIsUnderwater); - if (player.y <= mTop) + /// \todo player.y is the scene node position (which is above the head) and not the feet position + //if (player.y <= mTop) { mSimulation->addImpulse(Ogre::Vector2(player.x, player.z)); } diff --git a/files/materials/water.shader b/files/materials/water.shader index b02b4761c..400fbefb2 100644 --- a/files/materials/water.shader +++ b/files/materials/water.shader @@ -120,8 +120,8 @@ #define WAVE_SCALE 75 // overall wave scale #define BUMP 1.5 // overall water surface bumpiness - #define REFL_BUMP 0.16 // reflection distortion amount - #define REFR_BUMP 0.12 // refraction distortion amount + #define REFL_BUMP 0.08 // reflection distortion amount + #define REFR_BUMP 0.06 // refraction distortion amount #define SCATTER_AMOUNT 3.0 // amount of sunlight scattering #define SCATTER_COLOUR float3(0.0,1.0,0.95) // colour of sunlight scattering @@ -232,7 +232,8 @@ float3 normal_ripple = normalize(shSample(rippleNormalMap, relPos.xy).xyz * 2 - 1); normal_ripple = normal_ripple.xzy; - normal = normalize(normal + normal_ripple); + //normal = normalize(normal + normal_ripple); + normal = normalize(float3(normal.x + normal_ripple.x, normal.y, normal.z + normal_ripple.z)); // normal for sunlight scattering