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 

Rendering a scene to texture


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


Joined: 08 Oct 2017
Posts: 4

PostPosted: Sun Mar 18, 2018 10:12 am    Post subject:
Rendering a scene to texture
Reply with quote

Hi,

I want to do something like offscreen rendering.
What I want to do exactly:
I have one or more scenes (scene graphs) and one final scene.
The final scene contains a quad which has 1 texture.
Now I have 4 different scenes (scene graphs).
I want to render all these 4 scenes in 4 textures and use this textures for the quad.

My problem is:
How is it possible to render one scene seperattly in a texture without render it in a seperatly window?

My Design:
First the application-class
Code:

class Application
{
private:
osg::ref_ptr< osg::Group > mFinalScreenScene;
osg::ref_ptr< osg::Geode > mFinalScreenQuad;
osgViewer::Viewer mFinalViewer;

MyScene mSceneTest1;
MyScene mSceneTest2;
MyScene mSceneTest3;
MyScene mSceneTest4;

public:
Application();
~Application();

bool setup(const unsigned int& xPos, const unsigned int& yPos, const unsigned int& width, const unsigned int& height);

int run() {while(mFinalViewer.done()) mFinalViewer.frame();};

}


Now my < MyScene >-Class
Code:

class MyScene
{
private:
osgViewer::Viewer mViewer;
osg::ref_ptr< osg::Texture2D > mFinalRenderTexture;
// Root-Scene-Object
osg::ref_ptr< osg::Group > mRoot;

public:
virtual void setup(const unsigned int& cameraWidth, const unsigned int& cameraHeight);
osg::ref_ptr<osg::Texture2D> getFinalRenderedTexture() { return mFinalRenderTexture; };

void renderOneFrame() {mViewer.frame()};

}


... when I call MyScene::renderOneFrame() its rendered in a new window; and thats not what I want Sad

I hope you can understand my problem... because my english isn't very well^^

I've allready checked the compositeview example... but I don't understand it :/

Thank you!

Cheers,
Jochen
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12094

PostPosted: Sun Mar 18, 2018 2:15 pm    Post subject:
Render a Scene to texture
Reply with quote

HI Jochen,

What you need to do is use a render to texture (RTT) technique, with
rendering the six scenes to six separate textures or the six scenes to
the six faces of a cube map texture. The OSG supports both approaches
and each approach is essentially the same setup - you create an
osg::Camera to render each scene to a texture/texture face, the only
difference is the assignment of the texture(s) to the various Cameras.

Another decision you need to make is how you want to interact with
each scene - it's a fixed view of each scene, or do you want to treat
it as a separate View with it's own camera manipulator/event handlers?
With a fixed view then you could just set each Camera's View matrix
at setup time, add the scene as a subgraph to the Camera and then add
this Camera to the scene graph. If you want each View to be
interactive then you could do this using CompositeView with each scene
having it's own osgViewer::View.

In all these case the Camera set up, whether it's a render to texture
Camera in the scene graph or a the master Camera of osgVIewer::View
will essential be the same - you just assign the texture/texture face
to each Camera.

Then you'll want to have one last Camera or View (with it's master
Camera) that renders to the window and use all the results from the
RTT Camera's. To ensure that the various RTT Camera's are rendered
before the main Camera you'll want to use
Camera::setRenderOrder(osg::Camera::PRE_RENDER);

There aren't any OSG examples that do exactly what you want, but you
can have a look at the osgprerender, oreprerendercubemap and
osgdistorion examples to see how RTT can be done in various ways. The
osgcompositeviewer will also give an illustrate of using multiple
Views with multiple Scenes, this example doesn't do an RTT but could
easily be adapted to do so by adding the appropriate texture
attachments and render order settings.

Hopefully once you get familiar with RTT osg::Camera usage it'll all
start to make sense - this part of the OSG is very powerful and
flexible but can be a bit overwhelming the first time you start to
dive in.

Robert.



On 18 March 2018 at 10:12, Jochen Maier <> wrote:
Quote:
Hi,

I want to do something like offscreen rendering.
What I want to do exactly:
I have one or more scenes (scene graphs) and one final scene.
The final scene contains a cube which has 6 different textures.
Now I have 6 different scenes (scene graphs).
I want to render all these 6 scenes in 6 textures and use this textures for the cube.

My problem is:
How is it possible to render one scene in a texture without render it in a seperatly window?

I hope you can understand my problem... because my english isn't very well^^

I've allready checked the compositeview example... but I don't understand it :/

Thank you!

Cheers,
Jochen

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=73124#73124








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


Joined: 08 Oct 2017
Posts: 4

PostPosted: Sun Mar 18, 2018 6:08 pm    Post subject:
Reply with quote

Thank you very much Robert Smile

Okay, I'll take a look at the examples you had talked about.

I know that the way is to realize this is using different cameras and render to texture. But I don't know how to initiate the rendering-process; I only know this by calling Viewer::frame(). I thought there is another way.

btw:
I was thinking a little bit of this and my idea was:
There are different scene-roots (osg::group). Add all my scene childs to each osg::group.
Now I set for the RTT the sceneData which I want to render to texture (osgViewer::setSceneData(sceneToRenderToTexture)) and the camera which renders to texture and call osgViewer::frame().
Done!! I have a texture wich shows my scene (sceneToRenderToTexture).

Is this an option to solve my problem?

Cheers,
Jochen
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12094

PostPosted: Sun Mar 18, 2018 8:24 pm    Post subject:
Rendering a scene to texture
Reply with quote

HI Jochen,

On 18 March 2018 at 18:08, Jochen Maier <> wrote:
Quote:
I know that the way is to realize this is using different cameras and render to texture. But I don't know how to initiate the rendering-process; I only know this by calling Viewer::frame(). I thought there is another way.

Viewer::frame() kicks update, event and renderingTraverls(), the later
does the cull traversal (works out what data needs to be drawn in this
frame) and draw dispatch traversal (send data to OpenGL)


Quote:
btw:
I was thinking a little bit of this and my idea was:
There are different scene-roots (osg::group). Add all my scene childs to each osg::group.
Now I set for the RTT the sceneData which I want to render to texture (osgViewer::setSceneData(sceneToRenderToTexture)) and the camera which renders to texture and call osgViewer::frame().
Done!! I have a texture wich shows my scene (sceneToRenderToTexture).

Is this an option to solve my problem?

It's difficult to work exactly what you mean from this description.
As I don't understand what you mean I can't say whether it's a
sensible approach or not.

As a general note, the design of the OSG RTT system using osg::Camera
and osgViewer provides all the power and flexibility you need to do
what you need to do, there shouldn't be any need to add an extra
complexity into the main loop, just configure the scene graph or
viewer to do the rendering you need to do and just call viewer.run()
or frame() within a frame loop and everything should just work.

If you only want to update a subset of the RTT Camera's per frame you
can toggle them on/off by setting their NodeMask to 0x0 (for off) and
0xffffffff (for on). If you are using RTT Camera's in the scene graph
you can also using osg::Switch nodes to toggle thins on/off or use
your own custom cull callback above the RTT Camera's to decide whether
they should be traversed or not.

There is so much power and flexibility in this system you are best to
spend the time understanding the examples to see all the different
ways osg::Camera can be used. Just do a search for osg::Camera in the
whole OSG code base and you'll see it popping up in lots of places for
various different purposes.

Robert.


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


Joined: 08 Oct 2017
Posts: 4

PostPosted: Mon Mar 19, 2018 7:15 am    Post subject:
Reply with quote

Okay, thank you.

I will study the examples und do some research for RTT in osg Smile

Cheers,
Jochen
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 CompositeViewer with multiple view, a... Angel General 3 Tue Aug 28, 2018 1:15 pm View latest post
No new posts Rend to Texture Once GuiYe General 1 Sun Aug 26, 2018 7:31 am View latest post
No new posts Can't share Texture among several tex... mp3butcher General 1 Fri Aug 17, 2018 11:06 pm View latest post
No new posts minor change: move assumeSizedInterna... mp3butcher General 9 Wed Aug 15, 2018 10:07 pm View latest post
No new posts Minor change proposal : Blacklist usa... mp3butcher General 14 Mon Aug 13, 2018 1:42 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