Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7871153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:49:24+00:00 2026-06-03T01:49:24+00:00

I need to set a point Source above my landscape in OpenSceneGraph that will

  • 0

I need to set a point Source above my landscape in OpenSceneGraph that will act like a sun. I already know how to set up the light and it can be done in this fashion:

//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 produce a landscape that looks like this:

The Landscape with light above (Light is indicated by the sphere)

This light source doesn’t really seem to make a difference to the landscape though.
The question is what sort of light settings (ie. ambiance, diffusion etc) are needed to make a Sun emulating light.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:49:25+00:00Added an answer on June 3, 2026 at 1:49 am

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

    To try to answer your question here – it depends on the properties of the material you are trying to light.

    I’ve found that materials on some models I load will only react to one particular of the 3 light types (specifically, some model are specular-only), so I just turn on all 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
    

    For your case, you might alternatively be able to redefine the ambient and/or diffuse properties of your terrain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to set some server specific variables in a rails application that will
I need connect to server git. http://help.github.com/win-set-up-git/ I do everything to the point, 4
I need Set collection, where its items will be identified by items class. Something
Can someone please point me to the Firefox source code where Set-Cookie header is
Suppose I need to set an opacity mask on a WPF control that highlights
I have one set of source files from which I need to generate multiple
Hey, i have kinda silly problem, i need to set Point Pos as mouse
I know that a lot of c/c++ XML library questions have been asked already
I set copyright on the image. After that i need to delete the old
Need set zoom for camera preview...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.