is this z-fighting problem?

classic Classic list List threaded Threaded
1 message Options
edwards edwards
Reply | Threaded
Open this post in threaded view
|

is this z-fighting problem?

hi there~ I'm newbie to osg&osgEarth, I had a lot confusion recently when I add an to an earth.Here is the screen gif I captured.
 if the image did not animate use this link.

The osg::Geode I created was a triangle grid had almost 10k vertices.While the GRID I created was zooming in /out, it would be sometimes disappeared .At first I thought it may be z-fighting problem, so I add an offset(400) to elevation , BUT the problem is still on. On the other hand, I found a polygon created by osgEarth::ModelLayer which loaded from a SHP file worked fine.Could you give me a clue?Thank U in advance
--------------below is the code I create this geode-------------------
    osg::ref_ptr<osg::Geometry> geo = new osg::Geometry;
    osg::ref_ptr<osg::Vec3Array> geoPt = new osg::Vec3Array();

    const osgEarth::SpatialReference *srs = mapNode->getMapSRS();
//vertex is the input vertex vector
    geoPt->resize(vertex->size());
    std::transform(vertex->begin(), vertex->end(), geoPt->begin(),
                   [&](osg::Vec3f &v)->osg::Vec3f
                   {
                       osgEarth::Annotation::GeoPoint pt =
                           osgEarth::Annotation::GeoPoint(
                               srs,
                               v.x(),
                               v.z(),
                               v.y() + 400,
                               osgEarth::ALTMODE_ABSOLUTE);
                       osg::Vec3d geopt;
                       pt.toWorld(geopt);
                       return geopt;

                   });
    geo->setVertexArray(geoPt);
    geo->addPrimitiveSet(indice);

    if(!color)
    {
        osg::ref_ptr<osg::Vec4Array> _clr = new osg::Vec4Array;
        _clr->push_back(osg::Vec4(1.f, 1.f, 0.f, 0.f));
        geo->setColorArray(_clr);
    }
    else
        geo->setColorArray(color);
    geo->setColorBinding(osg::Geometry::BIND_OVERALL);

    osg::ref_ptr<osg::Vec3Array> norm = new osg::Vec3Array;
    norm->push_back(osg::Vec3(0.f, -1.f, 0.f));
    geo->setNormalArray(norm, osg::Array::BIND_OVERALL);
    geode->addDrawable(geo);

    osg::ref_ptr<osg::StateSet> stateset = geode->getOrCreateStateSet();
    stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
//    stateset->setRenderingHint(osg::StateSet::OPAQUE_BIN);
    // z-fighting
//    stateset->setAttributeAndModes(new osg::PolygonOffset(1,0), 1);
//    stateset->setAttributeAndModes(new osg::Depth(osg::Depth::LEQUAL, 0, 1, false));

    //
    osg::ref_ptr<osg::PolygonMode> polyMode = new osg::PolygonMode(osg::PolygonMode::FRONT,
                                                                 osg::PolygonMode::LINE);
    stateset->setAttributeAndModes(polyMode, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);


    root->addChild(geode);
--------------------------------------
My platform:
win10 64bit
INTEL HD Graphic 4000  
osg 3.5.5 osgearth 2.8
I create global by code directly ,not earth file