[osg-users] Slave camera lighting with disabled main camera

Ravi Mathur ravidavi at utexas.edu
Tue Jan 9 15:48:13 PST 2018

OK I figured it out after digging further into SceneView. In case anyone else ever runs into this, here is what's going on and how to fix it.

When a new View is created (e.g. osgViewer), it defaults to HEADLIGHT mode and internally creates the master Camera, along with a Renderer and SceneView for that camera. The SceneView initializes the master camera's StateSet with a new Light (diffuse+specular) and Light Model (ambient), enables the GL_LIGHTING mode, and internally sets itself up for HEADLIGHT mode.

>From here on, all slave cameras added to the View use the master camera's StateSet as their global stateset (via their own SceneViews). Under normal operations, calling View::setLightingMode(NO_LIGHT) results in the master camera's SceneView removing lighting from the global stateset during the cull stage. Consequently, all slave cameras also have their lighting disabled (unless explicitly enabled in their own StateSet). This is all great and works as expected.

However, in my example I was disabling the master camera by removing its graphics context. Because of this, the master camera's SceneView was never being executed during the cull stage, so the default (HEADLIGHT) lighting parameters were never removed from the master camera's stateset. Therefore all slaves were inheriting the HEADLIGHT lighting.

The solution to this is pretty simple: manually remove the lighting modes from the master camera's stateset after setting NO_LIGHT. Of course this is only necessary if you plan on disabling the master camera by removing its graphics context.

StateSet* ss = viewer.getCamera()->getStateSet();
if(ss) ss->removeMode(GL_LIGHTING);

If Robert or any of the other experienced folks on here think that I'm mistaken on this, or have other more elegant solutions, please let me know. Otherwise I'll consider the matter closed.


Read this topic online here:

More information about the osg-users mailing list