Hi,

Im currently working on what is basically the same problem. We want to be
able to have more than 8 lights in a scene and we want objects to be lit by
the N most influential lights.

We have decided not to support fixed function pipeline. Instead of
osg::LightSource/osg::Light we have a single custom Light node that is
registered with our LightManager. Each object that is lit queries the
lightmanager for the N most influential lights, similar to what your doing.
Uniforms are set based on the lights (gl_LightSource is not used) and the
shader loops over lights.

//Shader pseudo code
for each light L in lights
if L is directional
  do directional_light
else if L is point
  do point_light
else
  do spotlight

The last part is not fully implemented yet and im a bit worried about how it
will perform.


Currently the uniforms are set during the cull traversal by using a callback
on the drawables, but im not sure that this is the best or even a good way
of doing it. Is it better to do a a separate traversal by implementing a
NodeVisitor?

 /Andreas Lindmark

2008/10/13 Daniel Rowe <[EMAIL PROTECTED]>

> Hi everyone,
>
> This is my first post to osg-users, and I'd like to thank everyone who has
> contributed to OpenSceneGraph. I have found it to be indispensable.
>
> Currently I am modifying a Delta3D-based engine to select the most
> influential lights around an object, to allow our artists to place any
> number of lights in a scene without being restrained by the usual cap of 8
> lights.
>
> The algorithm is as follows: Upon being added to the scene, LightSources
> register themselves with the LightManager. Each lit object queries the
> LightManager for the 4 most influential lights (based on proximity and light
> intensity) during the Update traversal and assigns the appropriate shader to
> the node, such as the 1 directional 1 spot 2 point light shader, the 2
> directional 0 spot 1 point light shader, etc.
>
> The final problem I have to solve is to figure out how to get the correct
> lights into the correct order that the shaders will expect them in. I want
> to be able to ignore the default light number of the 4 light sources I'm
> using and be able to set them manually. However, this has proven difficult,
> since many lights will need multiple different indices, and assigning this
> in the update callback as I had originally planned would mean that every
> change except the last one would be overwritten.
>
> My first option is to write shaders with a list of uniforms for each light,
> and set the uniforms in the expected order. I have shied away from this
> approach for now to avoid bloated shaders, since GLSL has built-in uniforms
> for OpenGL lights.
>
> The second option, from what I've gathered, is to leverage
> osgUtil::RenderStage. As I see it, I'm going to need to clone the lights
> (managing them myself without adding them to the scene), re-number them
> appropriately, and add them to their own RenderStage, which also contains
> the lit object.
>
> I've dug extensively through past threads looking for information on
> RenderStage and selective lighting, but unfortunately I'm still somewhat
> clueless as to how the back end of the rendering works as a whole. How do
> RenderBins fit into this equation? Will I have to find a way to rip the lit
> object out of the default RenderStage and throw it into mine? Is this even a
> good approach, or is there a more elegant method I could use? Am I missing
> the point completely?
>
> Thanks in advance, everyone!
>
> - Daniel Rowe
>
> _______________________________________________
> 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

Reply via email to