Re: [osg-users] Draw Instanced intersections

2017-01-03 Thread Sebastian Messerschmidt

Hi Bruno,

There is simply no geometry in the scenegraph to intersect (or strictly 
speaking there is only one drawable)


Instancing takes away the load from the CPU to the GPU,which on the 
OSG-side means to put the instanced geometries into one drawable 
containing the instancing information.


You could use two scenes representing the rendered scene using the 
instances and another using  multiple drawables for intersection 
determination. If it is rather static, KD-Trees will help with 
performance on the intersection-set.



Apart from this, you could overwrite the intersections of DrawArrays 
with some method that takes instances into account, but that might get 
tricky as there are many different ways to realize instancing. I'd go 
with two scenes, using different node-masks for the intersection and the 
"draw"-scene, as it is the easiest approach.


Cheers
Sebastian




Hi, Oliveira,

there maybe many reasons that why no intersection. I cannot give you
advise without more information. u can check about examples within OSG
source code, e.g. "osgintersection".

--
Cheers,
---
TianZJ




At 2017-01-03 17:55:02, "Bruno Oliveira"
> wrote:

Hi TianZJ, Thanks for the quick answer.

I checked the intersector, but intersector->getIntersections()
returns no intersections at all.



2017-01-03 9:32 GMT+00:00 tianzjyh >:

Hi, Oliveira,
You can check the intersections of your intersector(e.g.
LineSegmentIntersector::Intersection), and you will find they
contain an "osg::NodePath", which means the whole path of the
node(e.g. matrix transform nodes upon the drawable instance).


--


Cheers,
---
TianZJ

At 2017-01-03 16:58:16, "Bruno Oliveira"
> wrote:

Hello,

I'm implementing a draw instanced optimized scene. This is
for drawing a set of polygons.

Previously I was creating a drawable for each polygon, but
now I am using draw instancing. With one drawable per
polygon I can easily use osg intersectors for computing
scene intersections. But how can I perform scene
intersections with draw instanced objects and get, for
instance, intersected instance IDs?






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


Re: [osg-users] Draw Instanced intersections

2017-01-03 Thread tianzjyh
Hi, Oliveira,


there maybe many reasons that why no intersection. I cannot give you advise 
without more information. u can check about examples within OSG source code, 
e.g. "osgintersection".


--

Cheers, 
---
TianZJ






At 2017-01-03 17:55:02, "Bruno Oliveira"  
wrote:

Hi TianZJ, Thanks for the quick answer.


I checked the intersector, but intersector->getIntersections() returns no 
intersections at all.





2017-01-03 9:32 GMT+00:00 tianzjyh :

Hi, Oliveira,
You can check the intersections of your intersector(e.g. 
LineSegmentIntersector::Intersection), and you will find they contain an 
"osg::NodePath", which means the whole path of the node(e.g. matrix transform 
nodes upon the drawable instance).



--





Cheers, 
---
TianZJ

At 2017-01-03 16:58:16, "Bruno Oliveira"  
wrote:

Hello,


I'm implementing a draw instanced optimized scene. This is for drawing a set of 
polygons.


Previously I was creating a drawable for each polygon, but now I am using draw 
instancing. With one drawable per polygon I can easily use osg intersectors for 
computing scene intersections. But how can I perform scene intersections with 
draw instanced objects and get, for instance, intersected instance IDs?






 


___
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] Draw Instanced intersections

2017-01-03 Thread Bruno Oliveira
Hi TianZJ, Thanks for the quick answer.

I checked the intersector, but intersector->getIntersections() returns no
intersections at all.



2017-01-03 9:32 GMT+00:00 tianzjyh :

> Hi, Oliveira,
> You can check the intersections of your intersector(e.g.
> LineSegmentIntersector::Intersection), and you will find they contain an
> "osg::NodePath", which means the whole path of the node(e.g. matrix
> transform nodes upon the drawable instance).
>
>
> --
>
>
> Cheers,
> ---
> TianZJ
>
> At 2017-01-03 16:58:16, "Bruno Oliveira" 
> wrote:
>
> Hello,
>
> I'm implementing a draw instanced optimized scene. This is for drawing a
> set of polygons.
>
> Previously I was creating a drawable for each polygon, but now I am using
> draw instancing. With one drawable per polygon I can easily use osg
> intersectors for computing scene intersections. But how can I perform scene
> intersections with draw instanced objects and get, for instance,
> intersected instance IDs?
>
>
>
>
>
> ___
> 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] Draw Instanced intersections

2017-01-03 Thread tianzjyh
Hi, Oliveira,
You can check the intersections of your intersector(e.g. 
LineSegmentIntersector::Intersection), and you will find they contain an 
"osg::NodePath", which means the whole path of the node(e.g. matrix transform 
nodes upon the drawable instance).



--





Cheers, 
---
TianZJ

At 2017-01-03 16:58:16, "Bruno Oliveira"  
wrote:

Hello,


I'm implementing a draw instanced optimized scene. This is for drawing a set of 
polygons.


Previously I was creating a drawable for each polygon, but now I am using draw 
instancing. With one drawable per polygon I can easily use osg intersectors for 
computing scene intersections. But how can I perform scene intersections with 
draw instanced objects and get, for instance, intersected instance IDs?

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


[osg-users] Draw Instanced intersections

2017-01-03 Thread Bruno Oliveira
Hello,

I'm implementing a draw instanced optimized scene. This is for drawing a
set of polygons.

Previously I was creating a drawable for each polygon, but now I am using
draw instancing. With one drawable per polygon I can easily use osg
intersectors for computing scene intersections. But how can I perform scene
intersections with draw instanced objects and get, for instance,
intersected instance IDs?
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Draw Instanced

2016-04-18 Thread Glenn Waldron
Yes, it's here:
https://github.com/gwaldron/osgearth/blob/master/src/osgEarth/Instancing.vert.glsl


Glenn Waldron

On Mon, Apr 18, 2016 at 3:49 PM, sam  wrote:

> Do you have an example of the shader that you used?
>
> On Mon, Apr 18, 2016 at 12:40 PM, Glenn Waldron 
> wrote:
>
>> That I do not know. But I do recall that my original DI implementation
>> tried to use UBOs, and I ditched them in favor of TBOs because of the size
>> limitations.
>>
>> Glenn Waldron
>>
>> On Fri, Apr 15, 2016 at 6:09 PM, sam  wrote:
>>
>>> Would there be a big performance difference between using a
>>> TextureBuffer Object and a UniformBuffer object?
>>>
>>> Thanks, Sam
>>>
>>> On Fri, Apr 15, 2016 at 1:15 PM, sam  wrote:
>>>
 Doh! Thanks, Glenn. Unfortunately I still have some holes in the map
 but its starting to look considerably better. I will definitely looking to
 using a TextureBuffer.

 On Fri, Apr 15, 2016 at 12:50 PM, Glenn Waldron 
 wrote:

> Sam,
> I think you are not calling setNumElements() on your uniform array.
> You could also do that in the osg::Uniform constructor.
>
> Anyway, a uniform array of matrices is going to be limiting in terms
> of scale and speed -- I'd recommend a buffer object instead. (osgEarth 
> uses
> an osg::TextureBuffer.)
>
>
> Glenn Waldron
>
> On Fri, Apr 15, 2016 at 2:35 PM, sam  wrote:
>
>> Hi All,
>>
>> I'm having some trouble getting my code to use hardware instancing.
>> I've referenced OSGEarth, DrawInstanced example, and a few different code
>> samples on the web. I've gotten pretty close but I seem to be at a bit of
>> an impasse.
>>
>> This screenshot shows what the map looks like with the default
>> rendering:
>>
>> http://imgur.com/fKvunfd
>>
>> This screenshot shows what the map looks like after I apply my
>> instance rendering code to it:
>>
>> http://imgur.com/zZCzurr
>>
>> The map is composed of a lot of little nodes. I figured instanced
>> rendering would be helpful in this case. The map has ~4000 individual
>> nodes. Two of the nodes are repeated 465 and 266 times. I have trimmed 
>> down
>> my code and it is posted here:
>>
>> http://pastebin.com/ifSVSzD6
>>
>> From what it looks like. Its rendering one copy of every nodes but
>> not anymore that that. I have commented out lines 215 to 224 as it 
>> doesn't
>> work at all. Any insight or help would be greatly appreciated.
>>
>> Thanks, Sam
>>
>> ___
>> 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 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 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] Draw Instanced

2016-04-18 Thread sam
Do you have an example of the shader that you used?

On Mon, Apr 18, 2016 at 12:40 PM, Glenn Waldron  wrote:

> That I do not know. But I do recall that my original DI implementation
> tried to use UBOs, and I ditched them in favor of TBOs because of the size
> limitations.
>
> Glenn Waldron
>
> On Fri, Apr 15, 2016 at 6:09 PM, sam  wrote:
>
>> Would there be a big performance difference between using a TextureBuffer
>> Object and a UniformBuffer object?
>>
>> Thanks, Sam
>>
>> On Fri, Apr 15, 2016 at 1:15 PM, sam  wrote:
>>
>>> Doh! Thanks, Glenn. Unfortunately I still have some holes in the map but
>>> its starting to look considerably better. I will definitely looking to
>>> using a TextureBuffer.
>>>
>>> On Fri, Apr 15, 2016 at 12:50 PM, Glenn Waldron 
>>> wrote:
>>>
 Sam,
 I think you are not calling setNumElements() on your uniform array. You
 could also do that in the osg::Uniform constructor.

 Anyway, a uniform array of matrices is going to be limiting in terms of
 scale and speed -- I'd recommend a buffer object instead. (osgEarth uses an
 osg::TextureBuffer.)


 Glenn Waldron

 On Fri, Apr 15, 2016 at 2:35 PM, sam  wrote:

> Hi All,
>
> I'm having some trouble getting my code to use hardware instancing.
> I've referenced OSGEarth, DrawInstanced example, and a few different code
> samples on the web. I've gotten pretty close but I seem to be at a bit of
> an impasse.
>
> This screenshot shows what the map looks like with the default
> rendering:
>
> http://imgur.com/fKvunfd
>
> This screenshot shows what the map looks like after I apply my
> instance rendering code to it:
>
> http://imgur.com/zZCzurr
>
> The map is composed of a lot of little nodes. I figured instanced
> rendering would be helpful in this case. The map has ~4000 individual
> nodes. Two of the nodes are repeated 465 and 266 times. I have trimmed 
> down
> my code and it is posted here:
>
> http://pastebin.com/ifSVSzD6
>
> From what it looks like. Its rendering one copy of every nodes but not
> anymore that that. I have commented out lines 215 to 224 as it doesn't 
> work
> at all. Any insight or help would be greatly appreciated.
>
> Thanks, Sam
>
> ___
> 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 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 mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Draw Instanced

2016-04-18 Thread Glenn Waldron
That I do not know. But I do recall that my original DI implementation
tried to use UBOs, and I ditched them in favor of TBOs because of the size
limitations.

Glenn Waldron

On Fri, Apr 15, 2016 at 6:09 PM, sam  wrote:

> Would there be a big performance difference between using a TextureBuffer
> Object and a UniformBuffer object?
>
> Thanks, Sam
>
> On Fri, Apr 15, 2016 at 1:15 PM, sam  wrote:
>
>> Doh! Thanks, Glenn. Unfortunately I still have some holes in the map but
>> its starting to look considerably better. I will definitely looking to
>> using a TextureBuffer.
>>
>> On Fri, Apr 15, 2016 at 12:50 PM, Glenn Waldron 
>> wrote:
>>
>>> Sam,
>>> I think you are not calling setNumElements() on your uniform array. You
>>> could also do that in the osg::Uniform constructor.
>>>
>>> Anyway, a uniform array of matrices is going to be limiting in terms of
>>> scale and speed -- I'd recommend a buffer object instead. (osgEarth uses an
>>> osg::TextureBuffer.)
>>>
>>>
>>> Glenn Waldron
>>>
>>> On Fri, Apr 15, 2016 at 2:35 PM, sam  wrote:
>>>
 Hi All,

 I'm having some trouble getting my code to use hardware instancing.
 I've referenced OSGEarth, DrawInstanced example, and a few different code
 samples on the web. I've gotten pretty close but I seem to be at a bit of
 an impasse.

 This screenshot shows what the map looks like with the default
 rendering:

 http://imgur.com/fKvunfd

 This screenshot shows what the map looks like after I apply my instance
 rendering code to it:

 http://imgur.com/zZCzurr

 The map is composed of a lot of little nodes. I figured instanced
 rendering would be helpful in this case. The map has ~4000 individual
 nodes. Two of the nodes are repeated 465 and 266 times. I have trimmed down
 my code and it is posted here:

 http://pastebin.com/ifSVSzD6

 From what it looks like. Its rendering one copy of every nodes but not
 anymore that that. I have commented out lines 215 to 224 as it doesn't work
 at all. Any insight or help would be greatly appreciated.

 Thanks, Sam

 ___
 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 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] Draw Instanced

2016-04-15 Thread sam
Would there be a big performance difference between using a TextureBuffer
Object and a UniformBuffer object?

Thanks, Sam

On Fri, Apr 15, 2016 at 1:15 PM, sam  wrote:

> Doh! Thanks, Glenn. Unfortunately I still have some holes in the map but
> its starting to look considerably better. I will definitely looking to
> using a TextureBuffer.
>
> On Fri, Apr 15, 2016 at 12:50 PM, Glenn Waldron 
> wrote:
>
>> Sam,
>> I think you are not calling setNumElements() on your uniform array. You
>> could also do that in the osg::Uniform constructor.
>>
>> Anyway, a uniform array of matrices is going to be limiting in terms of
>> scale and speed -- I'd recommend a buffer object instead. (osgEarth uses an
>> osg::TextureBuffer.)
>>
>>
>> Glenn Waldron
>>
>> On Fri, Apr 15, 2016 at 2:35 PM, sam  wrote:
>>
>>> Hi All,
>>>
>>> I'm having some trouble getting my code to use hardware instancing. I've
>>> referenced OSGEarth, DrawInstanced example, and a few different code
>>> samples on the web. I've gotten pretty close but I seem to be at a bit of
>>> an impasse.
>>>
>>> This screenshot shows what the map looks like with the default rendering:
>>>
>>> http://imgur.com/fKvunfd
>>>
>>> This screenshot shows what the map looks like after I apply my instance
>>> rendering code to it:
>>>
>>> http://imgur.com/zZCzurr
>>>
>>> The map is composed of a lot of little nodes. I figured instanced
>>> rendering would be helpful in this case. The map has ~4000 individual
>>> nodes. Two of the nodes are repeated 465 and 266 times. I have trimmed down
>>> my code and it is posted here:
>>>
>>> http://pastebin.com/ifSVSzD6
>>>
>>> From what it looks like. Its rendering one copy of every nodes but not
>>> anymore that that. I have commented out lines 215 to 224 as it doesn't work
>>> at all. Any insight or help would be greatly appreciated.
>>>
>>> Thanks, Sam
>>>
>>> ___
>>> 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 mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Draw Instanced

2016-04-15 Thread sam
Doh! Thanks, Glenn. Unfortunately I still have some holes in the map but
its starting to look considerably better. I will definitely looking to
using a TextureBuffer.

On Fri, Apr 15, 2016 at 12:50 PM, Glenn Waldron  wrote:

> Sam,
> I think you are not calling setNumElements() on your uniform array. You
> could also do that in the osg::Uniform constructor.
>
> Anyway, a uniform array of matrices is going to be limiting in terms of
> scale and speed -- I'd recommend a buffer object instead. (osgEarth uses an
> osg::TextureBuffer.)
>
>
> Glenn Waldron
>
> On Fri, Apr 15, 2016 at 2:35 PM, sam  wrote:
>
>> Hi All,
>>
>> I'm having some trouble getting my code to use hardware instancing. I've
>> referenced OSGEarth, DrawInstanced example, and a few different code
>> samples on the web. I've gotten pretty close but I seem to be at a bit of
>> an impasse.
>>
>> This screenshot shows what the map looks like with the default rendering:
>>
>> http://imgur.com/fKvunfd
>>
>> This screenshot shows what the map looks like after I apply my instance
>> rendering code to it:
>>
>> http://imgur.com/zZCzurr
>>
>> The map is composed of a lot of little nodes. I figured instanced
>> rendering would be helpful in this case. The map has ~4000 individual
>> nodes. Two of the nodes are repeated 465 and 266 times. I have trimmed down
>> my code and it is posted here:
>>
>> http://pastebin.com/ifSVSzD6
>>
>> From what it looks like. Its rendering one copy of every nodes but not
>> anymore that that. I have commented out lines 215 to 224 as it doesn't work
>> at all. Any insight or help would be greatly appreciated.
>>
>> Thanks, Sam
>>
>> ___
>> 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 mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Draw Instanced

2016-04-15 Thread Glenn Waldron
Sam,
I think you are not calling setNumElements() on your uniform array. You
could also do that in the osg::Uniform constructor.

Anyway, a uniform array of matrices is going to be limiting in terms of
scale and speed -- I'd recommend a buffer object instead. (osgEarth uses an
osg::TextureBuffer.)


Glenn Waldron

On Fri, Apr 15, 2016 at 2:35 PM, sam  wrote:

> Hi All,
>
> I'm having some trouble getting my code to use hardware instancing. I've
> referenced OSGEarth, DrawInstanced example, and a few different code
> samples on the web. I've gotten pretty close but I seem to be at a bit of
> an impasse.
>
> This screenshot shows what the map looks like with the default rendering:
>
> http://imgur.com/fKvunfd
>
> This screenshot shows what the map looks like after I apply my instance
> rendering code to it:
>
> http://imgur.com/zZCzurr
>
> The map is composed of a lot of little nodes. I figured instanced
> rendering would be helpful in this case. The map has ~4000 individual
> nodes. Two of the nodes are repeated 465 and 266 times. I have trimmed down
> my code and it is posted here:
>
> http://pastebin.com/ifSVSzD6
>
> From what it looks like. Its rendering one copy of every nodes but not
> anymore that that. I have commented out lines 215 to 224 as it doesn't work
> at all. Any insight or help would be greatly appreciated.
>
> Thanks, Sam
>
> ___
> 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] Draw Instanced

2016-04-15 Thread sam
Hi All,

I'm having some trouble getting my code to use hardware instancing. I've
referenced OSGEarth, DrawInstanced example, and a few different code
samples on the web. I've gotten pretty close but I seem to be at a bit of
an impasse.

This screenshot shows what the map looks like with the default rendering:

http://imgur.com/fKvunfd

This screenshot shows what the map looks like after I apply my instance
rendering code to it:

http://imgur.com/zZCzurr

The map is composed of a lot of little nodes. I figured instanced rendering
would be helpful in this case. The map has ~4000 individual nodes. Two of
the nodes are repeated 465 and 266 times. I have trimmed down my code and
it is posted here:

http://pastebin.com/ifSVSzD6

>From what it looks like. Its rendering one copy of every nodes but not
anymore that that. I have commented out lines 215 to 224 as it doesn't work
at all. Any insight or help would be greatly appreciated.

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


Re: [osg-users] Draw Instanced Help

2011-12-03 Thread Paul Martz

On 12/2/2011 8:04 PM, michael.a.bo...@l-3com.com wrote:

My question is this, if I load a file using

osgDB::readNodeFile(somefile.osg);

How would I set it up for instanced drawing?

My guess is that I would need to write a node-visitor that collects all
of the geometry -  drawables and sets them up to use the instanced call
overload instead of the default. I have tried doing this, but my
implementation has gotten pretty complex, and I want to make sure there
isn't a more simple way I have overlooked.


Yes, you'd need to write a NodeVisitor. It would have an apply(Geode) that 
iterates over each Drawable. If the Drawable is a Geometry, the code would 
further iterate over each PrimitiveSet and call setNumInstances() on each one. 
It really just boils down to a pair of nested loops. This doesn't seem 
particularly complex, so I wonder if you might be doing something different that 
is complicating things. Your description of what you're doing is pretty vague, 
so it's hard to tell.

   -Paul





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


[osg-users] Draw Instanced Help

2011-12-02 Thread Michael . A . Bosse
Hi Everyone,
Sorry, the last copy of this went out without a subject. Please
disregard, it has been a long day.
I'm trying to implement a fairly dense forested area and simply adding
in a bunch of osg::MatrixTransform nodes predictably causes the cull to
crash. I could try reorganizing the scene around an oct-tree as was
suggested by a previous discussion on this topic, but for draw
performance reasons, since each tree is the same model, I would like to
use the new draw instanced arb. I see that osgdrawinstanced has been
referenced in many similar threads, but osgdrawinstanced creates its
geometry on the fly, and in doing so can quite easily use the command
syntax for instancing. I am trying to apply the technique to a loaded
model and there is no obvious easy method.

My question is this, if I load a file using 

osgDB::readNodeFile(somefile.osg); 

How would I set it up for instanced drawing? 

My guess is that I would need to write a node-visitor that collects all
of the geometry - drawables and sets them up to use the instanced call
overload instead of the default. I have tried doing this, but my
implementation has gotten pretty complex, and I want to make sure there
isn't a more simple way I have overlooked.

Thank you very much for your time.

Michael A Bosse'

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


Re: [osg-users] Draw Instanced Help

2011-12-02 Thread Jean-Sébastien Guay

Hi Michael,


How would I set it up for instanced drawing?

My guess is that I would need to write a node-visitor that collects all
of the geometry -  drawables and sets them up to use the instanced call
overload instead of the default. I have tried doing this, but my
implementation has gotten pretty complex, and I want to make sure there
isn't a more simple way I have overlooked.


You've got the right idea for the general way to apply instanced 
rendering for complex objects. But you can simplify usage by making your 
model simpler.


Draw instanced will work really well if your model consists of a single 
primitiveset. So ideally you'll have your modeler create the tree in a 
single geometry with a single primitiveset. They can make a texture 
atlas so that the same texture file applies to the whole geometry, and 
then merge all the geometry into a single one.


If this is not possible, you can try using the osgUtil::Optimizer to do 
this for you as a pre-process. Using the artist's model as input, you 
would apply the SHARE_DUPLICATE_STATE, FLATTEN_STATIC_TRANSFORMS, 
MERGE_GEODES, MERGE_GEOMETRY, VERTEX_PRETRANSFORM, VERTEX_POSTTRANSFORM, 
INDEX_MESH and possibly TEXTURE_ATLAS_BUILDER optimizers on it. I use 
this combination on all models by the way, in combination with a few 
custom visitors it does wonders to cull and draw times. What these will do:


TEXTURE_ATLAS_BUILDER: Will merge many small textures into a single 
larger one, adjusting texture coordinates, which can then be shared by 
all those nodes. An artist-created texture atlas is better though, I've 
seen cases where the texture atlas builder in OSG will create a really 
large texture and use less than half the space in it, and other such 
inefficiencies. A human will also be better equipped to judge of the 
qualitative criteria in making some textures smaller thus fitting more 
textures into a single atlas.


SHARE_DUPLICATE_STATE: Make sure identical state is shared (uses the 
same pointer to the same object) instead of having multiple state 
attributes with the same value throughout your model. You might have to 
write a small visitor to help this optimizer a bit, essentially 
normalizing all state that your modeling tool might set differently from 
what you expect, but which has no effect on the final output. For 
example you could force all geometry to single sided, etc. The idea is 
to make sure the next steps will be able to merge as much as possible.


FLATTEN_STATIC_TRANSFORMS: Remove any transforms that are marked as 
static data variance. You might have to make a small visitor that will 
change the data variance to static on any transforms that you don't 
really need. Modeling programs have a tendency to put lots of transforms 
all over the place (in Maya for example, there are no groups, everything 
is a transform, even graph leaves are a transform plus a geometry...). 
Again this will make the next steps work more efficiently, because 
things that are separated by a transform can't be merged together. You 
might want to write another simple visitor that would remove unnecessary 
Group nodes. Once again things that are separated by a Group can't be 
merged together.


MERGE_GEODES, MERGE_GEOMETRY: Merge as many scene graph leaves together 
as possible. Again this will make the next steps work more efficiently. 
Note that the MERGE_GEODES optimizer in OSG has a pretty serious design 
flaw, it will only merge Geodes whose direct parent is a Group, and not 
any Group subclass. Sure, merging the children of an LOD node or Switch 
node is bad, but there are plenty of other subclass es of Group where it 
makes no difference. So I just subclassed the MergeGeodesVisitor so it 
checks the actual type of the parent, doesn't merge if it's certain 
types of Group subclasses (like LOD or Switch) but merges in all other 
cases.


VERTEX_PRETRANSFORM, VERTEX_POSTTRANSFORM, INDEX_MESH: This is a 
powerful trio of optimizers that will turn DrawArrays into DrawElements 
optimized for the GPU's cache, and merge all primitivesets under a 
Geometry together. After this, you might want to run the MERGE_GEODES 
and MERGE_GEOMETRY optimizers again, as they will be able to merge even 
more things together.


So anyways, I described why you would want to use the various optimizers 
for general models, but for your trees the goal is to end up with a 
single Geometry which has a single primitiveset. Then your job of doing 
instanced drawing of this tree becomes much easier. And again, if you 
can get your artist / modeler to make the model with this in mind, all 
the better. In general, if you can massage the data in order to make the 
code simpler, it's normally a win in the long run.


Hope this helps,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.dyndns-web.com/