Problems with lighting

classic Classic list List threaded Threaded
3 messages Options
Xtof Xtof
Reply | Threaded
Open this post in threaded view
|

Problems with lighting

Hi all,

I'm trying several ways to add lights to my scene.

1. Using GLSky with MapNode::addExtension method:
osgEarth::Config config("Sky");
osgEarth::ConfigOptions configOptions(config);
osgEarth::Drivers::GLSky::GLSkyOptions glSkyOptions(configOptions);
mapNode->addExtension(osgEarth::Extension::create("sky_gl", glSkyOptions));

This seems to be fine.

2. Using GLSky without MapNode::addExtension method:
osgEarth::Config config("Sky");
osgEarth::ConfigOptions configOptions(config);
osgEarth::Drivers::GLSky::GLSkyOptions glSkyOptions(configOptions);
osg::ref_ptr<osgEarth::Util::SkyNode> glSky = osgEarth::Util::SkyNode::create(glSkyOptions, mapNode.get());
glSky->setLighting(osg::StateAttribute::OFF);
mapNode->addChild(glSky.get());

This doesn't work, but if I replace mapNode->addChild(glSky.get()) by glSky->addChild(mapNode.get()), it seems to be fine again.

3. Using my own light based on osgearth_lights.cpp example:
osg::ref_ptr<osg::Group> lights = new osg::Group();
osgEarth::Util::Ephemeris ephemeris;
osgEarth::DateTime date(2016, 8, 10, 14.0);
osg::Vec3d world = ephemeris.getSunPositionECEF(date);
osg::ref_ptr<osg::Light> sun = new osg::Light(0);
sun->setAmbient(osg::Vec4(0.2f, 0.2f, 0.2f, 1.f));
sun->setDiffuse(osg::Vec4(1.f, 1.f, 0.9f, 1.f));
world.normalize();
sun->setDirection(-world);
osg::ref_ptr<osg::LightSource> lightSource = new osg::LightSource();
lightSource->setLight(sun.get());
lights->addChild(lightSource.get());
osgEarth::GenerateGL3LightingUniforms generator;
lights->accept(generator);
mapNode->addChild(lights.get());
This doesn't work either (same display as above), even when replacing mapNode->addChild(lights.get()) by lights->addChild(mapNode.get())

Any idea why points 2. and 3. don't work as expected?
Is there something I'm doing wrong?

Thanks,
Christophe
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Problems with lighting

Christophe,

A Sky node lights its children. So it must be an ancestor of MapNode to light the map/terrain.

Are you using a projected map? The built-in sky implementations, and the Ephemeris classes as well, only work correctly in a geocentric environment.
Glenn Waldron / Pelican Mapping
Xtof Xtof
Reply | Threaded
Open this post in threaded view
|

Re: Problems with lighting

Hi Glenn,

Thanks for your reply.

So putting MapNode as child of SkyNode makes lighting working.
But in this cas, osgearth_lights.cpp provided with the master version doesn't do the work correctly!
int
addLights(MapNode* mapNode, int lightNum)
{
    ...
    osg::Group* lights = new osg::Group();
    ...
    mapNode->addChild(lights);
    ...
}


I've tried built-in sky implementations in a geocentric environment, but it doesn't work.
I've also tried to add a red spot light and a green point light as mentioned in osgearth_lights.cpp, but it doesn't work either (on a projected map and in a geocentric environment).
Any advices?

Thanks,
Christophe