<div dir="ltr">Hi Robert,<div><br></div><div>I am very thankful for every hint, really. These hints are really valuable for optimization. And I found the issue, it was pre/post multiply order of the matrices. I was to avoid the calculus from the nodepath and use the ModelView matrix already available in the CullVisitor. Here is the snippet for someone who might face the same issue:</div><div><br></div><div><div>osg::Matrixd inverseViewMatrix = getCurrentCamera()->getInverseViewMatrix();</div><div>osg::Matrixd modelViewMatrix = (*getModelViewMatrix());</div><div>osg::Matrixd worldMatrix = osg::computeLocalToWorld(getNodePath());</div><div>osg::Matrixd worldMatrix2 = modelViewMatrix * inverseViewMatrix;</div></div><div><br></div><div>worldMatrix is equal to worldMatrix2 .. It was really the order of the matrices. I was under impression it is the same as in GLSL</div><div><br></div><div>Thanks a bunch again!</div><div><br></div><div>Cheers,</div><div>Nick</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 3, 2016 at 2:59 PM, 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">I don't have time to dive deeply in user projects, I can do quick<br>
scans of email and provide quick replies where possible. In terms of<br>
optimization I'd say avoiding the inverse matrix might be useful.<br>
Using the Matrix.postMultTrans/<wbr>preMultTrans would also be another<br>
optimization step you could use. The use of the UserValue looks like<br>
it won't be thread safe or even safe n the presence of multiple cull<br>
traversals.<br>
<br>
On 3 November 2016 at 11:40, Trajce Nikolov NICK<br>
<div class="HOEnZb"><div class="h5"><<a href="mailto:trajce.nikolov.nick@gmail.com">trajce.nikolov.nick@gmail.com</a><wbr>> wrote:<br>
> Thanks Robert,<br>
><br>
> I am aware of it, it is already used in my second snippet. Here it is: (is<br>
> it done properly?)<br>
><br>
> void MyCullVisitor::apply(osg::<wbr>LightSource& node)<br>
> {<br>
><br>
> osg::Matrixd inverseViewMatrix =<br>
> osg::Matrixd::inverse(<wbr>getCurrentCamera()-><wbr>getViewMatrix());<br>
> osg::Matrixd worldMatrix = inverseViewMatrix * (*getModelViewMatrix());<br>
><br>
> osg::Vec3d pos(node.getLight()-><wbr>getPosition().x(),<br>
> node.getLight()->getPosition()<wbr>.y(), node.getLight()->getPosition()<wbr>.z());<br>
> worldMatrix = osg::Matrixd::translate(pos) * worldMatrix;<br>
><br>
> node.setUserValue("<wbr>WorldMatrix", worldMatrix);<br>
> if (node.getLight()->getLightNum(<wbr>) == 0)<br>
> {<br>
> osgUtil::CullVisitor::apply(<wbr>node);<br>
> }<br>
> }<br>
><br>
><br>
> On Thu, Nov 3, 2016 at 9:14 AM, Robert Osfield <<a href="mailto:robert.osfield@gmail.com">robert.osfield@gmail.com</a>><br>
> wrote:<br>
>><br>
>> 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>
>> <<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<br>
>> > LightSource<br>
>> > and the ViewMatrix (which is the same as the World inverse just with<br>
>> > some<br>
>> > extra rotation). In my code after the update before the rendering<br>
>> > traversal<br>
>> > I am updating these matrices each frame and I am about to place this<br>
>> > code in<br>
>> > my custom CullVisitor (which traverse the scene anyway but only the<br>
>> > active<br>
>> > children).<br>
>> ><br>
>> > Here is my approach at the moment: list of light entities and here is<br>
>> > 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<br>
>> > node<br>
>> > path. This seams to be costly<br>
>> ><br>
>> > I am after wiser optimization, to place this in my CullVistor: Here is<br>
>> > 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>
>> > ______________________________<wbr>_________________<br>
>> > osg-users mailing list<br>
>> > <a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.<wbr>openscenegraph.org</a><br>
>> ><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>
><br>
><br>
><br>
><br>
> --<br>
> trajce nikolov nick<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>
><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>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">trajce nikolov nick<br></div>
</div>