Re: [osg-users] Rendering a scene to texture

2018-03-18 Thread Robert Osfield
HI Jochen,

On 18 March 2018 at 18:08, Jochen Maier  wrote:
> 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)


> 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
0x (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.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Rendering a scene to texture

2018-03-18 Thread Jochen Maier
Thank you very much Robert :)

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

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Render a Scene to texture

2018-03-18 Thread Robert Osfield
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:
> 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
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] View coordinates of a 3D point

2018-03-18 Thread Wojciech Lewandowski
Hi,

Knowing the 3D coordinates of a point, is there an easy way in OSG to
> compute its 2D projected equivalent (i.e. in pixel coordinates)?


Yes. In general your pixel coord is computed as:

pixel_coords = WindowMatrix * ProjectionMatrix * ViewMatrix * ModelMatrix *
point;

Your solution may vary whether you compute it in Update/Cull stage.
Visitiors may have some utility functions making it simpler. But here I
present more general solution:

osg::Vec3 point; // Your 3D point somewhere in the graph as a coord of some
vertex under some point_parent_node  Node
osg::Matrix ModelMatrix = point_parent_node->getWorldMatrices()[0]; //
Assuming your point have single parental path
osg::Matrix ViewMatrix = camera->getViewMatrix();
osg::Matrix ProjectionMatrix = camera->getProjectionMatrix();
osg::Matrix WindowMatrix = camera->getViewport()->computeWindowMatrix();

osg::Vec3 pixel_coords = WindowMatrix * ProjectionMatrix * ViewMatrix *
ModelMatrix * point;
// x i y are window screen coords z is depth coord

Cheers,
Wojtek


2018-03-16 13:37 GMT+01:00 Antoine Rennuit :

> Dear OSG forum,
>
> Knowing the 3D coordinates of a point, is there an easy way in OSG to
> compute its 2D projected equivalent (i.e. in pixel coordinates)?
>
> Thanks,
>
> Antoine.
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=73112#73112
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Render a Scene to texture

2018-03-18 Thread Jochen Maier
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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org