OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Slave camera lighting with disabled main camera


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
ravidavi
User


Joined: 06 Nov 2015
Posts: 44

PostPosted: Tue Jan 09, 2018 1:06 am    Post subject:
Slave camera lighting with disabled main camera
Reply with quote

Hi all,

Sorry to bring up yet another question about osg::View::setLightingMode(NO_LIGHT), but I'm having trouble understanding some lighting behavior.

Suppose I have a simple scene with no explicitly-specified StateSets ... e.g. I'm not setting lights or enabling GL_LIGHTING or anything like that. If I do viewer.setLightingMode(NO_LIGHT), then as expected the viewer doesn't set up any light and doesn't enable GL_LIGHTING. If I add a slave camera, then that slave camera also has no lighting, also as expected.

Now suppose I disable the main camera using viewer.getCamera()->setGraphicsContext(NULL). Suddenly, the slave camera goes back to the default headlight! I've searched around and looked through the code for Renderer and SceneView, but am not able to make sense of this. Can anyone please explain it?

BTW I'm on the OpenSceneGraph-3.5.6 Git tag.

Thanks!
Ravi

Here's the minimal example code to duplicate this behavior.

Code:
using namespace osg;
int main()
{
  // Standard OSG sphere
  ShapeDrawable* sphereSD = new ShapeDrawable(new Sphere());
  Geode *sphereGeode = new Geode();
  sphereGeode->addDrawable(sphereSD);
 
  // Viewer with no light
  osgViewer::Viewer viewer;
  viewer.setSceneData(sphereGeode);
  viewer.setUpViewInWindow(30, 30, 640, 480);
  viewer.setLightingMode(View::NO_LIGHT);
 
  // Slave camera
  Camera* slaveCam = new Camera();
  slaveCam->setViewport(viewer.getCamera()->getViewport());
  slaveCam->setGraphicsContext(viewer.getCamera()->getGraphicsContext());
  viewer.addSlave(slaveCam);

  // Disable main camera
  // This causes slaveCam to have default HEADLIGHT: why??
  viewer.getCamera()->setGraphicsContext(NULL);
 
  return viewer.run();
}
Back to top
View user's profile Send private message
ravidavi
User


Joined: 06 Nov 2015
Posts: 44

PostPosted: Tue Jan 09, 2018 11:47 pm    Post subject:
Reply with quote

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.

Code:
viewer.setLightingMode(View::NO_LIGHT);
StateSet* ss = viewer.getCamera()->getStateSet();
if(ss) ss->removeMode(GL_LIGHTING);
...
viewer.getCamera()->setGraphicsContext(NULL);


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.

Thanks!
Ravi
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11924

PostPosted: Wed Jan 10, 2018 10:00 am    Post subject:
Slave camera lighting with disabled main camera
Reply with quote

HI Ravi,

Quote:
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.

I haven't yet looked deeply into the issue as I'm still in post
holiday catch up mode. What version of the OSG are you using?

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
ravidavi
User


Joined: 06 Nov 2015
Posts: 44

PostPosted: Wed Jan 10, 2018 2:20 pm    Post subject:
Re: Slave camera lighting with disabled main camera
Reply with quote

robertosfield wrote:
HI Ravi,

I haven't yet looked deeply into the issue as I'm still in post
holiday catch up mode. What version of the OSG are you using?

Robert.


I'm on the OpenSceneGraph-3.5.6 tag.
Back to top
View user's profile Send private message
ravidavi
User


Joined: 06 Nov 2015
Posts: 44

PostPosted: Wed Jan 10, 2018 2:53 pm    Post subject:
Re: Slave camera lighting with disabled main camera
Reply with quote

ravidavi wrote:
robertosfield wrote:
HI Ravi,

I haven't yet looked deeply into the issue as I'm still in post
holiday catch up mode. What version of the OSG are you using?

Robert.


I'm on the OpenSceneGraph-3.5.6 tag.


I just checked, and the same behavior & solution exists on master.
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11924

PostPosted: Wed Jan 10, 2018 3:30 pm    Post subject:
Slave camera lighting with disabled main camera
Reply with quote

HI Ravi,

On 10 January 2018 at 14:53, Ravi Mathur <> wrote:
Quote:
I just checked, and the same behavior & solution exists on master.

Looking at the internal setup of the rendering backend I think the
reason for the behavior is that the Renderer implement found in
OpenSceneGraph/src/osgViewer/Renderer.cpp constructor reads the View's
LightingMode and then passes this on to the SceneView's it setups to
do the rendering. This setup happens when you add the slave cameras.

I think the problem comes in that the osg::View::LightingMode value
isn't passed onto the SceneView's by the Renderer's.

Attached is a modification of src/osgViewer/Renderer.cpp that passes
the View::LightingMode value to the SceneView on each new cull
traversal.

Could you try this out to see if it works, if so I'll check it in.

Robert.



------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11924

PostPosted: Wed Jan 10, 2018 3:40 pm    Post subject:
Slave camera lighting with disabled main camera
Reply with quote

Ops, don't send modifications without compiling them first...

The View::LightingMode and SceneView::LightingMode aren't compatible
enum's so can't be passed as is. I've spotted a better way of doing
this update, putting into the Renderer::updateSceneView() method along
with the setting of the fusion distance.

Could you test this one?

Robert.



------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
ravidavi
User


Joined: 06 Nov 2015
Posts: 44

PostPosted: Wed Jan 10, 2018 4:24 pm    Post subject:
Re: Slave camera lighting with disabled main camera
Reply with quote

robertosfield wrote:
Ops, don't send modifications without compiling them first...

The View::LightingMode and SceneView::LightingMode aren't compatible
enum's so can't be passed as is. I've spotted a better way of doing
this update, putting into the Renderer::updateSceneView() method along
with the setting of the fusion distance.

Could you test this one?

Robert.



------------------
Post generated by Mail2Forum


Unfortunately your update to Renderer::updateSceneView() doesn't address the issue, nor would I expect it to. SceneView already gets the updated osg::View::LightingMode value inside SceneView::inheritCullSettings(), which is called inside Renderer::cull() (line 69, just a few lines down from the call to updateSceneView()).

The problem is that the Renderer is never run for the master camera since I disabled it using mastercamera->setGraphicsContext(NULL). So the SceneViews for the slaves, which use the master camera's StateSet as their _globalStateSet, still have lighting enabled.

I'm not saying this behavior is wrong per se, since I did explicitly disable the master camera. But if any change is to made to the OSG, it would have to be in ViewerBase::renderingTraversals() since that is where the master camera's Renderer::cull() method would normally be called.

Let me think of an appropriate minimal update to ViewerBase::renderingTraversals(). Basically it needs to first update the lighting modes for each disabled camera's StateSet before performing Renderer::cull() for each enabled camera.

Ravi
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11924

PostPosted: Wed Jan 10, 2018 5:01 pm    Post subject:
Slave camera lighting with disabled main camera
Reply with quote

Hi Ravi,

Oh well. I've removed the LightingMode changes, there is a little
clean up in there so I've merged this with master.

FYI, LightingMode is really just there for convince and backwards
compatibility back to the 1.0/2,0 days of the OSG.

These days I'd write lighting management all myself rather than
leverage these built-in defaults.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
ravidavi
User


Joined: 06 Nov 2015
Posts: 44

PostPosted: Wed Jan 10, 2018 8:56 pm    Post subject:
Slave camera lighting with disabled main camera
Reply with quote

No worries, thank you for looking into it anyway. Smile

To be honest, I don't think that "fixing" this behavior within OSG is worth it. The code additions to ViewerBase::renderingTraversals() would be duplicated from Renderer and SceneView, and would only benefit fringe cases where the user wants NO_LIGHT with an explicitly disabled master camera.


I'm fine with the solution I outlined before (manually disabling GL_LIGHTING on master camera). Plus as you said, most lighting management should be done by the user anyway.


Ravi

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts osgviewer camera initial angle. Vagn General 1 Wed Jun 20, 2018 2:31 pm View latest post
No new posts Positioning a Camera relative to anot... Takarashy General 0 Thu May 24, 2018 8:27 am View latest post
No new posts Using 'NodeTrackerManipulator' while ... loopy General 3 Wed May 09, 2018 10:40 pm View latest post
No new posts Getting the main camera. Rowley, Marlin R General 2 Wed May 02, 2018 5:05 pm View latest post
No new posts Camera serializer and culling mp3butcher General 1 Sat Apr 21, 2018 12:16 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP