Closed mingweiLIU closed 1 month ago
I don't see any obvious problems with your code -- are you able to post your .osgb file for us to look at?
Tile+006+008.zip sorry for late reply, attached is the .osgb file
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
It is so strange, it works fine with osgviewer
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
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();
}
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
please put “osgt file” into the directory which contains metadata.xml
the file normally display in osgviewer
Please try adding the following just after you create you Viewer:
#include <osgEarth/GLUtils>
...
viewer.setRealizeOperation(new osgEarth::GL3RealizeOperation());
@gwaldron thank you for your suggest
i have try, but the problem is not solved
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 ...
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.
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 thank you for your help
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: `
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: