osg::Group*
addLights(osg::View* view, osg::Node* root, int lightNum)
{
    MapNode* mapNode = MapNode::get(root);
    const SpatialReference* mapsrs = mapNode->getMapSRS();
    const SpatialReference* geosrs = mapsrs->getGeographicSRS();
    
    osg::Vec3d world;
    osg::Group* lights = new osg::Group();

    // Add a directional light that simulates the sun - but skip this if a sky
    // was already added in the earth file.
    if (lightNum == 0)
    {
        Ephemeris e;
        DateTime dt(2016, 8, 10, 14.0);
        CelestialBody sun = e.getSunPosition(dt);
        world = sun.geocentric;

        osg::Light* sunLight = new osg::Light(lightNum++);
        world.normalize();
        sunLight->setPosition(osg::Vec4d(world, 0.0));

        sunLight->setAmbient(osg::Vec4(0.2, 0.2, 0.2, 1.0));
        sunLight->setDiffuse(osg::Vec4(1.0, 1.0, 0.9, 1.0));

        osg::LightSource* sunLS = new osg::LightSource();
        sunLS->setLight(sunLight);

        lights->addChild( sunLS );

        ShadowCaster* caster = osgEarth::findTopMostNodeOfType<ShadowCaster>(root);
        if (caster)
        {
            OE_INFO << "Found a shadow caster!\n";
            caster->setLight(sunLight);
        }
    }

#if 1
    // A red spot light. A spot light has a real position in space 
    // and points in a specific direciton. The Cutoff and Exponent
    // properties control the cone angle and sharpness, respectively
    {
        GeoPoint p(geosrs, -121, 34, 5000000., ALTMODE_ABSOLUTE);
        p.toWorld(world);

        osg::Light* spot = new osg::Light(lightNum++);    
        spot->setPosition(worldToVec4(world));
        spot->setAmbient(osg::Vec4(0,0.2,0,1));
        spot->setDiffuse(osg::Vec4(1,0,0,1));
        spot->setSpotCutoff(20.0f);
        spot->setSpotExponent(100.0f);

        // point straight down at the map:
        world.normalize();
        spot->setDirection(-world);

        osg::LightSource* spotLS = new osg::LightSource();
        spotLS->setLight(spot);

        lights->addChild( spotLS );
    }

    // A green point light. A Point light lives at a real location in 
    // space and lights equally in all directions.
    {
        GeoPoint p(geosrs, -45, -35, 1000000., ALTMODE_ABSOLUTE);
        p.toWorld(world);

        osg::Light* point = new osg::Light(lightNum++);
        point->setPosition(worldToVec4(world));
        point->setAmbient(osg::Vec4(0,0,0,1));
        point->setDiffuse(osg::Vec4(1.0, 1.0, 0.0,1));

        osg::LightSource* pointLS = new osg::LightSource();
        pointLS->setLight(point);

        lights->addChild( pointLS );
    }
#endif

    // Generate the necessary uniforms for the shaders.
    GenerateGL3LightingUniforms gen;
    lights->accept(gen);

    return lights;
}