点深度缓冲区未正确排序

Points depth buffer not sorting properly

我是 OpenSceneGraph 的新手,我正在开发一个生成点云的应用程序。我们首先创建一个包含特定区域点的 osg::Geometry 对象,然后我们创建一个包含几何的 osg::Geode 对象,然后我们将它作为子对象添加到包含所有这些的 osg::Group地形点。然后我们将其添加为 osgViewer::Viewer 的场景数据,我们也在其中设置了我们的相机。

所以我们像这样生成 geode/geometry:

osg::ref_ptr<osg::Geometry> geometry(new osg::Geometry());
geometry->setVertexArray(vertices.get());
geometry->setColorArray(colors.get());
geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, static_cast<int>(segment_size)));
geometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
geometry->getOrCreateStateSet()->setRenderingHint(osg::StateSet::OPAQUE_BIN);
osg::ref_ptr<osg::Geode> geode(new osg::Geode());
geode->addDrawable(geometry.get());
geode->setNodeMask(TERRAIN_ENABLED_NODE_MASK);

然后我们将它添加到我们的组和查看器中,如下所示:

m_terrain_group = new osg::Group();    
m_terrain_group->addChild(geode);
m_viewer = new osgViewer::Viewer();
m_viewer->setCamera(make_camera(width(), height(), m_graphics_window_embedded));
m_viewer->setCameraManipulator(make_camera_manipulator(), true);
m_viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
m_viewer->realize();
m_viewer->setSceneData(m_terrain_group);

make_camera 函数如下所示:

osg::Camera* OsgWidget::make_camera(int width, int height, osg::GraphicsContext* graphics_context) const noexcept
{
    double aspect_ratio = static_cast<double>(width) / static_cast<double>(height);

    osg::CullSettings cull_settings;
    cull_settings.setCullingMode(osg::CullSettings::CullingModeValues::VIEW_FRUSTUM_SIDES_CULLING | osg::CullSettings::CullingModeValues::CLUSTER_CULLING);
    cull_settings.setCullMask(TERRAIN_ENABLED_NODE_MASK);

    osg::Camera* camera = new osg::Camera();
    camera->setViewport(0, 0, width, height);
    camera->setProjectionMatrixAsPerspective(m_camera_vertical_fov, aspect_ratio, m_camera_clipping_planes.first, m_camera_clipping_planes.second);
    camera->setGraphicsContext(graphics_context);
    camera->setCullSettings(cull_settings);
    camera->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
    return camera;
}

移动相机的最终结果如下所示:

如您所见,点的深度似乎很不对,平面相互进进出出。

有人知道如何解决这个问题吗?我是否在查看代码的正确部分来解决这个问题?

正如@Scheff'sCat 所建议的,深度测试未启用。添加以下行解决了我的问题。

m_terrain_group->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);