From e1e47e76ec9ea6d1e5e587e624169ab1dec35df9 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Fri, 6 Feb 2009 17:47:55 +0100 Subject: [PATCH] Turn off z buffer writes for clouds. This is standard practice for semi-transparent objects and should cut down on the flickering and other sorting artifacts. --- simgear/scene/sky/newcloud.cxx | 6 +++++- simgear/scene/util/StateAttributeFactory.cxx | 3 +++ simgear/scene/util/StateAttributeFactory.hxx | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/simgear/scene/sky/newcloud.cxx b/simgear/scene/sky/newcloud.cxx index 43ed8e69..efdf0c55 100644 --- a/simgear/scene/sky/newcloud.cxx +++ b/simgear/scene/sky/newcloud.cxx @@ -25,6 +25,7 @@ #endif #include +#include #include #include #include @@ -183,7 +184,10 @@ SGNewCloud::SGNewCloud(string type, stateSet->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON ); stateSet->setRenderBinDetails(osg::StateSet::TRANSPARENT_BIN, "DepthSortedBin"); - + // Turn off z buffer writes. Standard hack for + // semi-transparent geometry to avoid sorting / flickering + // artifacts. + stateSet->setAttributeAndModes(attribFactory->getDepthWritesDisabled()); static ref_ptr alphaFunc; static ref_ptr program; static ref_ptr baseTextureSampler; diff --git a/simgear/scene/util/StateAttributeFactory.cxx b/simgear/scene/util/StateAttributeFactory.cxx index 43e09b97..6e121c07 100644 --- a/simgear/scene/util/StateAttributeFactory.cxx +++ b/simgear/scene/util/StateAttributeFactory.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -70,6 +71,8 @@ StateAttributeFactory::StateAttributeFactory() _cullFaceFront->setDataVariance(Object::STATIC); _cullFaceBack = new CullFace(CullFace::BACK); _cullFaceBack->setDataVariance(Object::STATIC); + _depthWritesDisabled = new Depth(Depth::LESS, 0.0, 1.0, false); + _depthWritesDisabled->setDataVariance(Object::STATIC); } } diff --git a/simgear/scene/util/StateAttributeFactory.hxx b/simgear/scene/util/StateAttributeFactory.hxx index 9d55ebc0..18b1a59d 100644 --- a/simgear/scene/util/StateAttributeFactory.hxx +++ b/simgear/scene/util/StateAttributeFactory.hxx @@ -31,6 +31,7 @@ namespace osg class AlphaFunc; class BlendFunc; class CullFace; +class Depth; class ShadeModel; class Texture2D; class TexEnv; @@ -59,6 +60,8 @@ public: // cull front and back facing polygons osg::CullFace* getCullFaceFront() { return _cullFaceFront.get(); } osg::CullFace* getCullFaceBack() { return _cullFaceBack.get(); } + // Standard depth with writes disabled. + osg::Depth* getDepthWritesDisabled() { return _depthWritesDisabled.get(); } StateAttributeFactory(); protected: osg::ref_ptr _standardAlphaFunc; @@ -70,6 +73,7 @@ protected: osg::ref_ptr _white; osg::ref_ptr _cullFaceFront; osg::ref_ptr _cullFaceBack; + osg::ref_ptr _depthWritesDisabled; }; } #endif -- 2.39.5