[osg-users] Many lights in OSG - solution

Chris Hanson xenon at alphapixel.com
Fri Oct 23 13:32:47 PDT 2015


Cool stuff.

Have you considered a non-FFP solution? Withthis, you could have more than
8 lights.

Also, there are alternative shader-based non-FFP rendering methods like
Forward+ that have already successfully been implemented in OSG-based tools
that offer a large number of lights with good performance:
https://www.youtube.com/watch?v=LHzNpAb_GjI&app=desktop


On Fri, Oct 23, 2015 at 9:58 AM, Jannik Heller <scrawl at baseoftrash.de>
wrote:

> Hi OSG friends,
>
> I will be wrapping up my OpenMW port to OpenSceneGraph soon and wanted to
> share a few things with you that I learned along the way. One such thing is
> the lighting system that I wrote. If you do a quick search on the mailing
> list, you will see that the OpenGL fixed pipeline supports a maximum of 8
> simultaneous lights and OSG inherits this limit. I have a lot more lights
> in my scenes, so I had to come up with a solution.
>
> What I ended up with is a new lighting system, that allows you to place
> any number of light sources in the scene graph, but then prior to rendering
> a particular model will set the 8 closest lights as the OpenGL lights. This
> is implemented as CullCallback for the individual models, pushing a
> StateSet with the correct lights onto the CullVisitor. I also needed to
> implement a custom StateAttribute for the light state, this is because when
> applying lights OpenGL multiplies the position specified with the current
> modelView matrix (which is no problem when you apply lights at beginning of
> frame like OSG does, but in my case the lights are applied in between
> renderning of models,Ii need to apply the lights in world space rather than
> relative to that model). The solution was to write a custom light
> StateAttribute that resets the modelView matrix to just the view matrix
> before applying the state, then reset again to modelView when done.
>
> The code is here and it should be easily adaptable to your own
> applications:
>
>
> https://github.com/OpenMW/openmw/blob/master/components/sceneutil/lightmanager.cpp
>
> https://github.com/OpenMW/openmw/blob/master/components/sceneutil/lightmanager.hpp
>
> Usage is pretty straight forward:
>
> - Decorate your scene graph with a LightManager node.
> - Create any number of LightSource's in the scene graph. The lightNum of
> the contained lights do not matter as they are not used.
> - Make sure that you have Mask_Lit (1<<16) in your update and cull masks
> where lighting is desired.
> - Add some LightListCallback's as CullCallback in your scene graph. Where
> you put the callbacks determines the granularity of the light lists, so can
> have an impact on visuals and performance. I recommend adding the callback
> onto individual model(s) (but not necessarily individual Drawable's as that
> would be slower).
>
> You can also combine the LightManager with regular OSG lighting. For
> example, if you need a "global" directional light in your scene that is
> always active, you can create it as a regular osg::LightSource and tell the
> LightManager to skip over it, using setStartLight(1). This would mean the
> LightManager is only managing lights 1-7 rather than all 8.
>
> Hope this might be useful to some OSG users as it took me a while to put
> together. I did find a previous topic about the subject (
> http://forum.openscenegraph.org/viewtopic.php?t=8325&view=previous ) but
> no satisfying solution was posted.
>
> I wonder if there is enough interest, could this turn into an official OSG
> example? Or even a new NodeKit or part of the core scene graph?
>
> By the way, I am super impressed that I was able to implement this feature
> without changing one line of code within OSG - the flexibility you get with
> the various visitors and callbacks is amazing. A big kudos goes to Robert
> for making the OSG so extensible!
>
> Cheers,
> Jannik
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=65420#65420
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



-- 
Chris 'Xenon' Hanson, omo sanza lettere. Xenon at AlphaPixel.com
http://www.alphapixel.com/
Training • Consulting • Contracting
3D • Scene Graphs (Open Scene Graph/OSG) • OpenGL 2 • OpenGL 3 • OpenGL 4 •
GLSL • OpenGL ES 1 • OpenGL ES 2 • OpenCL
Legal/IP • Code Forensics • Digital Imaging • GIS • GPS •
osgEarth • Terrain • Telemetry • Cryptography • LIDAR • Embedded • Mobile •
iPhone/iPad/iOS • Android
@alphapixel <https://twitter.com/alphapixel> facebook.com/alphapixel (775)
623-PIXL [7495]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20151023/b3c3bf49/attachment-0003.htm>


More information about the osg-users mailing list