From 37c9c12962f74fd26543b7cdf8b0063928c78e1b Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 28 Oct 2015 18:54:49 +0100 Subject: [PATCH] Water: clipping plane offset --- apps/openmw/mwrender/water.cpp | 19 ++++++++++--------- files/shaders/water_fragment.glsl | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwrender/water.cpp b/apps/openmw/mwrender/water.cpp index b2354924a..97e0df1b6 100644 --- a/apps/openmw/mwrender/water.cpp +++ b/apps/openmw/mwrender/water.cpp @@ -142,8 +142,6 @@ class ClipCullNode : public osg::Group osg::Polytope::PlaneList origPlaneList = cv->getProjectionCullingStack().back().getFrustum().getPlaneList(); - // TODO: offset plane towards the viewer to fix bleeding at the water shore - osg::Plane plane = *mCullPlane; plane.transform(*cv->getCurrentRenderStage()->getInitialViewMatrix()); @@ -175,18 +173,21 @@ class ClipCullNode : public osg::Group { osgUtil::CullVisitor* cv = static_cast(nv); osg::Vec3d eyePoint = cv->getEyePoint(); + + osg::RefMatrix* modelViewMatrix = new osg::RefMatrix(*cv->getModelViewMatrix()); + // flip the below graph if the eye point is above the plane if (mCullPlane->intersect(osg::BoundingSphere(osg::Vec3d(0,0,eyePoint.z()), 0)) > 0) { - osg::RefMatrix* modelViewMatrix = new osg::RefMatrix(*cv->getModelViewMatrix()); modelViewMatrix->preMultScale(osg::Vec3(1,1,-1)); - - cv->pushModelViewMatrix(modelViewMatrix, osg::Transform::RELATIVE_RF); - traverse(node, nv); - cv->popModelViewMatrix(); } - else - traverse(node, nv); + // move the plane back along its normal a little bit to prevent bleeding at the water shore + const float clipFudge = 5; + modelViewMatrix->preMultTranslate(mCullPlane->getNormal() * (-clipFudge)); + + cv->pushModelViewMatrix(modelViewMatrix, osg::Transform::RELATIVE_RF); + traverse(node, nv); + cv->popModelViewMatrix(); } private: diff --git a/files/shaders/water_fragment.glsl b/files/shaders/water_fragment.glsl index 01e0816bc..5860120ab 100644 --- a/files/shaders/water_fragment.glsl +++ b/files/shaders/water_fragment.glsl @@ -21,8 +21,8 @@ const float WAVE_CHOPPYNESS = 0.05; // wave choppyness const float WAVE_SCALE = 75.0; // overall wave scale const float BUMP = 0.5; // overall water surface bumpiness -const float REFL_BUMP = 0.15; // reflection distortion amount -const float REFR_BUMP = 0.06; // refraction distortion amount +const float REFL_BUMP = 0.10; // reflection distortion amount +const float REFR_BUMP = 0.07; // refraction distortion amount const float SCATTER_AMOUNT = 0.3; // amount of sunlight scattering const vec3 SCATTER_COLOUR = vec3(0.0,1.0,0.95); // colour of sunlight scattering