gwaldron / osgearth

3D Maps for OpenSceneGraph / C++14
https://www.pelicanmapping.com/home-1/opensource
Other
1.47k stars 772 forks source link

featuremodelayer ignore light. #2578

Closed YHLpuyu closed 1 month ago

YHLpuyu commented 1 month ago

hi, i meet a problem that when i set no light effect in a root node of FeatureModelLayer, the polygon in layer is still with some dark region, like the polygon has been rendered with light. but I want there is no light effect Is your feature request related to a problem? Please describe. when set SimpleSkyNode->getSunLight()->setAmbient(0,0,0,1), and set featuremodellayer.getnode() is light off, the polygon in featuremodelayer alwasy has dark area. the polygon is effected by sunlight. how can i get pure color in polygon image

Describe the solution you'd like when set layer->getNode()->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED);, the polygon should has pure color, with no dark, like all gray color. below are some test code, just use the boston buildings

    OGRFeatureSource* data = new OGRFeatureSource();
    data->setName("buildings-data");
    data->setURL(BUILDINGS_URL);
    Style buildingStyle;
    buildingStyle.setName("default");
    RenderSymbol* rs = buildingStyle.getOrCreateSymbol<RenderSymbol>();
    rs->depthOffset()->enabled() = true;
    PolygonSymbol* poly = buildingStyle.getOrCreate<PolygonSymbol>();
    poly->fill()->color() = Color::White;
    LineSymbol* ls = buildingStyle.getOrCreate<LineSymbol>();
    ls->stroke()->color() = Color::Red;
    ls->stroke()->width() = 12;
    ls->stroke()->widthUnits() = Units::PIXELS;
    AltitudeSymbol* alt = buildingStyle.getOrCreate<AltitudeSymbol>();
    alt->clamping() = alt->CLAMP_TO_TERRAIN;
    alt->binding() = alt->BINDING_VERTEX;
    StyleSheet* styleSheet = new StyleSheet();
    styleSheet->addStyle(buildingStyle);
    FeatureDisplayLayout layout;
    layout.tileSize() = 500;

    FeatureModelLayer* layer = new FeatureModelLayer();
    layer->setName("Buildings");
    layer->setFeatureSource(data);
    layer->setStyleSheet(styleSheet);
    layer->setLayout(layout);
    layer->setMaxVisibleRange(20000.0);

    osg::Node* _root = layer->getNode();
    _root->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED);

    map->addLayer(layer);

// set ambient
    SkyOptions options;
    options.quality() = SkyOptions::QUALITY_HIGH;
    mapNode->addExtension(Extension::create("sky_simple", options));
    SimpleSky::SimpleSkyNode* sky = findTopMostNodeOfType<SimpleSky::SimpleSkyNode>(root);
    osg::Light* lit = sky->getSunLight();
    lit->setAmbient(osg::Vec4(0, 0, 0, 1));

the reason that i set ambient is when there have some layer with extrusionsymbol it render effect can be clear, when the face is facing the direction of light is lighter, and others is darker.

gwaldron commented 1 month ago

You might need to try the osgEarth lighting function, which supports the shaders used for the sky model. Something like:

#include <osgEarth/Lighting>
osgEarth::Lighting::set(stateSet, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
YHLpuyu commented 1 month ago

thanks, that works. now the polygon is pure .