osgearth icon indicating copy to clipboard operation
osgearth copied to clipboard

ShaderGenerator don't work model loaded black without texturing

Open mingweiLIU opened this issue 1 year ago • 5 comments

Hi, I am loading a osgb file with osgearth, I used osgEarth::Registry::shaderGenerator().run() to generate shader the node needed, while it turned out to be black, the code is: `

    osgEarth::initialize();
osgViewer::Viewer* viewer = new osgViewer::Viewer();
osg::ref_ptr<osgEarth::Map> map = new osgEarth::Map();

osgEarth::MapNode* mapNode = new osgEarth::MapNode(map.get());

osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("Tile_+006_+008.osgb");
osgEarth::Registry::shaderGenerator().run(node.get());

osg::ref_ptr<osgEarth::GeoTransform> xform = new osgEarth::GeoTransform;
xform->addChild(node);
xform->setPosition(osgEarth::GeoPoint(osgEarth::SpatialReference::create("EPSG:4326"),osg::Vec3(120,30,100)));
osg::ref_ptr < osgEarth::ModelLayer> oneModelLayer = new osgEarth::ModelLayer();
oneModelLayer->setName("test");
oneModelLayer->setNode(xform.get());
map->addLayer(oneModelLayer.get());
viewer->setSceneData(mapNode);`

the osgearth version is: [osgearth info] Hello, world. [osgearth info] [Capabilities] osgEarth Version: 3.5.0 build 150 [osgearth info] [Capabilities] GDAL Version: 3.8.1 [osgearth info] [Capabilities] OSG Version: 3.6.5 [osgearth info] [Capabilities] OSG GL3 Features: yes [osgearth info] [Capabilities] OSG FFP Available: no [osgearth info] [Capabilities] GL_VENDOR: NVIDIA Corporation [osgearth info] [Capabilities] GL_VERSION: 3.3.0 NVIDIA 528.24 [osgearth info] [Capabilities] GL CORE Profile: yes the output is: Snipaste_2024-03-17_23-39-17

mingweiLIU avatar Mar 17 '24 15:03 mingweiLIU

I don't see any obvious problems with your code -- are you able to post your .osgb file for us to look at?

gwaldron avatar Mar 19 '24 14:03 gwaldron

Tile_+006_+008.zip sorry for late reply, attached is the .osgb file

mingweiLIU avatar Mar 23 '24 13:03 mingweiLIU

I do not know why, but this model does not display correctly in the GL CORE profile. Try setting this environment variable and see if it works (Windows)

set OSG_GL_CONTEXT_PROFILE_MASK=2

gwaldron avatar Mar 27 '24 19:03 gwaldron

It is so strange, it works fine with osgviewer

mingweiLIU avatar Mar 30 '24 02:03 mingweiLIU

i've got a model with blue texture after running osgEarth::Registry::shaderGenerator().run() and i've noticed that if i zoom out and turn around the earth until the moon appeared, then nav to my model, the texture was normal. maybe some shaders were applied when the moon rendered. i don't know how to apply these shaders manually, do you guys have any ideas about it?

my code almost the same with you, but i added a SkyNode to the view

I used the vcpkg version osgearth this is my version infos: [osgEarth] [Capabilities] Capabilities: [osgEarth] [Capabilities] osgEarth Version: 3.4.0 build 148 [osgEarth] [Capabilities] OSG Version: 3.6.5 [osgEarth] [Capabilities] GDAL Version: 3.7.0 [osgEarth] [Capabilities] GEOS Version: 3.11.2 [osgEarth] [Capabilities] GPU Vendor: NVIDIA Corporation [osgEarth] [Capabilities] GPU Renderer: NVIDIA GeForce RTX 3060 Ti/PCIe/SSE2 [osgEarth] [Capabilities] GL/Driver Version: 3.3.0 NVIDIA 545.92 (330) [osgEarth] [Capabilities] GL Core Profile: yes

image

image

alexhsu avatar Apr 03 '24 11:04 alexhsu

i have the same problem:

i use vcpkg toolchain to compile osgearth

this is my osgearth's version infos:

osgearth_versiond.exe  --caps
[osgearth info] Hello, world.
[osgearth info] [Capabilities] osgEarth Version:  3.6.0 build 158
[osgearth info] [Capabilities] GDAL Version:      3.9.0
[osgearth info] [Capabilities] OSG Version:       3.6.5
[osgearth info] [Capabilities] OSG GL3 Features:  yes
[osgearth info] [Capabilities] OSG FFP Available: no
[osgearth info] [Capabilities] CPU Cores:         12
[osgearth info] [Capabilities] GL_VENDOR:         Intel
[osgearth info] [Capabilities] GL_RENDERER:       Intel(R) UHD Graphics 630
[osgearth info] [Capabilities] GL_VERSION:        3.3.0 - Build 31.0.101.2127
[osgearth info] [Capabilities] GL CORE Profile:   yes
[osgearth info] Goodbye.

my codes is :


int main(int argc, char **argv)
{
  osgEarth::initialize();
  osg::Group *root = new osg::Group;

  // create Map
  osgEarth::ProfileOptions profileOptions;
  osgEarth::RocksDBCache::RocksDBCacheOptions cacheOptions;
  cacheOptions.rootPath() = "D:/cache";
  osgEarth::Map::Options mapOptions;
  mapOptions.cache() = cacheOptions;
  mapOptions.profile() = profileOptions;
  mapOptions.cachePolicy() = osgEarth::CachePolicy::USAGE_READ_WRITE;
  osgEarth::Map *map = new osgEarth::Map(mapOptions, nullptr);
  // create MapNode
  osgEarth::MapNode *mapNode = new osgEarth::MapNode(map);
  // create osmlayer
  osgEarth::XYZImageLayer *xyzImageLayer = new osgEarth::XYZImageLayer();
  xyzImageLayer->setURL("https://......");
  xyzImageLayer->setProfile(osgEarth::Profile::create(osgEarth::Profile::SPHERICAL_MERCATOR));
  xyzImageLayer->setOpacity(1.0f);
  mapNode->getMap()->addLayer(xyzImageLayer);
  //
  root->addChild(mapNode);
  // create Viewer
  osgViewer::Viewer viewer{};
  viewer.setUpViewInWindow(0, 100, 800, 600);
  viewer.setName("load osgb to earth");
  viewer.setSceneData(root);
  osg::ref_ptr<osgEarth::Util::EarthManipulator> earthManipulator = new osgEarth::Util::EarthManipulator;
  viewer.setCameraManipulator(earthManipulator);
  //
  //
  std::string filePath = "D:/tile_24_26_OSGB/tile_24_26/Data.osgt";
  osgEarth::GeoPoint position(osgEarth::SpatialReference::get("EPSG:2326"), 836974.635391304, 815456.572217391, 0);
  osg::ref_ptr<osg::Node> osgbNode = osgDB::readNodeFile(filePath);
  // osgbNode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
  osgEarth::Registry::shaderGenerator().run(osgbNode.get());
  //
  osgEarth::GeoTransform *geoTransform = new osgEarth::GeoTransform();
  geoTransform->addChild(osgbNode);
  geoTransform->setTerrain(mapNode->getTerrain());
  geoTransform->setPosition(position);
  //
  osgEarth::ModelLayer *modelLayer = new osgEarth::ModelLayer();
  modelLayer->setNode(geoTransform);
  modelLayer->setName("osbg tiles");
  map->addLayer(modelLayer);

  // set Viewpoint
  osgEarth::Viewpoint viewpoint;
  viewpoint.focalPoint() = position;
  viewpoint.heading()->set(0.0, osgEarth::Units::DEGREES);
  viewpoint.pitch()->set(-89.0, osgEarth::Units::DEGREES);
  viewpoint.range()->set(10000, osgEarth::Units::METERS);
  viewpoint.positionOffset()->set(0, 0, 0);
  earthManipulator->setViewpoint(viewpoint);

  //
  osgEarth::Util::MapNodeHelper().configureView(&viewer);

  // event loop
  return viewer.run();
}
  
  

error-map

zyxgis avatar Jul 21 '24 10:07 zyxgis

my osgb file is

https://pdmap.pland.gov.hk/PLANDWEB/public/3d_photo_realistic_models/OSGB/tile_24_26_OSGB.zip

the osgt file is

Data.zip

please put “osgt file” into the directory which contains metadata.xml

zyxgis avatar Jul 21 '24 11:07 zyxgis

the file normally display in osgviewer

ok-map-in-osgviewer

zyxgis avatar Jul 21 '24 11:07 zyxgis

Please try adding the following just after you create you Viewer:

    #include <osgEarth/GLUtils>
    ...
    viewer.setRealizeOperation(new osgEarth::GL3RealizeOperation());

gwaldron avatar Jul 22 '24 14:07 gwaldron

@gwaldron thank you for your suggest

i have try, but the problem is not solved error-pic

zyxgis avatar Jul 22 '24 23:07 zyxgis

OK. I can confirm that this issue happens only in GL CORE profile. We are able to reproduce it with any textured model. We will continue to investigate ...

gwaldron avatar Jul 23 '24 13:07 gwaldron

In the meantime you can set this environment variable to enable the compatibility profile:

set OSG_GL_CONTEXT_PROFILE_MASK=2

See if that works around the issue.

gwaldron avatar Jul 23 '24 15:07 gwaldron

I have pushed an update that will address this. The underlying problem is that your model has no normal arrays. We decided that it makes sense to automatically add normals to model that run through the shader generator, since our shaders do expect them to be valid.

gwaldron avatar Jul 24 '24 15:07 gwaldron

@gwaldron thank you for your help

zyxgis avatar Jul 25 '24 12:07 zyxgis