1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-21 18:39:40 +00:00

Fix applying of plane height in ClipCullNode (Fixes #2985)

This commit is contained in:
scrawl 2015-11-02 01:23:21 +01:00
parent 3f988327c7
commit 0348b8df1c

View file

@ -145,14 +145,18 @@ class ClipCullNode : public osg::Group
osg::RefMatrix* modelViewMatrix = new osg::RefMatrix(*cv->getModelViewMatrix()); osg::RefMatrix* modelViewMatrix = new osg::RefMatrix(*cv->getModelViewMatrix());
// move the plane back along its normal a little bit to prevent bleeding at the water shore
const float clipFudge = -5;
// now apply the height of the plane
// we can't apply this height in the addClipPlane() since the "flip the below graph" function would otherwise flip the height as well
float translate = clipFudge + ((*mCullPlane)[3] * -1);
modelViewMatrix->preMultTranslate(mCullPlane->getNormal() * translate);
// flip the below graph if the eye point is above the plane // 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) if (mCullPlane->intersect(osg::BoundingSphere(osg::Vec3d(0,0,eyePoint.z()), 0)) > 0)
{ {
modelViewMatrix->preMultScale(osg::Vec3(1,1,-1)); modelViewMatrix->preMultScale(osg::Vec3(1,1,-1));
} }
// 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); cv->pushModelViewMatrix(modelViewMatrix, osg::Transform::RELATIVE_RF);
traverse(node, nv); traverse(node, nv);
@ -168,7 +172,7 @@ public:
{ {
addCullCallback (new PlaneCullCallback(&mPlane)); addCullCallback (new PlaneCullCallback(&mPlane));
mClipNodeTransform = new osg::PositionAttitudeTransform; mClipNodeTransform = new osg::Group;
mClipNodeTransform->addCullCallback(new FlipCallback(&mPlane)); mClipNodeTransform->addCullCallback(new FlipCallback(&mPlane));
addChild(mClipNodeTransform); addChild(mClipNodeTransform);
@ -184,12 +188,12 @@ public:
mPlane = plane; mPlane = plane;
mClipNode->getClipPlaneList().clear(); mClipNode->getClipPlaneList().clear();
mClipNode->addClipPlane(new osg::ClipPlane(0, mPlane)); mClipNode->addClipPlane(new osg::ClipPlane(0, osg::Plane(mPlane.getNormal(), 0))); // mPlane.d() applied in FlipCallback
mClipNode->setStateSetModes(*getOrCreateStateSet(), osg::StateAttribute::ON); mClipNode->setStateSetModes(*getOrCreateStateSet(), osg::StateAttribute::ON);
} }
private: private:
osg::ref_ptr<osg::PositionAttitudeTransform> mClipNodeTransform; osg::ref_ptr<osg::Group> mClipNodeTransform;
osg::ref_ptr<osg::ClipNode> mClipNode; osg::ref_ptr<osg::ClipNode> mClipNode;
osg::Plane mPlane; osg::Plane mPlane;
@ -205,7 +209,7 @@ public:
} }
}; };
/// Moves water mesh away from the camera slightly if the camera gets to close on the Z axis. /// Moves water mesh away from the camera slightly if the camera gets too close on the Z axis.
/// The offset works around graphics artifacts that occured with the GL_DEPTH_CLAMP when the camera gets extremely close to the mesh (seen on NVIDIA at least). /// The offset works around graphics artifacts that occured with the GL_DEPTH_CLAMP when the camera gets extremely close to the mesh (seen on NVIDIA at least).
/// Must be added as a Cull callback. /// Must be added as a Cull callback.
class FudgeCallback : public osg::NodeCallback class FudgeCallback : public osg::NodeCallback
@ -215,7 +219,7 @@ public:
{ {
osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(nv); osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(nv);
const float fudge = 0.1; const float fudge = 0.2;
if (std::abs(cv->getEyeLocal().z()) < fudge) if (std::abs(cv->getEyeLocal().z()) < fudge)
{ {
float diff = fudge - cv->getEyeLocal().z(); float diff = fudge - cv->getEyeLocal().z();