[osg-users] PrimitiveSet lighting issues

Jean-Sébastien Guay jean-sebastien.guay at polymtl.ca
Mon Sep 24 17:12:37 PDT 2007


Hello Nelson,

> I'm still new to all this.  All I found on emissive color is the following:
>
> glMaterial Default Parameters
> GL_EMISSION (0.0, 0.0, 0.0, 1.0) emissive color of material

The OpenSceneGraph is a rather thin wrapper of OpenGL, so in most  
cases the OpenGL documentation will be useful to make sense out of  
what OSG does. In most cases, if you see a method name in OSG's  
doxygen reference, you can search for similar names in OpenGL and you  
will find out what it does.

In this case, "Chapter 5 - Lighting" from the red book will be useful.
http://www.glprogramming.com/red/chapter05.html

At around 1/6th of the page, you will see:
   "In addition to ambient, diffuse, and specular colors, materials have an
    emissive color, which simulates light originating from an object. In the
    OpenGL lighting model, the emissive color of a surface adds  
intensity to the
    object, but is unaffected by any light sources. Also, the emissive  
color does
    not introduce any additional light into the overall scene."

To understand what the emissive color will give as a result, see  
around 5/6th of the page, where you will find the general lighting  
equation OpenGL uses:

The color produced by lighting a vertex is computed as follows:

"vertex color =
     the material emission at that vertex +
     the global ambient light scaled by the material's ambient property at that
         vertex +
     the ambient, diffuse, and specular contributions from all the  
light sources,
         properly attenuated

So if you just want your color independently of any lighting, you  
should set your color as the material's emissive color, and disable  
all other lighting in the scene (or at least for those nodes in the  
scene graph).

> Is this what you had in mind:
>
>
> 	osg::StateSet* state = geode->getOrCreateStateSet();
>     	state ->setMode(GL_COLOR_MATERIAL,osg::StateAttribute::ON);
> 	osg::ref_ptr<osg::Material> mat = new osg::Material;
> 	mat->setColorMode(osg::Material::EMISSION);
> 	state->setAttribute(mat.get()

The problem there is that you don't set the emissive color. I think  
this should work, but untested... :

     osg::StateSet* state = geode->getOrCreateStateSet();
     osg::ref_ptr<osg::Material> mat = new osg::Material;
     mat->setEmission(osg::Material::FRONT_AND_BACK,
         osg::Vec4(1.0, 1.0, 1.0, 1.0);    // Set the color to  
whatever you want
     state->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
     state->setAttribute(mat.get());

But you were definitely on the right track.

Good luck,

J-S
-- 
______________________________________________________
Jean-Sebastien Guay     jean-sebastien.guay at polymtl.ca
                         http://whitestar02.webhop.org/

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.





More information about the osg-users mailing list