Try adding an osg::LightModel to your StateSet. Also read up on how OpenGL lighting works.
Robert.
On 5/11/06, Graham Towse <[EMAIL PROTECTED]> wrote:
Hi Robert,
I had a look at both the osglight & osgprecipitation
examples and have come up with some code that is half
way there, I'm just unsure if I am doing it correctly
as I can't seem to get a completely black scene when
setting my lighting to a black colour, I set up my
viewer like so:
pViewer->setUpViewer(osgProducer::Viewer::ViewerOptions::ESCAPE_SETS_DONE);
and perform the following routines to setup the
lighting:
// create the root node
pRootNode = new osg::MatrixTransform;
// create the plane transform
pPlaneTransform = new osg::PositionAttitudeTransform;
// create the plane
osg::Node* pPlaneModel = createPlaneModel(1.0f);
pPlaneTransform->addChild(pPlaneModel);
pRootNode->addChild(pPlaneTransform);
// run optimization over the scene graph
osgUtil::Optimizer optimzer;
optimzer.optimize(pRootNode);
// create a stateset for the root node
osg::StateSet* rootStateSet = new osg::StateSet;
pRootNode->setStateSet(rootStateSet);
// get the global stateset
osg::StateSet* pGlobalStateSet =
pViewer->getGlobalStateSet();
pGlobalStateSet->setMode(GL_LIGHTING,
osg::StateAttribute::ON);
// create the light
m_pWorldLight = new osg::Light;
m_pWorldLight->setLightNum(0);
m_pWorldLight->setPosition(osg::Vec4(0.0f,0.0f,1.0f,0.0f));
// directional light from above
m_pWorldLight->setAmbient(osg::Vec4( 0.8f,0.8f,0.8f,1.0f));
m_pWorldLight->setDiffuse(osg::Vec4(0.2f,0.2f,0.2f,1.0f));
m_pWorldLight->setSpecular(osg::Vec4(0.2f,0.2f,0.2f,1.0f));
// setup the light source
m_pWorldLightSource = new osg::LightSource;
m_pWorldLightSource->setLight(m_pWorldLight);
m_pWorldLightSource->setLocalStateSetModes(osg::StateAttribute::ON);
m_pWorldLightSource->setReferenceFrame(osg::LightSource::RELATIVE_RF);
m_pWorldLightSource->setStateSetModes(*rootStateSet,osg::StateAttribute::ON);
// add the light source to the root node
pRootNode->addChild(m_pWorldLightSource);
// set the scene to render
pViewer->setSceneData(pRootNode);
Then a call to:
osg::Vec4 red = osg::Vec4(1.0,0.0,0.0,1.0);
m_pWorldLight->setAmbient(red);
m_pWorldLight->setDiffuse(red);
m_pWorldLight->setSpecular(red);
results in a red coloured scene, but a call to
osg::Vec4 black = osg::Vec4(0.0,0.0,0.0,1.0);
m_pWorldLight->setAmbient(black);
m_pWorldLight->setDiffuse(black);
m_pWorldLight->setSpecular(black);
results in a scene that is dark but still illuminated,
can you see what I am doing wrong?
Cheers,
Graham
HI Graham,
The viewer light sources are just their for
convinience rather than
flexibility. I'd recommend just adding an
osg::LightSource in to your scene
to set you own lights. See the osglight example, the
new osgprecipitation
example also has code for using an osg::LightSource to
rest the lighting to
reduce the diffuse and specular and increase the
ambient values to better
fit lighting in rain/snow.
Robert.
Robert.
On 5/11/06, Graham Towse < [EMAIL PROTECTED]> wrote:
>
> Hi All,
>
> I am trying to create a function that sets a world
> light ie
>
> setWorldLightIntensity(float fIntensity)
>
> where an argument of 1.0 results in a midday scene
and
> 0.0 results in a midnight scene.
>
> I am using the default SKY_LIGHT in osgProducer and
> attempting to modify it to affect my scene, but I am
> confused my the multiple calls to new osg::Light
that
> exist in the osgProducer code.
>
> The first call is at line 338 of Viewer.cpp
>
> 386: setSceneDecorator(lightsource);
> 387: {
> 388: osg::Light* light = new osg::Light; <----
> 389: lightsource->setLight(light);
>
> and the second call is at line 127 of SceneView.cpp
>
> 134: if ((options & HEADLIGHT) || (options &
> SKY_LIGHT))
> 135: {
> 136: _lightingMode=(options&HEADLIGHT) ? HEADLIGHT
> : SKY_LIGHT;
> 137: _light = new osg::Light;
> 138: _light->setLightNum(0);
>
> Before I delve too much into getting my world light
to
> work, I thought I should ask, does anyone know why
> there are two instances of a light created when I
> call:
>
>
pViewer->setUpViewer(osgProducer::Viewer::ViewerOptions::ESCAPE_SETS_DONE
> |
osgProducer::Viewer::ViewerOptions::SKY_LIGHT_SOURCE
> );
>
> Cheers,
>
> Graham Towse
> [EMAIL PROTECTED]
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam
protection around
> http://mail.yahoo.com
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://openscenegraph.net/mailman/listinfo/osg-users
> http://www.openscenegraph.org/
>
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
_______________________________________________ osg-users mailing list [email protected] http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/
