Creating a Sunlight Source in OSG

I need to set the Source item over my landscape in OpenSceneGraph, which will act like the sun. I already know how to set up the light, and this can be done as follows:

//LIGHT CODE ------------------------
osg::ref_ptr<osg::Group> lightGroup (new osg::Group);
osg::ref_ptr<osg::StateSet> lightSS (root->getOrCreateStateSet());
osg::ref_ptr<osg::LightSource> lightSource1 = new osg::LightSource;
osg::ref_ptr<osg::LightSource> lightSource2 = new osg::LightSource;

// create a local light.

float xCenter = tree->getRoot()->getXCenter();
float yCenter = tree->getRoot()->getYCenter();


osg::Vec4f lightPosition (osg::Vec4f(xCenter, yCenter,75.0,1.0f));
osg::ref_ptr<osg::Light> myLight = new osg::Light;
myLight->setLightNum(1);
myLight->setPosition(lightPosition);
    myLight->setAmbient(osg::Vec4(0.8f,0.8f,0.8f,1.0f));
    myLight->setDiffuse(osg::Vec4(0.1f,0.4f,0.1f,1.0f));
    myLight->setConstantAttenuation(1.0f);
    myLight->setDirection(osg::Vec3(0.0f, 0.0f, -1.0f));
lightSource1->setLight(myLight.get());

lightSource1->setLocalStateSetModes(osg::StateAttribute::ON); 
lightSource1->setStateSetModes(*lightSS,osg::StateAttribute::ON);
//osg::StateSet* lightSS (lightGroup->getOrCreateStateSet());

lightGroup->addChild(lightSource1.get());

//Light markers: small spheres
osg::ref_ptr<osg::Geode> lightMarkerGeode (new osg::Geode);
lightMarkerGeode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3f(xCenter,yCenter,75),10.0f)));


//Tuto 9: lighting code
root->addChild(lightGroup.get());
//Tuto 9: Adding the light marker geode
root->addChild(lightMarkerGeode.get());

//LIGHTCODE END----------------

And this will create a landscape that looks like this:

Landscape with light above (light is indicated by a sphere)

This light source does not seem to really affect the landscape. The question is what lighting parameters (i.e., Atmosphere, diffusion, etc.) are needed to create the emulating light of the Sun.

+3
source share
1 answer

For what it's worth, the OSG forum / mailing list is usually good at answering questions: http://forum.openscenegraph.org/

- , .

, , , ( , - ), 3:

osg::Light *light = new osg::Light;
light->setAmbient(osg::Vec4(1.0,1.0,1.0,1.0));
light->setDiffuse(osg::Vec4(1.0,1.0,1.0,1.0));
light->setSpecular(osg::Vec4(1,1,1,1));  // some examples don't have this one

/ .

+3

All Articles