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 

How to handle cameras in the scene graph when rendering to framebuffer


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


Joined: 06 Feb 2013
Posts: 56

PostPosted: Fri Feb 24, 2017 4:47 pm    Post subject:
How to handle cameras in the scene graph when rendering to framebuffer
Reply with quote

Hi all,
sorry for so many questions today.

My scene graph has additional cameras as children somewhere in the scene
graph.
For example a hud camera for a background image.

I do screenshots by adding a slave camera to the main camera which
renders the scene to the FB.
Unfortunately this rendering doesn't show the parts of the nested
cameras, i.e. no
background wallpaper.
What is the recommended way to solve this?

Thanks for any help.

- Werner -




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


Joined: 18 Mar 2009
Posts: 10791

PostPosted: Fri Feb 24, 2017 4:59 pm    Post subject:
How to handle cameras in the scene graph when rendering to framebuffer
Reply with quote

Hi Werner,

In principle what you are doing should be possible. What is going
wrong in your instance is impossible to say without seeing how you are
setting up the viewer Camera's and the in scene graph Camera's.

Robert.

On 24 February 2017 at 16:44, Werner Modenbach
<> wrote:
Quote:
Hi all,
sorry for so many questions today.

My scene graph has additional cameras as children somewhere in the scene
graph.
For example a hud camera for a background image.

I do screenshots by adding a slave camera to the main camera which renders
the scene to the FB.
Unfortunately this rendering doesn't show the parts of the nested cameras,
i.e. no
background wallpaper.
What is the recommended way to solve this?

Thanks for any help.

- Werner -





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


Joined: 26 Jan 2017
Posts: 56

PostPosted: Sun Feb 26, 2017 5:28 pm    Post subject:
Reply with quote

Hi,

I would try to play with the render order. For me, my whole render-to-texture chain didn't start working until I set them to PRE, even though in my head I thought POST was the one. Very Happy

What else can I say... There's a couple of discrepancies, and some might strike you as odd.

There are viewer slaves, but you can also add the cameras to the scene graph directly:
http://forum.openscenegraph.org/viewtopic.php?t=16523)

And here is my big thread about my rtt travels:
http://forum.openscenegraph.org/viewtopic.php?t=16517

Thank you!

Cheers,
Johny
Back to top
View user's profile Send private message
wernerM
User


Joined: 06 Feb 2013
Posts: 56

PostPosted: Mon Feb 27, 2017 10:37 am    Post subject:
How to handle cameras in the scene graph when rendering to framebuffer
Reply with quote

Hi Robert,

sorry for the delayed answer. It's carnival time here and so everybody is out - except me Wink

I try to give an as compressed description as possible here.

The scene looks like that:
     *
Quote:
* ---------------
Quote:
* | RootNode | * --------------- * / * --------------- --------------------- * | ShadowScene | |evtl. PPU-Prozessor| * --------------- --------------------- * / * --------------- --------------- * | Switchnode | | LightSource | * | RootNode |
0
Quote:
* | RootNode |
1
Quote:
* | RootNode |
2
Quote:
* | RootNode |
3
Quote:
* | RootNode |
4
Quote:
* | RootNode |
5
The main camera is a standard camera with perspective view and a trackball manipulator.
The wallpaper class is like that:
class Cl_3D_Wallpaper : public osg::Camera {
Quote:
* | RootNode |
6
Quote:
* | RootNode |
7
Quote:
* | RootNode |
8
Quote:
* | RootNode |
9
Quote:
* ---------------
0
Quote:
* ---------------
1
Cl_3D_Wallpaper::Cl_3D_Wallpaper(Cl_3Dview_osg *_parent): view(_parent), path(QLatin1String("")) {
Quote:
* ---------------
2
Quote:
* ---------------
3
Quote:
* ---------------
4
Quote:
* ---------------
5
Quote:
* ---------------
6
Quote:
* ---------------
7
Quote:
* ---------------
8
Quote:
* ---------------
9
Quote:
* /
0
Quote:
* /
1
Quote:
* /
2
Quote:
* /
3
Quote:
* /
4
Quote:
* /
5
Quote:
* /
6
Quote:
* /
7
Quote:
* /
8
Quote:
* /
9
Quote:
* --------------- ---------------------
0
Quote:
* --------------- ---------------------
1           path = _path;
Quote:
* --------------- ---------------------
2
Quote:
* --------------- ---------------------
3
Quote:
* --------------- ---------------------
4
Quote:
* --------------- ---------------------
5
Quote:
* --------------- ---------------------
6
Quote:
* --------------- ---------------------
7
Quote:
* --------------- ---------------------
8
Quote:
* --------------- ---------------------
9
Quote:
* | ShadowScene | |evtl. PPU-Prozessor|
0
Quote:
* | ShadowScene | |evtl. PPU-Prozessor|
1
Quote:
* | ShadowScene | |evtl. PPU-Prozessor|
2
Quote:
* | ShadowScene | |evtl. PPU-Prozessor|
3
Quote:
* | ShadowScene | |evtl. PPU-Prozessor|
4
Quote:
* | ShadowScene | |evtl. PPU-Prozessor|
5
Quote:
* | ShadowScene | |evtl. PPU-Prozessor|
6
Quote:
* | ShadowScene | |evtl. PPU-Prozessor|
7 Now the part of getting a frame buffer screenshot:

/** The screen image is rendered at a pregiven dpi */
Quote:
* | ShadowScene | |evtl. PPU-Prozessor|
8
Quote:
* | ShadowScene | |evtl. PPU-Prozessor|
9 double scale = (double)_dpi / (double)dpi;
Quote:
* --------------- ---------------------
0
Quote:
* --------------- ---------------------
1
Quote:
* --------------- ---------------------
2
Quote:
* --------------- ---------------------
3
Quote:
* --------------- ---------------------
4
Quote:
* --------------- ---------------------
5
Quote:
* --------------- ---------------------
6
Quote:
* --------------- ---------------------
7          osg::ref_ptr<osg::Image> image = new osg::Image;
Quote:
* --------------- ---------------------
8
Quote:
* --------------- ---------------------
9
Quote:
* /
0
Quote:
* /
1
Quote:
* /
2
Quote:
* /
3
Quote:
* /
4
Quote:
* /
5
Quote:
* /
6
Quote:
* /
7
Quote:
* /
8
Quote:
* /
9
Quote:
* --------------- ---------------
0
Quote:
* --------------- ---------------
1          view->getCamera()->addChild(camera.get());
Quote:
* --------------- ---------------
2
Quote:
* --------------- ---------------
3
Quote:
* --------------- ---------------
4           int y_out = imageHeight - 1;
Quote:
* --------------- ---------------
5                    for (int col = 0; col < tiles; col++) {
Quote:
* --------------- ---------------
6
Quote:
* --------------- ---------------
7
Quote:
* --------------- ---------------
8
Quote:
* --------------- ---------------
9
Quote:
* | Switchnode | | LightSource |
0
Quote:
* | Switchnode | | LightSource |
1
Quote:
* | Switchnode | | LightSource |
2                    }
Quote:
* | Switchnode | | LightSource |
3
Quote:
* | Switchnode | | LightSource |
4
Quote:
* | Switchnode | | LightSource |
5
Quote:
* | Switchnode | | LightSource |
6
The rendered image is missing my wallpaper.
If I add the camera as a slave camera to the main camera I just get an empty black image.
Actually I also don't understand the difference between slave and child cameras here. I know you explained it recently Smile
Why does the slave camera give an empty image but the child camera doesn't?

BTW. I wrote my code here with the background of giving an example to others looking for functionality like that.




Am 24.02.2017 um 17:56 schrieb Robert Osfield:

Quote:
Quote:
* | Switchnode | | LightSource |
7
Quote:
Quote:
* | Switchnode | | LightSource |
8 * | Switchnode | | LightSource |
9


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


Joined: 18 Mar 2009
Posts: 10791

PostPosted: Mon Feb 27, 2017 11:04 am    Post subject:
How to handle cameras in the scene graph when rendering to framebuffer
Reply with quote

HI Werner,

It's hard to work exactly what is going on with a quick read through
as it's rather complicated set up of various Camera's. My current
best guess Your Cl_3D_Wallpaper class is setting the RenderOrder to
POST_RENDER as this is make it render after the Camera you are adding
to do the screenshot has been done.

Perhaps the best way to work out what order things are being done in
is to add a Camera initiali, pre, post and a final DrawCallbacks to
each of the Camera's and have these debug callbacks just write to the
console when they are being called.

Robert.

On 27 February 2017 at 10:34, Werner Modenbach
<> wrote:
Quote:
Hi Robert,

sorry for the delayed answer. It's carnival time here and so everybody is
out - except me ;-)

I try to give an as compressed description as possible here.

The scene looks like that:
*

* ---------------

* | RootNode |

* ---------------

* / \

* ---------------
---------------------

* | ShadowScene | |evtl.
PPU-Prozessor|

* ---------------
---------------------

* / \

* --------------- ---------------

* | Switchnode | | LightSource |

* --------------- ---------------

* / \\\

* --------------- -----------------

* | User scene | | evtl. further |

* --------------- | Objects |

* -----------------

The further objects are the wallpaper, a magnifier etc.


The main camera is a standard camera with perspective view and a trackball
manipulator.
The wallpaper class is like that:
class Cl_3D_Wallpaper : public osg::Camera {

public:

Cl_3D_Wallpaper(Cl_3Dview_osg *_parent);

/** This Method creates the background image. */

void setWallpaper(const QString _path);

protected:
Cl_3Dview_osg *view;
QString path;
};


Cl_3D_Wallpaper::Cl_3D_Wallpaper(Cl_3Dview_osg *_parent): view(_parent),
path(QLatin1String("")) {

setCullingActive( false );

setClearMask( 0 );

setAllowEventFocus( false );

setReferenceFrame( osg::Transform::ABSOLUTE_RF );

setRenderOrder( osg::Camera::POST_RENDER );

setProjectionMatrix( osg::Matrix::ortho2D(0.0, 1.0, 0.0, 1.0) );

setName(getNodeName().toStdString().c_str());

osg::StateSet* ss = getOrCreateStateSet();

ss->setMode( GL_LIGHTING, osg::StateAttribute::OFF );

ss->setAttributeAndModes( new osg::Depth(osg::Depth::LEQUAL, 1.0, 1.0)
);

view->installDefaultShader(ss); // In case we are on gl3

}

/** Diese Methode erzeugt eine Hintergrundbildanzeige,

* falls der Pfad auf eine Bilddatei verweist.

*/

void Cl_3D_Wallpaper::setWallpaper(const QString _path) {

path = _path;

if (!_path.isEmpty()) {

// ================================================

// Die Szene des Bildes erzeugen

// ================================================

osg::Geode* geode = new osg::Geode();

osg::Geometry* geometry =
osg::createTexturedQuadGeometry(osg::Vec3(0,0,0),osg::Vec3(1,0,0),osg::Vec3(0,1,0),0,
0, 1, 1);

geode->addDrawable(geometry);

osg::Texture2D* texture = view->loadTexture(_path, false);


geode->getOrCreateStateSet()->setTextureAttributeAndModes(BASE_TEXTURE_UNIT,
texture, osg::StateAttribute:ShockedN);

geode->getOrCreateStateSet()->setMode(GL_LIGHTING,
osg::StateAttribute::OFF);

addChild(geode);

view->installDefaultShader(geode->getOrCreateStateSet()); //In case
we are on gl3

}

}

Now the part of getting a frame buffer screenshot:

/** The screen image is rendered at a pregiven dpi */

QImage Cl_3Dview_osg::getHighResQImage(const int _dpi) {

double scale = (double)_dpi / (double)dpi;

// Calculation of image size and tiles per row

int width = (int) (view->getGraphicsWidth());

int height = (int) (view->getGraphicsHeight());

int imageWidth = (int)(width * scale);

int imageHeight = (int)(height * scale);

int tiles = (imageWidth - 1) / width + 1;

osg::ref_ptr<osg::Image> image = new osg::Image;

// Creating the new camera
osg::ref_ptr<osg::Camera> camera = new osg::Camera;

camera->getOrCreateStateSet()->setGlobalDefaults();

camera->setClearColor(view->getCamera()->getClearColor());

camera->setViewport(new osg::Viewport(0,0,width,height));

camera->setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );

camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);

camera->setRenderOrder( osg::Camera::POST_RENDER );


camera->addChild(view->getCamera()->getChild(0)); // The root node

osg::ref_ptr<osg::Image> fbImage = new osg::Image;

fbImage->allocateImage(width,height,1,GL_RGBA,GL_UNSIGNED_BYTE, 1);

camera->attach( osg::Camera::COLOR_BUFFER, fbImage.get(), 0, 0);

// Setting the new camera a child of the main camera

view->getCamera()->addChild(camera.get());

// Loop over tiles
osg::Matrixd viewMatrix = view->getCamera()->getViewMatrix();

osg::Matrixd projectionMatrix =
view->getCamera()->getProjectionMatrix();

int y_out = imageHeight - 1;

for (int row = 0; row < tiles; row++) {

for (int col = 0; col < tiles; col++) {

// Calculate projection matrix offset of each tile

osg::Matrix offsetMatrix =

osg::Matrix::scale(scale, scale, 1.0) *

osg::Matrix::translate(scale-1-2*col, scale-1-2*row,
0.0);

camera->setViewMatrix(viewMatrix);

camera->setProjectionMatrix( projectionMatrix * offsetMatrix );

view->frame();
image = fbImage.get();

// Transferring tile into final image
.......

}

y_out -= height;

if (y_out < 0) break;

}

view->getCamera()->removeChild(camera.get());
}


The rendered image is missing my wallpaper.
If I add the camera as a slave camera to the main camera I just get an empty
black image.
Actually I also don't understand the difference between slave and child
cameras here. I know you explained it recently Smile
Why does the slave camera give an empty image but the child camera doesn't?

BTW. I wrote my code here with the background of giving an example to others
looking for functionality like that.





Am 24.02.2017 um 17:56 schrieb Robert Osfield:

Hi Werner,

In principle what you are doing should be possible. What is going
wrong in your instance is impossible to say without seeing how you are
setting up the viewer Camera's and the in scene graph Camera's.

Robert.

On 24 February 2017 at 16:44, Werner Modenbach
<> wrote:

Hi all,
sorry for so many questions today.

My scene graph has additional cameras as children somewhere in the scene
graph.
For example a hud camera for a background image.

I do screenshots by adding a slave camera to the main camera which renders
the scene to the FB.
Unfortunately this rendering doesn't show the parts of the nested cameras,
i.e. no
background wallpaper.
What is the recommended way to solve this?

Thanks for any help.

- Werner -












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


Joined: 06 Feb 2013
Posts: 56

PostPosted: Mon Feb 27, 2017 11:11 am    Post subject:
How to handle cameras in the scene graph when rendering to framebuffer
Reply with quote

Hi Robert,

you may be right. There are several (more) objects that have to be rendered in a certain sequence and PRE-/NORMAL-/POST-RENDER is
a little weak for fine grained tuning.
Can I use
Quote:
StateSet->setRenderBinDetails( 11, "RenderBin");

instead? That should work, isn't it?
What are the bin numbers usually used for the 3 modes?

Am 27.02.2017 um 12:02 schrieb Robert Osfield:

Quote:
Quote:
HI Werner,

It's hard to work exactly what is going on with a quick read through
as it's rather complicated set up of various Camera's. My current
best guess Your Cl_3D_Wallpaper class is setting the RenderOrder to
POST_RENDER as this is make it render after the Camera you are adding
to do the screenshot has been done.

Perhaps the best way to work out what order things are being done in
is to add a Camera initiali, pre, post and a final DrawCallbacks to
each of the Camera's and have these debug callbacks just write to the
console when they are being called.

Robert.

On 27 February 2017 at 10:34, Werner Modenbach
<> (
Only registered users can see emails on this board!
Get registred or enter the forums!
) wrote:
Quote:
Hi Robert,

sorry for the delayed answer. It's carnival time here and so everybody is
out - except me ;-)

I try to give an as compressed description as possible here.

The scene looks like that:
*

* ---------------

* | RootNode |

* ---------------

* /

* ---------------
---------------------

* | ShadowScene | |evtl.
PPU-Prozessor|

* ---------------
---------------------

* /

* --------------- ---------------

* | Switchnode | | LightSource |

* --------------- ---------------

* / \

* --------------- -----------------

* | User scene | | evtl. further |

* --------------- | Objects |

* -----------------

The further objects are the wallpaper, a magnifier etc.


The main camera is a standard camera with perspective view and a trackball
manipulator.
The wallpaper class is like that:
class Cl_3D_Wallpaper : public osg::Camera {

public:

Cl_3D_Wallpaper(Cl_3Dview_osg *_parent);

/** This Method creates the background image. */

void setWallpaper(const QString _path);

protected:
Cl_3Dview_osg *view;
QString path;
};


Cl_3D_Wallpaper::Cl_3D_Wallpaper(Cl_3Dview_osg *_parent): view(_parent),
path(QLatin1String("")) {

setCullingActive( false );

setClearMask( 0 );

setAllowEventFocus( false );

setReferenceFrame( osg::Transform::ABSOLUTE_RF );

setRenderOrder( osg::Camera::POST_RENDER );

setProjectionMatrix( osg::Matrix::ortho2D(0.0, 1.0, 0.0, 1.0) );

setName(getNodeName().toStdString().c_str());

osg::StateSet* ss = getOrCreateStateSet();

ss->setMode( GL_LIGHTING, osg::StateAttribute::OFF );

ss->setAttributeAndModes( new osg::Depth(osg::Depth::LEQUAL, 1.0, 1.0)
);

view->installDefaultShader(ss); // In case we are on gl3

}

/** Diese Methode erzeugt eine Hintergrundbildanzeige,

* falls der Pfad auf eine Bilddatei verweist.

*/

void Cl_3D_Wallpaper::setWallpaper(const QString _path) {

path = _path;

if (!_path.isEmpty()) {

// ================================================

// Die Szene des Bildes erzeugen

// ================================================

osg::Geode* geode = new osg::Geode();

osg::Geometry* geometry =
osg::createTexturedQuadGeometry(osg::Vec3(0,0,0),osg::Vec3(1,0,0),osg::Vec3(0,1,0),0,
0, 1, 1);

geode->addDrawable(geometry);

osg::Texture2D* texture = view->loadTexture(_path, false);


geode->getOrCreateStateSet()->setTextureAttributeAndModes(BASE_TEXTURE_UNIT,
texture, osg::StateAttribute:ShockedN);

geode->getOrCreateStateSet()->setMode(GL_LIGHTING,
osg::StateAttribute::OFF);

addChild(geode);

view->installDefaultShader(geode->getOrCreateStateSet()); //In case
we are on gl3

}

}

Now the part of getting a frame buffer screenshot:

/** The screen image is rendered at a pregiven dpi */

QImage Cl_3Dview_osg::getHighResQImage(const int _dpi) {

double scale = (double)_dpi / (double)dpi;

// Calculation of image size and tiles per row

int width = (int) (view->getGraphicsWidth());

int height = (int) (view->getGraphicsHeight());

int imageWidth = (int)(width * scale);

int imageHeight = (int)(height * scale);

int tiles = (imageWidth - 1) / width + 1;

osg::ref_ptr<osg::Image> image = new osg::Image;

// Creating the new camera
osg::ref_ptr<osg::Camera> camera = new osg::Camera;

camera->getOrCreateStateSet()->setGlobalDefaults();

camera->setClearColor(view->getCamera()->getClearColor());

camera->setViewport(new osg::Viewport(0,0,width,height));

camera->setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );

camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);

camera->setRenderOrder( osg::Camera::POST_RENDER );


camera->addChild(view->getCamera()->getChild(0)); // The root node

osg::ref_ptr<osg::Image> fbImage = new osg::Image;

fbImage->allocateImage(width,height,1,GL_RGBA,GL_UNSIGNED_BYTE, 1);

camera->attach( osg::Camera::COLOR_BUFFER, fbImage.get(), 0, 0);

// Setting the new camera a child of the main camera

view->getCamera()->addChild(camera.get());

// Loop over tiles
osg::Matrixd viewMatrix = view->getCamera()->getViewMatrix();

osg::Matrixd projectionMatrix =
view->getCamera()->getProjectionMatrix();

int y_out = imageHeight - 1;

for (int row = 0; row < tiles; row++) {

for (int col = 0; col < tiles; col++) {

// Calculate projection matrix offset of each tile

osg::Matrix offsetMatrix =

osg::Matrix::scale(scale, scale, 1.0) *

osg::Matrix::translate(scale-1-2*col, scale-1-2*row,
0.0);

camera->setViewMatrix(viewMatrix);

camera->setProjectionMatrix( projectionMatrix * offsetMatrix );

view->frame();
image = fbImage.get();

// Transferring tile into final image
.......

}

y_out -= height;

if (y_out < 0) break;

}

view->getCamera()->removeChild(camera.get());
}


The rendered image is missing my wallpaper.
If I add the camera as a slave camera to the main camera I just get an empty
black image.
Actually I also don't understand the difference between slave and child
cameras here. I know you explained it recently Smile
Why does the slave camera give an empty image but the child camera doesn't?

BTW. I wrote my code here with the background of giving an example to others
looking for functionality like that.





Am 24.02.2017 um 17:56 schrieb Robert Osfield:

Hi Werner,

In principle what you are doing should be possible. What is going
wrong in your instance is impossible to say without seeing how you are
setting up the viewer Camera's and the in scene graph Camera's.

Robert.

On 24 February 2017 at 16:44, Werner Modenbach
<> (
Only registered users can see emails on this board!
Get registred or enter the forums!
) wrote:

Hi all,
sorry for so many questions today.

My scene graph has additional cameras as children somewhere in the scene
graph.
For example a hud camera for a background image.

I do screenshots by adding a slave camera to the main camera which renders
the scene to the FB.
Unfortunately this rendering doesn't show the parts of the nested cameras,
i.e. no
background wallpaper.
What is the recommended way to solve this?

Thanks for any help.

- Werner -


_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

--
TEXION Software Solutions, Rotter Bruch 26a, D-52068 Aachen
Phone: +49 241 475757-0
Fax: +49 241 475757-29
Web: http://texion.eu
eMail: (
Only registered users can see emails on this board!
Get registred or enter the forums!
)

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


Joined: 06 Feb 2013
Posts: 56

PostPosted: Mon Feb 27, 2017 12:09 pm    Post subject:
How to handle cameras in the scene graph when rendering to framebuffer
Reply with quote

Sorry, found the second parameter of  setRenderOrder, but using this on the wallpaper and the framebuffer camera doen't make a difference, independent of the numbers I assign.

Am 27.02.2017 um 12:08 schrieb Werner Modenbach:

Quote:
Hi Robert,

you may be right. There are several (more) objects that have to be rendered in a certain sequence and PRE-/NORMAL-/POST-RENDER is
a little weak for fine grained tuning.
Can I use
Quote:
StateSet->setRenderBinDetails( 11, "RenderBin");

instead? That should work, isn't it?
What are the bin numbers usually used for the 3 modes?

Am 27.02.2017 um 12:02 schrieb Robert Osfield:

Quote:
Quote:
HI Werner,

It's hard to work exactly what is going on with a quick read through
as it's rather complicated set up of various Camera's. My current
best guess Your Cl_3D_Wallpaper class is setting the RenderOrder to
POST_RENDER as this is make it render after the Camera you are adding
to do the screenshot has been done.

Perhaps the best way to work out what order things are being done in
is to add a Camera initiali, pre, post and a final DrawCallbacks to
each of the Camera's and have these debug callbacks just write to the
console when they are being called.

Robert.

On 27 February 2017 at 10:34, Werner Modenbach
<> (
Only registered users can see emails on this board!
Get registred or enter the forums!
) wrote:
Quote:
Hi Robert,

sorry for the delayed answer. It's carnival time here and so everybody is
out - except me ;-)

I try to give an as compressed description as possible here.

The scene looks like that:
*

* ---------------

* | RootNode |

* ---------------

* /

* ---------------
---------------------

* | ShadowScene | |evtl.
PPU-Prozessor|

* ---------------
---------------------

* /

* --------------- ---------------

* | Switchnode | | LightSource |

* --------------- ---------------

* / \

* --------------- -----------------

* | User scene | | evtl. further |

* --------------- | Objects |

* -----------------

The further objects are the wallpaper, a magnifier etc.


The main camera is a standard camera with perspective view and a trackball
manipulator.
The wallpaper class is like that:
class Cl_3D_Wallpaper : public osg::Camera {

public:

Cl_3D_Wallpaper(Cl_3Dview_osg *_parent);

/** This Method creates the background image. */

void setWallpaper(const QString _path);

protected:
Cl_3Dview_osg *view;
QString path;
};


Cl_3D_Wallpaper::Cl_3D_Wallpaper(Cl_3Dview_osg *_parent): view(_parent),
path(QLatin1String("")) {

setCullingActive( false );

setClearMask( 0 );

setAllowEventFocus( false );

setReferenceFrame( osg::Transform::ABSOLUTE_RF );

setRenderOrder( osg::Camera::POST_RENDER );

setProjectionMatrix( osg::Matrix::ortho2D(0.0, 1.0, 0.0, 1.0) );

setName(getNodeName().toStdString().c_str());

osg::StateSet* ss = getOrCreateStateSet();

ss->setMode( GL_LIGHTING, osg::StateAttribute::OFF );

ss->setAttributeAndModes( new osg::Depth(osg::Depth::LEQUAL, 1.0, 1.0)
);

view->installDefaultShader(ss); // In case we are on gl3

}

/** Diese Methode erzeugt eine Hintergrundbildanzeige,

* falls der Pfad auf eine Bilddatei verweist.

*/

void Cl_3D_Wallpaper::setWallpaper(const QString _path) {

path = _path;

if (!_path.isEmpty()) {

// ================================================

// Die Szene des Bildes erzeugen

// ================================================

osg::Geode* geode = new osg::Geode();

osg::Geometry* geometry =
osg::createTexturedQuadGeometry(osg::Vec3(0,0,0),osg::Vec3(1,0,0),osg::Vec3(0,1,0),0,
0, 1, 1);

geode->addDrawable(geometry);

osg::Texture2D* texture = view->loadTexture(_path, false);


geode->getOrCreateStateSet()->setTextureAttributeAndModes(BASE_TEXTURE_UNIT,
texture, osg::StateAttribute:ShockedN);

geode->getOrCreateStateSet()->setMode(GL_LIGHTING,
osg::StateAttribute::OFF);

addChild(geode);

view->installDefaultShader(geode->getOrCreateStateSet()); //In case
we are on gl3

}

}

Now the part of getting a frame buffer screenshot:

/** The screen image is rendered at a pregiven dpi */

QImage Cl_3Dview_osg::getHighResQImage(const int _dpi) {

double scale = (double)_dpi / (double)dpi;

// Calculation of image size and tiles per row

int width = (int) (view->getGraphicsWidth());

int height = (int) (view->getGraphicsHeight());

int imageWidth = (int)(width * scale);

int imageHeight = (int)(height * scale);

int tiles = (imageWidth - 1) / width + 1;

osg::ref_ptr<osg::Image> image = new osg::Image;

// Creating the new camera
osg::ref_ptr<osg::Camera> camera = new osg::Camera;

camera->getOrCreateStateSet()->setGlobalDefaults();

camera->setClearColor(view->getCamera()->getClearColor());

camera->setViewport(new osg::Viewport(0,0,width,height));

camera->setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );

camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);

camera->setRenderOrder( osg::Camera::POST_RENDER );


camera->addChild(view->getCamera()->getChild(0)); // The root node

osg::ref_ptr<osg::Image> fbImage = new osg::Image;

fbImage->allocateImage(width,height,1,GL_RGBA,GL_UNSIGNED_BYTE, 1);

camera->attach( osg::Camera::COLOR_BUFFER, fbImage.get(), 0, 0);

// Setting the new camera a child of the main camera

view->getCamera()->addChild(camera.get());

// Loop over tiles
osg::Matrixd viewMatrix = view->getCamera()->getViewMatrix();

osg::Matrixd projectionMatrix =
view->getCamera()->getProjectionMatrix();

int y_out = imageHeight - 1;

for (int row = 0; row < tiles; row++) {

for (int col = 0; col < tiles; col++) {

// Calculate projection matrix offset of each tile

osg::Matrix offsetMatrix =

osg::Matrix::scale(scale, scale, 1.0) *

osg::Matrix::translate(scale-1-2*col, scale-1-2*row,
0.0);

camera->setViewMatrix(viewMatrix);

camera->setProjectionMatrix( projectionMatrix * offsetMatrix );

view->frame();
image = fbImage.get();

// Transferring tile into final image
.......

}

y_out -= height;

if (y_out < 0) break;

}

view->getCamera()->removeChild(camera.get());
}


The rendered image is missing my wallpaper.
If I add the camera as a slave camera to the main camera I just get an empty
black image.
Actually I also don't understand the difference between slave and child
cameras here. I know you explained it recently Smile
Why does the slave camera give an empty image but the child camera doesn't?

BTW. I wrote my code here with the background of giving an example to others
looking for functionality like that.





Am 24.02.2017 um 17:56 schrieb Robert Osfield:

Hi Werner,

In principle what you are doing should be possible. What is going
wrong in your instance is impossible to say without seeing how you are
setting up the viewer Camera's and the in scene graph Camera's.

Robert.

On 24 February 2017 at 16:44, Werner Modenbach
<> (
Only registered users can see emails on this board!
Get registred or enter the forums!
) wrote:

Hi all,
sorry for so many questions today.

My scene graph has additional cameras as children somewhere in the scene
graph.
For example a hud camera for a background image.

I do screenshots by adding a slave camera to the main camera which renders
the scene to the FB.
Unfortunately this rendering doesn't show the parts of the nested cameras,
i.e. no
background wallpaper.
What is the recommended way to solve this?

Thanks for any help.

- Werner -


_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

--
TEXION Software Solutions, Rotter Bruch 26a, D-52068 Aachen
Phone: +49 241 475757-0
Fax: +49 241 475757-29
Web: http://texion.eu
eMail: (
Only registered users can see emails on this board!
Get registred or enter the forums!
)


Quote:
_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

--
TEXION Software Solutions, Rotter Bruch 26a, D-52068 Aachen
Phone: +49 241 475757-0
Fax: +49 241 475757-29
Web: http://texion.eu
eMail: (
Only registered users can see emails on this board!
Get registred or enter the forums!
)

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


Joined: 26 Jan 2017
Posts: 56

PostPosted: Mon Feb 27, 2017 4:10 pm    Post subject:
Reply with quote

Hi,

You cna also just add the cameras in the right order and don't bother with the render orders. Something else is going wrong.

Cheers,
Johny
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 Polygon Rendering bhanu406 General 1 Thu Mar 16, 2017 9:18 am View latest post
No new posts How do cameras handle the render target? wernerM General 3 Wed Mar 15, 2017 9:59 am View latest post
No new posts Multiple cameras sharing multisample fbo ravidavi General 1 Sat Mar 11, 2017 8:17 am View latest post
No new posts About separate rendering of a slave c... wernerM General 0 Tue Mar 07, 2017 3:14 pm View latest post
No new posts Covert and use 3ds Max scene to OpenS... lucia General 0 Mon Mar 06, 2017 9:19 am 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