]> git.mxchange.org Git - simgear.git/commitdiff
Turn off z buffer writes for clouds.
authorTim Moore <timoore@redhat.com>
Fri, 6 Feb 2009 16:47:55 +0000 (17:47 +0100)
committerTim Moore <timoore@redhat.com>
Fri, 6 Feb 2009 16:48:23 +0000 (17:48 +0100)
This is standard practice for semi-transparent objects and should cut down
on the flickering and other sorting artifacts.

simgear/scene/sky/newcloud.cxx
simgear/scene/util/StateAttributeFactory.cxx
simgear/scene/util/StateAttributeFactory.hxx

index 43ed8e696b6a80f3c1599f042c793a5b1acfc85f..efdf0c559d5768d152851092167841d6dda1c345 100644 (file)
@@ -25,6 +25,7 @@
 #endif
 
 #include <osg/AlphaFunc>
+#include <osg/Depth>
 #include <osg/Program>
 #include <osg/Uniform>
 #include <osg/ref_ptr>
@@ -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> alphaFunc;
         static ref_ptr<Program> program;
         static ref_ptr<Uniform> baseTextureSampler;
index 43e09b9738ec569f6b41ecbd6fe5771753e88aca..6e121c073d0d7765c102bccddfc32311ccbffe5d 100644 (file)
@@ -24,6 +24,7 @@
 #include <osg/Array>
 #include <osg/BlendFunc>
 #include <osg/CullFace>
+#include <osg/Depth>
 #include <osg/ShadeModel>
 #include <osg/Texture2D>
 #include <osg/TexEnv>
@@ -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);
 }
 
 }
index 9d55ebc0685467dbc55563381242b378eeea3a8c..18b1a59d811099aff1671d6071d6866c53ebaf2c 100644 (file)
@@ -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<osg::AlphaFunc> _standardAlphaFunc;
@@ -70,6 +73,7 @@ protected:
     osg::ref_ptr<osg::Vec4Array> _white;
     osg::ref_ptr<osg::CullFace> _cullFaceFront;
     osg::ref_ptr<osg::CullFace> _cullFaceBack;
+    osg::ref_ptr<osg::Depth> _depthWritesDisabled;
 };
 }
 #endif