## Fixed light order.

Problems building or running the engine, queries about how to use features etc.
mkultra333
Posts: 1889
Joined: Sun Mar 08, 2009 5:25 am
x 104

### Fixed light order.

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?
"In theory there is no difference between practice and theory. In practice, there is." - Psychology Textbook.

nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: Princeton, New Jersey, USA
x 13
Contact:

### Re: Fixed light order.

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?

mkultra333
Posts: 1889
Joined: Sun Mar 08, 2009 5:25 am
x 104

### Re: Fixed light order.

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) 	``
"In theory there is no difference between practice and theory. In practice, there is." - Psychology Textbook.

mkultra333
Posts: 1889
Joined: Sun Mar 08, 2009 5:25 am
x 104

### Re: Fixed light order.

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 )
"In theory there is no difference between practice and theory. In practice, there is." - Psychology Textbook.

nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 9

### Re: Fixed light order.

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);

mkultra333
Posts: 1889
Joined: Sun Mar 08, 2009 5:25 am
x 104

### Re: Fixed light order.

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