<div dir="ltr">Thanks Robert,<div><br></div><div>I am aware of it, it is already used in my second snippet. Here it is: (is it done properly?)</div><div><br></div><div><ol class="gmail-cpp" style="color:rgb(172,172,172);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(247,247,247);margin:0px;padding:0px 0px 0px 55px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono",monospace,serif;font-size:12px"><li class="gmail-li1" style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(255,255,255)"><div class="gmail-de1" style="padding:0px 8px;vertical-align:top;color:rgb(51,51,51);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><span class="gmail-kw4" style="color:rgb(0,0,255)">void</span> MyCullVisitor<span class="gmail-sy4" style="color:rgb(0,128,128)">::</span><span class="gmail-me2" style="color:rgb(0,119,136)">apply</span><span class="gmail-br0" style="color:rgb(0,128,0)">(</span>osg<span class="gmail-sy4" style="color:rgb(0,128,128)">::</span><span class="gmail-me2" style="color:rgb(0,119,136)">LightSource</span><span class="gmail-sy3" style="color:rgb(0,0,64)">&</span> node<span class="gmail-br0" style="color:rgb(0,128,0)">)</span></div></li><li class="gmail-li1" style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(255,255,255)"><div class="gmail-de1" style="padding:0px 8px;vertical-align:top;color:rgb(51,51,51);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><span class="gmail-br0" style="color:rgb(0,128,0)">{</span>              </div></li><li class="gmail-li1" style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(255,255,255)"><div class="gmail-de1" style="padding:0px 8px;vertical-align:top;color:rgb(51,51,51);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">   </div></li><li class="gmail-li1" style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(255,255,255)"><div class="gmail-de1" style="padding:0px 8px;vertical-align:top;color:rgb(51,51,51);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">    osg<span class="gmail-sy4" style="color:rgb(0,128,128)">::</span><span class="gmail-me2" style="color:rgb(0,119,136)">Matrixd</span> inverseViewMatrix <span class="gmail-sy1" style="color:rgb(0,0,128)">=</span> osg<span class="gmail-sy4" style="color:rgb(0,128,128)">::</span><span class="gmail-me2" style="color:rgb(0,119,136)">Matrixd</span><span class="gmail-sy4" style="color:rgb(0,128,128)">::</span><span class="gmail-me2" style="color:rgb(0,119,136)">inverse</span><span class="gmail-br0" style="color:rgb(0,128,0)">(</span>getCurrentCamera<span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span><span class="gmail-sy2" style="color:rgb(0,0,64)">-</span><span class="gmail-sy1" style="color:rgb(0,0,128)">></span>getViewMatrix<span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span><span class="gmail-sy4" style="color:rgb(0,128,128)">;</span></div></li><li class="gmail-li2" style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(255,255,255)"><div class="gmail-de2" style="padding:0px 8px;vertical-align:top;color:rgb(51,51,51);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">    osg<span class="gmail-sy4" style="color:rgb(0,128,128)">::</span><span class="gmail-me2" style="color:rgb(0,119,136)">Matrixd</span> worldMatrix <span class="gmail-sy1" style="color:rgb(0,0,128)">=</span> inverseViewMatrix <span class="gmail-sy2" style="color:rgb(0,0,64)">*</span> <span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-sy2" style="color:rgb(0,0,64)">*</span>getModelViewMatrix<span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span><span class="gmail-sy4" style="color:rgb(0,128,128)">;</span></div></li><li class="gmail-li1" style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(255,255,255)"><div class="gmail-de1" style="padding:0px 8px;vertical-align:top;color:rgb(51,51,51);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"> </div></li><li class="gmail-li1" style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(255,255,255)"><div class="gmail-de1" style="padding:0px 8px;vertical-align:top;color:rgb(51,51,51);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">    osg<span class="gmail-sy4" style="color:rgb(0,128,128)">::</span><span class="gmail-me2" style="color:rgb(0,119,136)">Vec3d</span> pos<span class="gmail-br0" style="color:rgb(0,128,0)">(</span>node.<span class="gmail-me1" style="color:rgb(0,119,136)">getLight</span><span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span><span class="gmail-sy2" style="color:rgb(0,0,64)">-</span><span class="gmail-sy1" style="color:rgb(0,0,128)">></span>getPosition<span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span>.<span class="gmail-me1" style="color:rgb(0,119,136)">x</span><span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span>, node.<span class="gmail-me1" style="color:rgb(0,119,136)">getLight</span><span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span><span class="gmail-sy2" style="color:rgb(0,0,64)">-</span><span class="gmail-sy1" style="color:rgb(0,0,128)">></span>getPosition<span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span>.<span class="gmail-me1" style="color:rgb(0,119,136)">y</span><span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span>, node.<span class="gmail-me1" style="color:rgb(0,119,136)">getLight</span><span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span><span class="gmail-sy2" style="color:rgb(0,0,64)">-</span><span class="gmail-sy1" style="color:rgb(0,0,128)">></span>getPosition<span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span>.<span class="gmail-me1" style="color:rgb(0,119,136)">z</span><span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span><span class="gmail-sy4" style="color:rgb(0,128,128)">;</span></div></li><li class="gmail-li1" style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(255,255,255)"><div class="gmail-de1" style="padding:0px 8px;vertical-align:top;color:rgb(51,51,51);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">    worldMatrix <span class="gmail-sy1" style="color:rgb(0,0,128)">=</span> osg<span class="gmail-sy4" style="color:rgb(0,128,128)">::</span><span class="gmail-me2" style="color:rgb(0,119,136)">Matrixd</span><span class="gmail-sy4" style="color:rgb(0,128,128)">::</span><span class="gmail-me2" style="color:rgb(0,119,136)">translate</span><span class="gmail-br0" style="color:rgb(0,128,0)">(</span>pos<span class="gmail-br0" style="color:rgb(0,128,0)">)</span> <span class="gmail-sy2" style="color:rgb(0,0,64)">*</span> worldMatrix<span class="gmail-sy4" style="color:rgb(0,128,128)">;</span></div></li><li class="gmail-li1" style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(255,255,255)"><div class="gmail-de1" style="padding:0px 8px;vertical-align:top;color:rgb(51,51,51);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"> </div></li><li class="gmail-li2" style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(255,255,255)"><div class="gmail-de2" style="padding:0px 8px;vertical-align:top;color:rgb(51,51,51);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">    node.<span class="gmail-me1" style="color:rgb(0,119,136)">setUserValue</span><span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-st0" style="color:rgb(255,0,0)">"WorldMatrix"</span>, worldMatrix<span class="gmail-br0" style="color:rgb(0,128,0)">)</span><span class="gmail-sy4" style="color:rgb(0,128,128)">;</span></div></li><li class="gmail-li1" style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(255,255,255)"><div class="gmail-de1" style="padding:0px 8px;vertical-align:top;color:rgb(51,51,51);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">    <span class="gmail-kw1" style="color:rgb(0,0,255)">if</span> <span class="gmail-br0" style="color:rgb(0,128,0)">(</span>node.<span class="gmail-me1" style="color:rgb(0,119,136)">getLight</span><span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span><span class="gmail-sy2" style="color:rgb(0,0,64)">-</span><span class="gmail-sy1" style="color:rgb(0,0,128)">></span>getLightNum<span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span> <span class="gmail-sy1" style="color:rgb(0,0,128)">==</span> <span class="gmail-nu0" style="color:rgb(0,0,221)">0</span><span class="gmail-br0" style="color:rgb(0,128,0)">)</span></div></li><li class="gmail-li1" style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(255,255,255)"><div class="gmail-de1" style="padding:0px 8px;vertical-align:top;color:rgb(51,51,51);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">    <span class="gmail-br0" style="color:rgb(0,128,0)">{</span></div></li><li class="gmail-li1" style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(255,255,255)"><div class="gmail-de1" style="padding:0px 8px;vertical-align:top;color:rgb(51,51,51);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">        osgUtil<span class="gmail-sy4" style="color:rgb(0,128,128)">::</span><span class="gmail-me2" style="color:rgb(0,119,136)">CullVisitor</span><span class="gmail-sy4" style="color:rgb(0,128,128)">::</span><span class="gmail-me2" style="color:rgb(0,119,136)">apply</span><span class="gmail-br0" style="color:rgb(0,128,0)">(</span>node<span class="gmail-br0" style="color:rgb(0,128,0)">)</span><span class="gmail-sy4" style="color:rgb(0,128,128)">;</span></div></li><li class="gmail-li1" style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(255,255,255)"><div class="gmail-de1" style="padding:0px 8px;vertical-align:top;color:rgb(51,51,51);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">    <span class="gmail-br0" style="color:rgb(0,128,0)">}</span></div></li><li class="gmail-li2" style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(255,255,255)"><div class="gmail-de2" style="padding:0px 8px;vertical-align:top;color:rgb(51,51,51);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(248,248,248)"><span class="gmail-br0" style="color:rgb(0,128,0)">}</span></div></li></ol></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 3, 2016 at 9:14 AM, Robert Osfield <span dir="ltr"><<a href="mailto:robert.osfield@gmail.com" target="_blank">robert.osfield@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Nick,<br>
<br>
The osgUtil::CullVisitor has the maintains a stack of ModelViewMatrix<br>
that it accumulates through the the scene graph traversal, you should<br>
just need to get the top of this stack using<br>
cullVisitor-><wbr>getModelViewMatrix().<br>
<br>
Robert.<br>
<br>
On 2 November 2016 at 22:25, Trajce Nikolov NICK<br>
<div><div class="h5"><<a href="mailto:trajce.nikolov.nick@gmail.com">trajce.nikolov.nick@gmail.com</a><wbr>> wrote:<br>
> Hi Community,<br>
><br>
> I am trying to optimize the rendering. Getting huge update numbers.<br>
><br>
> The story is this:<br>
> My scene has huge number of lights, some are static (streetlights) some<br>
> dynamic (a car). The lighting engine needs the World matrix of a LightSource<br>
> and the ViewMatrix (which is the same as the World inverse just with some<br>
> extra rotation). In my code after the update before the rendering traversal<br>
> I am updating these matrices each frame and I am about to place this code in<br>
> my custom CullVisitor (which traverse the scene anyway but only the active<br>
> children).<br>
><br>
> Here is my approach at the moment: list of light entities and here is how I<br>
> am computing these:<br>
> <a href="http://pastebin.com/0A64sc7Y" rel="noreferrer" target="_blank">http://pastebin.com/0A64sc7Y</a><br>
> Simply getting the NodePath and computing the world matrix from this node<br>
> path. This seams to be costly<br>
><br>
> I am after wiser optimization, to place this in my CullVistor: Here is the<br>
> snippet:<br>
> <a href="http://pastebin.com/6dQnih8N" rel="noreferrer" target="_blank">http://pastebin.com/6dQnih8N</a><br>
><br>
> These snippets are simple and I would like to ask if this is more proper<br>
> way, which it seams to me since I will gain more performance by updating<br>
> only the culled and active nodes. Also the math in the cull visitor.<br>
><br>
> Thanks a lot for any hints, ideas. As always :-)<br>
><br>
> Cheers,<br>
> Nick<br>
><br>
> --<br>
> trajce nikolov nick<br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> osg-users mailing list<br>
> <a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.<wbr>openscenegraph.org</a><br>
> <a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.<wbr>org/listinfo.cgi/osg-users-<wbr>openscenegraph.org</a><br>
><br>
______________________________<wbr>_________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.<wbr>openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.<wbr>org/listinfo.cgi/osg-users-<wbr>openscenegraph.org</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">trajce nikolov nick<br></div>
</div>