Google

Fixed light order.

Problems building or running the engine, queries about how to use features etc.

Moderators: OGRE Team, Moderators

Fixed light order.

Postby mkultra333 » Mon Aug 10, 2009 6:49 pm

I am lighting a scene with 4 lights. My understanding is that once the lights go out to the shaders they might be in any order, light 0 in my program might not be light 0 in the shader, they get sorted by distance and stuff.

I don't want this. I want to know that light 0 to light 3 as I declare them in my program will also be light 0 to light 3 in my shader. I need this because my shader is going to do some different things in one pass depending on which light it is.

Doing searching, I see some stuff about lightlists and renderable listeners or something, I didnt understand it and it seemed like a lot of work to achieve something very simple.

How do I turn off all this unwanted scrambling of the light orders?
mkultra333
Veteran
 
Posts: 673
Joined: Sun Mar 08, 2009 5:25 am

Re: Fixed light order.

Postby nikki » Mon Aug 10, 2009 6:56 pm

What if you have 12 lights and the limit is 4, and the first light is is furthest away from the object, so that the first light in your shader cannot be the first light that you created?

Maybe you could store some 'light index' in the alpha of the light colour and then check with that?
User avatar
nikki
Veteran
 
Posts: 2666
Joined: Sat Sep 17, 2005 10:08 am
Location: Doha, Qatar.

Re: Fixed light order.

Postby mkultra333 » Mon Aug 10, 2009 7:03 pm

nikki wrote:What if you have 12 lights and the limit is 4, and the first light is is furthest away from the object, so that the first light in your shader cannot be the first light that you created?

Maybe you could store some 'light index' in the alpha of the light colour and then check with that?


There will never be 12 lights, only 4.

That alpha idea might work, but the problem then is that my shader has to waste time, at the fragment level, working out which light is which before proceeding. If instead it just knew that light 0 was really light 0, that would be much better.

Edit: Do lights have an alpha colour? The Api says you set the diffuse by

Code: Select all
void Ogre::Light::setDiffuseColour ( Real red, Real green, Real blue)    
mkultra333
Veteran
 
Posts: 673
Joined: Sun Mar 08, 2009 5:25 am

Re: Fixed light order.

Postby mkultra333 » Mon Aug 10, 2009 8:06 pm

After poking around in the Ogre source and the API, I found Ogre::SceneManager::Listener::sortLightsAffectingFrustum(LightList & lightList ) [virtual]

This sounds like it might be able to do what I want, allowing me to control the light order manually. But I don't really understand how I'm supposed to use it. Any tips? (Assume I have a low understanding of listeners and lightlists :) )
mkultra333
Veteran
 
Posts: 673
Joined: Sun Mar 08, 2009 5:25 am

Re: Fixed light order.

Postby nullsquared » Mon Aug 10, 2009 10:36 pm

Create a class that inherits from SceneManager::Listener, override that function, inside clear the LightList and push_back() your lights in the correct order, and then do sceneMgr->setListener(&anInstanceOfYourListener);
User avatar
nullsquared
OGRE Expert User
OGRE Expert User
 
Posts: 3257
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA

Re: Fixed light order.

Postby mkultra333 » Wed Aug 12, 2009 1:29 pm

Thanks nullsquared.

I set it up as follows, copied more or less from the shadow listener already in the code (unused):

Code: Select all
   struct LightOrderListener: public Ogre::SceneManager::Listener
   {


      bool sortLightsAffectingFrustum(LightList & lightList )
      {
         return true ;         
      }


      // these are pure virtual but we don't need them...  so just make them empty
    // otherwise we get "cannot declare of type Mgr due to missing abstract
    // functions" and so on
    void shadowTexturesUpdated(size_t) {}
    void shadowTextureReceiverPreViewProj(Ogre::Light*, Ogre::Frustum*) {}
    void preFindVisibleObjects(Ogre::SceneManager*, Ogre::SceneManager::IlluminationRenderStage, Ogre::Viewport*) {}
    void postFindVisibleObjects(Ogre::SceneManager*, Ogre::SceneManager::IlluminationRenderStage, Ogre::Viewport*) {}
      void shadowTextureCasterPreViewProj(Ogre::Light *light, Ogre::Camera *cam, size_t) {}

   } LightOrderUpdater;



I initially had a version that re-added the lights, but the performance hit was terrible, dropping one scene from 24fps down to 15fps. However I noticed something interesting. Just by having sortLightsAffectingFrustum do nothing except return true, it seems light sorting is skipped and my lights stay in the original order they were when I set them up. I still lose a couple of fps (why not sorting should be slower than sorting, I don't know) but it seems acceptable.
mkultra333
Veteran
 
Posts: 673
Joined: Sun Mar 08, 2009 5:25 am


Return to Help

Who is online

Users browsing this forum: Google Adsense [Bot], LordJimBeam and 8 guests