From 162b25c1808b61103be37f406e77e637e90ab15d Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Wed, 17 Mar 2021 01:46:04 +0000 Subject: [PATCH] Fix sunglare on Mesa The sunglare works by comparing an occlusion query with depth testing on against one with depth testing off to determine if there's anything closer to the camera than the maximum depth buffer value. For the depth- tested query, the depth range is set from 1 to 1 so it's always drawn at the maximum distance. Originally, we had the depth function set to LESS, meaning that the query would always fail as 1 is not less than 1, but also glPolygonOffset was used to move the query by "the smallest value that is guaranteed to produce a resolvable offset for a given implementation" closer to the camera. While other driver and hardware combinations do that, Mesa seems to be clamping to the depth range, so still failing. Instead, it's simpler to just get rid of the polygon offset and change the depth test to LEQUAL as 1 *is* less than or equal to 1, but not than any other possible depth buffer value. --- apps/openmw/mwrender/sky.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index f82641676..5a6ec06e5 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -497,8 +497,6 @@ public: // Disable writing to the color buffer. We are using this geometry for visibility tests only. osg::ref_ptr colormask (new osg::ColorMask(0, 0, 0, 0)); stateset->setAttributeAndModes(colormask, osg::StateAttribute::ON); - osg::ref_ptr po (new osg::PolygonOffset( -1., -1. )); - stateset->setAttributeAndModes(po, osg::StateAttribute::ON); mTransform->addChild(queryNode); @@ -595,7 +593,7 @@ private: if (queryVisible) { osg::ref_ptr depth (new osg::Depth); - depth->setFunction(osg::Depth::LESS); + depth->setFunction(osg::Depth::LEQUAL); // This is a trick to make fragments written by the query always use the maximum depth value, // without having to retrieve the current far clipping distance. // We want the sun glare to be "infinitely" far away.