Hi Paul,
I don't have a .osg file but can give you a very simple .cpp file that
reproduces the issue which is the modification of the "osgbillboard"
example. Is very interesting because as you can see at the end you can
choose the threading model which gives very interesting results. For
example in single threaded model i get 100 fps, in multi threaded
model I get around 140 which means that when coupled with a lot of
matrix transformations the multithreading can really boost
performances.
Another interesting issue is that turning on the stats slowly kills
the performances of the program with some threading models.
To test the frustum culling i simply move the camera in the block of
billboards and look around.
On Fri, May 23, 2008 at 5:26 PM, Michele Bosi <[EMAIL PROTECTED]> wrote:
> On Fri, May 23, 2008 at 5:06 PM, Robert Osfield
> <[EMAIL PROTECTED]> wrote:
>> Hi Michele,
>>
>> On Fri, May 23, 2008 at 3:58 PM, Michele Bosi <[EMAIL PROTECTED]> wrote:
>>> Thank you Robert,
>>> v-sync is off, I get around 90-100 FPS, when enabled OSG stats I get
>>> 3.4 for "cull" and 6.4 for "draw", also in this case the frame rate
>>> basically does not change but floats around the same range 90-100.
>>> Since the performances are already very good I wont dig more into the
>>> "problem", which might not be a "problem" but rather a lack of
>>> understanding of what's going on.
>>>
>>> Another thing: I instance a single Geometry (my quad billboard) then
>>> add it 4000 times to a Billboard node. I looked in the archives for
>>> "quadtree" but coulnd't find any info. How can I use the quadtrees you
>>> mentioned with OSG? Did you mean quadtrees to speedup frustum culling
>>> or a particular parent/child layout for OSG nodes?
>>
>> I'm afraid I can't teach you about general real-time graphics work I
>> have enough on my plate.
>>
>
> Thank you Robert, I know you are swamped of work and deliver for free
> a great service to the list, but I am afraid you don't need to teach
> me anything about quadtrees, I regularly work with quadtrees and
> octrees and implemented several of them.
>
>> There are lots of books and online resources on items like quad trees.
>> Lots in the archives too.
>>
>
> I looked in the archives through this web page:
> http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/
> and there are exactly 0 results for "quadtree" and "quad-tree".
>
> My question was very clear, and it has to do a lot with OSG and a few
> with quadtrees but probably it was a misunderstanding.
>
> In your mail you said: "Also with your scene graph, make sure you
> build a quad tree to store all those billboards, and avoid large flat
> node contains lots of children/drawables".
> Did you mean, "OSG has a quadtree class somewhere, use it" or
> "implement your own quadtree scene graph management, integrate it with
> OSG culling mechanics, and put your billboards in it"?
>
> Michele
>
>> Robert.
>> _______________________________________________
>> osg-users mailing list
>> [email protected]
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>
/* OpenSceneGraph example, osgbillboard.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <osg/Node>
#include <osg/Geometry>
#include <osg/Notify>
#include <osg/MatrixTransform>
#include <osg/Texture2D>
#include <osg/Billboard>
#include <osg/LineWidth>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
//
// A simple demo demonstrating different texturing modes,
// including using of texture extensions.
//
typedef std::vector< osg::ref_ptr<osg::Image> > ImageList;
/** create quad at specified position. */
osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3&
width,const osg::Vec3& height, osg::Image* image=NULL)
{
// set up the Geometry.
osg::Geometry* geom = new osg::Geometry;
geom->setUseDisplayList(false);
geom->setSupportsDisplayList(false);
geom->setUseVertexBufferObjects(false);
osg::Vec3Array* vert = new osg::Vec3Array;
//(*coords)[0] = corner;
//(*coords)[1] = corner+width;
//(*coords)[2] = corner+width+height;
//(*coords)[3] = corner+height;
vert->push_back( osg::Vec3( -0.5, 0.0, -0.5 ) );
vert->push_back( osg::Vec3( +0.5, 0.0, -0.5 ) );
vert->push_back( osg::Vec3( +0.5, 0.0, +0.5 ) );
vert->push_back( osg::Vec3( -0.5, 0.0, +0.5 ) );
geom->setVertexArray(vert);
osg::Vec3Array* norms = new osg::Vec3Array;
geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
norms->push_back( osg::Vec3(0,-1,0) );
norms->push_back( osg::Vec3(0,-1,0) );
norms->push_back( osg::Vec3(0,-1,0) );
norms->push_back( osg::Vec3(0,-1,0) );
#if 0
geom->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4) );
#else
osg::DrawElementsUInt* drawel = new
osg::DrawElementsUInt(osg::PrimitiveSet::QUADS);
drawel->push_back(0);
drawel->push_back(1);
drawel->push_back(2);
drawel->push_back(3);
geom->addPrimitiveSet( drawel );
#endif
geom->dirtyBound();
return geom;
}
osg::Drawable* createAxis(const osg::Vec3& corner,const osg::Vec3& xdir,const
osg::Vec3& ydir,const osg::Vec3& zdir)
{
// set up the Geometry.
osg::Geometry* geom = new osg::Geometry;
osg::Vec3Array* coords = new osg::Vec3Array(6);
(*coords)[0] = corner;
(*coords)[1] = corner+xdir;
(*coords)[2] = corner;
(*coords)[3] = corner+ydir;
(*coords)[4] = corner;
(*coords)[5] = corner+zdir;
geom->setVertexArray(coords);
osg::Vec4 x_color(0.0f,1.0f,1.0f,1.0f);
osg::Vec4 y_color(0.0f,1.0f,1.0f,1.0f);
osg::Vec4 z_color(1.0f,0.0f,0.0f,1.0f);
osg::Vec4Array* color = new osg::Vec4Array(6);
(*color)[0] = x_color;
(*color)[1] = x_color;
(*color)[2] = y_color;
(*color)[3] = y_color;
(*color)[4] = z_color;
(*color)[5] = z_color;
geom->setColorArray(color);
geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,6));
osg::StateSet* stateset = new osg::StateSet;
osg::LineWidth* linewidth = new osg::LineWidth();
linewidth->setWidth(4.0f);
stateset->setAttributeAndModes(linewidth,osg::StateAttribute::ON);
stateset->setMode(GL_LIGHTING,osg::StateAttribute::ON);
geom->setStateSet(stateset);
return geom;
}
osg::Node* createModel()
{
// create the root node which will hold the model.
osg::Group* root = new osg::Group();
osg::Drawable* square =
createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),NULL);
// add the drawable into a single goede to be shared...
osg::Billboard* center = new osg::Billboard();
center->setMode(osg::Billboard::POINT_ROT_EYE);
center->addDrawable(
square,
osg::Vec3(0.0f,0.0f,0.0f));
for(int i=0; i<4000; i++)
{
float x = (float)rand() / RAND_MAX * 50;
float y = (float)rand() / RAND_MAX * 50;
float z = (float)rand() / RAND_MAX * 50;
center->addDrawable(
square,
osg::Vec3(x,y,z)
);
}
//osg::Billboard* x_arrow = new osg::Billboard();
//x_arrow->setMode(osg::Billboard::AXIAL_ROT);
//x_arrow->setAxis(osg::Vec3(1.0f,0.0f,0.0f));
//x_arrow->setNormal(osg::Vec3(0.0f,-1.0f,0.0f));
//x_arrow->addDrawable(
//
createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Cubemap_axis/posx.png")),
// osg::Vec3(5.0f,0.0f,0.0f));
//osg::Billboard* y_arrow = new osg::Billboard();
//y_arrow->setMode(osg::Billboard::AXIAL_ROT);
//y_arrow->setAxis(osg::Vec3(0.0f,1.0f,0.0f));
//y_arrow->setNormal(osg::Vec3(1.0f,0.0f,0.0f));
//y_arrow->addDrawable(
//
createSquare(osg::Vec3(0.0f,-0.5f,-0.5f),osg::Vec3(0.0f,1.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Cubemap_axis/posy.png")),
// osg::Vec3(0.0f,5.0f,0.0f));
//osg::Billboard* z_arrow = new osg::Billboard();
//z_arrow->setMode(osg::Billboard::AXIAL_ROT);
//z_arrow->setAxis(osg::Vec3(0.0f,0.0f,1.0f));
//z_arrow->setNormal(osg::Vec3(0.0f,-1.0f,0.0f));
//z_arrow->addDrawable(
//
createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Cubemap_axis/posz.png")),
// osg::Vec3(0.0f,0.0f,5.0f));
// osg::Geode* axis = new osg::Geode();
//
axis->addDrawable(createAxis(osg::Vec3(0.0f,0.0f,0.0f),osg::Vec3(5.0f,0.0f,0.0f),osg::Vec3(0.0f,5.0f,0.0f),osg::Vec3(0.0f,0.0f,5.0f)));
root->addChild(center);
// root->addChild(x_arrow);
// root->addChild(y_arrow);
// root->addChild(z_arrow);
// root->addChild(axis);
return root;
}
int main(int, char**)
{
// construct the viewer
osgViewer::Viewer viewer;
viewer.addEventHandler(new osgViewer::WindowSizeHandler);
viewer.addEventHandler(new osgViewer::StatsHandler);
// set the scene to render
viewer.setSceneData(createModel());
switch(3)
{
case 0: viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); break;
// 197
case 1:
viewer.setThreadingModel(osgViewer::Viewer::CullDrawThreadPerContext); break;
// 162
case 2: viewer.setThreadingModel(osgViewer::Viewer::ThreadPerContext);
break; // 200
case 3: viewer.setThreadingModel(osgViewer::Viewer::DrawThreadPerContext);
break; // 300
case 4:
viewer.setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext);
break; // 300
case 5: viewer.setThreadingModel(osgViewer::Viewer::ThreadPerCamera);
break; // 170
case 6: viewer.setThreadingModel(osgViewer::Viewer::AutomaticSelection);
break;
}
// run the viewers frame loop
return viewer.run();
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org