SceneMgr::_renderScene() updates scenegraph AFTER shadows?

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
User avatar
lunkhound
Gremlin
Posts: 169
Joined: Sun Apr 29, 2012 1:03 am
Location: Santa Monica, California

SceneMgr::_renderScene() updates scenegraph AFTER shadows?

Post by lunkhound » Wed Jan 16, 2013 5:32 am

I encountered a bug where shadows were lagging the camera by a frame. I tracked the problem down to the order of things in SceneManager::_renderScene().
The order was prepareShadowTextures(), then updateSceneGraph().

Here is a sort of pseudocode of the flow to illustrate the bug (each level of indention is a deeper level of the call stack):

Code: Select all

SceneManager::_renderScene( main camera )
    ->prepareShadowTextures()
          ->set up shadow cameras (shadow space projection matrices are pushed into GPU params)
          ->render shadow maps
                ->_renderScene( shadow camera ) (recursive call to render the first shadow map)
                      ->updateSceneGraph() (main camera is moved here because it is attached to a sceneNode, and this is the first time in the frame updateSceneGraph has been called)
                      ->render shadow map
    ->updateSceneGraph()
    ->render main camera view (using stale matrices from the previous camera state)
It seems pretty obvious that this is the wrong order to do things. Updating the scene graph and determining the final camera position should be done BEFORE preparing the shadow maps which DEPEND on the camera being up to date.
I believe the only reason this bug hasn't been noticed before is that the recursive calls to _renderScene() tend mask the problem in many cases. In my case, this bug was only apparent when camera-relative-rendering mode was on (and the camera had to be parented to a scene node).

I would expect that if there was a weird and obscure reason why updating the scenegraph should come after preparing shadow textures, that there would be a comment in the code explaining it. But there isn't.
So barring any objections, I'll submit a patch for this to v1-8 branch.
0 x

User avatar
Kaylx
Greenskin
Posts: 123
Joined: Sun May 22, 2011 10:45 pm
Location: Scotland

Re: SceneMgr::_renderScene() updates scenegraph AFTER shadow

Post by Kaylx » Wed Jan 16, 2013 9:39 am

Keep us posted on when you submit that patch. :)
0 x

User avatar
lunkhound
Gremlin
Posts: 169
Joined: Sun Apr 29, 2012 1:03 am
Location: Santa Monica, California

Re: SceneMgr::_renderScene() updates scenegraph AFTER shadow

Post by lunkhound » Wed Jan 16, 2013 6:34 pm

I've put the patch on my bitbucket fork:

https://bitbucket.org/cc8192/ogre/commi ... d6eebe15a3

and requested a pull.
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: SceneMgr::_renderScene() updates scenegraph AFTER shadow

Post by masterfalcon » Wed Jan 16, 2013 6:40 pm

Thanks. I'll take a look at it. But I don't anticipate any problems
0 x

TheSHEEEP
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 972
Joined: Mon Jun 02, 2008 6:52 pm
Location: Berlin

Re: SceneMgr::_renderScene() updates scenegraph AFTER shadow

Post by TheSHEEEP » Wed Jan 16, 2013 6:59 pm

masterfalcon wrote:But I don't anticipate any problems
:shock:
Oh oh. Now you've challenged fate!
0 x
My site! - Have a look :)
Also on Twitter - extra fluffy

User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 1
Contact:

Re: SceneMgr::_renderScene() updates scenegraph AFTER shadow

Post by Wolfmanfx » Wed Jan 16, 2013 7:01 pm

I know that this changed by patch now its reverted by a patch :) funny thing (the first one were did in 1.7 branch long time ago)
0 x

User avatar
lunkhound
Gremlin
Posts: 169
Joined: Sun Apr 29, 2012 1:03 am
Location: Santa Monica, California

Re: SceneMgr::_renderScene() updates scenegraph AFTER shadow

Post by lunkhound » Wed Jan 16, 2013 9:38 pm

Wolfmanfx wrote:I know that this changed by patch now its reverted by a patch :) funny thing (the first one were did in 1.7 branch long time ago)
Interesting. Its commit #2053 by Sinbad. Comment says "Patch 2986437: auto-tracking update should be after the re-entrant call to update shadow textures, otherwise old tracking state may be used"

Not sure why the auto-tracking would want to come after shadow textures. Anybody know what that means?
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4146
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 268
Contact:

Re: SceneMgr::_renderScene() updates scenegraph AFTER shadow

Post by dark_sylinc » Thu Jan 17, 2013 4:42 am

I don't know, but if our shadows were lagging behind one frame, it could really explain our overly excessive acne.

I wouldn't be surprised that changing the order breaks something else. As I was designing the docs for 2.0, I've discovered the update order wasn't really strongly defined, with a couple possible catch-22 scenarios.
0 x

User avatar
sparkprime
Ogre Magi
Posts: 1137
Joined: Mon May 07, 2007 3:43 am
Location: Ossining, New York
Contact:

Re: SceneMgr::_renderScene() updates scenegraph AFTER shadow

Post by sparkprime » Thu Jan 17, 2013 5:35 pm

Surely anything other than the following order is insane:

1) update scenegraph
2) update auto tracking
3) update shadows (including preparation of matrixes, culling for cast passes, and render)
4) receiver passes


Why is there any re-entrancy?
0 x

User avatar
lunkhound
Gremlin
Posts: 169
Joined: Sun Apr 29, 2012 1:03 am
Location: Santa Monica, California

Re: SceneMgr::_renderScene() updates scenegraph AFTER shadow

Post by lunkhound » Thu Jan 17, 2013 10:10 pm

Well I hope my patch doesn't break things too badly. Or at least that it fixes more than it breaks...
I'll be so glad to see this mess cleaned up in 2.0!
0 x

Post Reply