Hi Todd and Robert,

On 4/09/10 0:21 , Todd J. Furlong wrote:
> I made a couple of changes to the osgFX::Outline class (SVN patch attached).  
> I had a
> couple of issues with it that I was trying to resolve:
> 
> 1. When an outline object was occluded by another object, the backfacing 
> wireframe was
> exposed.  To fix that, I removed the disabling of GL_DEPTH_TEST.

I've modified the osgoutline example to expose the issue and have verified your 
patch and
it works as advertised.  It still is a bit odd, since the depth_test=off seems 
to bleed
from the FX into other parts of the scene.

The modified files (and the patch) is attached.

Cheers,
/ulrich
Index: src/osgFX/Outline.cpp
===================================================================
--- src/osgFX/Outline.cpp       (revision 11730)
+++ src/osgFX/Outline.cpp       (working copy)
@@ -30,7 +30,8 @@
 #include <osg/Texture1D>
 
 
-namespace {
+namespace
+{
     const unsigned int Override_On = 
osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE;
     const unsigned int Override_Off = 
osg::StateAttribute::OFF|osg::StateAttribute::OVERRIDE;
 }
@@ -71,8 +72,9 @@
             _color = color;
             if (_material.valid()) {
                 const osg::Material::Face face = osg::Material::FRONT_AND_BACK;
-                _material->setAmbient(face, color);
-                _material->setDiffuse(face, color);
+                _material->setAmbient(face, osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
+                _material->setDiffuse(face, osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
+                _material->setSpecular(face, osg::Vec4(0.0f, 0.0f, 0.0f, 
1.0f));
                 _material->setEmission(face, color);
             }
         }
@@ -119,14 +121,14 @@
                 state->setAttributeAndModes(stencil, Override_On);
 
                 // cull front-facing polys
-                osg::CullFace* cf = new osg::CullFace;
-                cf->setMode(osg::CullFace::FRONT);
-                state->setAttributeAndModes(cf, Override_On);
+                osg::CullFace* cullFace = new osg::CullFace;
+                cullFace->setMode(osg::CullFace::FRONT);
+                state->setAttributeAndModes(cullFace, Override_On);
 
                 // draw back-facing polygon lines
-                osg::PolygonMode* pm = new osg::PolygonMode;
-                pm->setMode(osg::PolygonMode::BACK, osg::PolygonMode::LINE);
-                state->setAttributeAndModes(pm, Override_On);
+                osg::PolygonMode* polyMode = new osg::PolygonMode;
+                polyMode->setMode(osg::PolygonMode::BACK, 
osg::PolygonMode::LINE);
+                state->setAttributeAndModes(polyMode, Override_On);
 
                 // outline width
                 _lineWidth = new osg::LineWidth;
@@ -135,13 +137,13 @@
 
                 // outline color/material
                 _material = new osg::Material;
-                _material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
+                _material->setColorMode(osg::Material::OFF);
                 setColor(_color);
                 state->setAttributeAndModes(_material.get(), Override_On);
 
                 // disable modes
                 state->setMode(GL_BLEND, Override_Off);
-                state->setMode(GL_DEPTH_TEST, Override_Off);
+                //state->setMode(GL_DEPTH_TEST, Override_Off);
                 state->setTextureMode(0, GL_TEXTURE_1D, Override_Off);
                 state->setTextureMode(0, GL_TEXTURE_2D, Override_Off);
                 state->setTextureMode(0, GL_TEXTURE_3D, Override_Off);
Index: examples/osgoutline/osgoutline.cpp
===================================================================
--- examples/osgoutline/osgoutline.cpp  (revision 11730)
+++ examples/osgoutline/osgoutline.cpp  (working copy)
@@ -5,6 +5,7 @@
  */
 
 #include <osg/Group>
+#include <osg/PositionAttitudeTransform>
 
 #include <osgDB/ReadFile>
 #include <osgViewer/Viewer>
@@ -18,18 +19,59 @@
     
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+"
 [options] <file>");
     arguments.getApplicationUsage()->addCommandLineOption("-h or 
--help","Display this information");
    
-    // create outline effect
-    osg::ref_ptr<osgFX::Outline> outline = new osgFX::Outline;
-    outline->setWidth(8);
-    outline->setColor(osg::Vec4(1,1,0,1));
+    // load outlined object
+    std::string modelFilename = arguments.argc() > 1 ? arguments[1] : 
"dumptruck.osg";
+    osg::ref_ptr<osg::Node> outlineModel = osgDB::readNodeFile(modelFilename);
+    if (!outlineModel)
+    {
+        osg::notify(osg::FATAL) << "Unable to load model '" << modelFilename 
<< "'\n";
+        return -1;
+    }
 
+    // load occluded object
+    std::string occludedModelFilename = "cow.osg";
+    osg::ref_ptr<osg::Node> occludedModel = 
osgDB::readNodeFile(occludedModelFilename);
+    if (!occludedModel)
+    {
+        osg::notify(osg::FATAL) << "Unable to load model '" << 
occludedModelFilename << "'\n";
+        return -1;
+    }
+
     // create scene
     osg::ref_ptr<osg::Group> root = new osg::Group;
-    root->addChild(outline.get());
 
-    osg::ref_ptr<osg::Node> model0 = osgDB::readNodeFile(arguments.argc() > 1 
? arguments[1] : "al.obj");
-    outline->addChild(model0.get());
+    {
+        // occluder behind outlined model
+        osg::ref_ptr<osg::PositionAttitudeTransform> modelTransform = new 
osg::PositionAttitudeTransform;
+        root->addChild(modelTransform.get());
 
+        // offset from outlined object
+        const osg::BoundingSphere& bsphere = outlineModel->getBound();
+        modelTransform->setPosition(bsphere.center() + osg::Vec3(0,1,0) * 
bsphere.radius() * -1.2f);
+        modelTransform->addChild(occludedModel.get());
+    }
+
+    {
+        // create outline effect
+        osg::ref_ptr<osgFX::Outline> outline = new osgFX::Outline;
+        root->addChild(outline.get());
+
+        outline->setWidth(8);
+        outline->setColor(osg::Vec4(1,1,0,1));
+        outline->addChild(outlineModel.get());
+    }
+
+    {
+        // occluder in front of outlined model
+        osg::ref_ptr<osg::PositionAttitudeTransform> modelTransform = new 
osg::PositionAttitudeTransform;
+        root->addChild(modelTransform.get());
+
+        // offset from outlined object
+        const osg::BoundingSphere& bsphere = outlineModel->getBound();
+        modelTransform->setPosition(bsphere.center() + osg::Vec3(0,1,0) * 
bsphere.radius() * 1.2f);
+        modelTransform->addChild(occludedModel.get());
+    }
+
     // must have stencil buffer...
     osg::DisplaySettings::instance()->setMinimumNumStencilBits(1);
 

Attachment: Outline.tar.gz
Description: GNU Zip compressed data

_______________________________________________
osg-submissions mailing list
osg-submissions@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to