[SOLVED]Mind-boggling problem with lights!

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
xirtamatrix
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

[SOLVED]Mind-boggling problem with lights!

Post by xirtamatrix »

Hi Folks,

Ok, here's a tough one thats been boggling my mind for the past 48 hours.

I have two applications. I load the same level with the same lights and they display the lights differently. The code that is loading the level and the lights is exactly the same. Lets look closely. Observe the image below:

Image

We have 2 images, one on left and one on right.
We have 3 lights:

1. The main POINT light in the middle with is yellow.
2. A SPOT light on the right which is white.
3. A second POINT light on the left, showing the bounding box, which is red.

The first two lights have a radius of 100.
Light 3, showing the bounding-box, has a radius of only 2. Which means it should not be touching anything and therefore no red light should be visible. The application on the left show this correct behaviour.

But the application on the right, which has the SAME code, clearly shows the red light. It is as if the light is extending far beyond its radius.

Mind you, all the lights have exactly the same radius and same attenuation in both apps, and no, the radius is NOT changed after the attenuation is set.

Why is this happening?
I have tested this a zillion times over and there is ABSOLUTELY no difference between the lights. I collect all light-data directly from the lightSceneNode and display on screen, and all the data, position, rotation, radius, attenuation in boths apps is exactly the same.

Not only that, if you observe really carefully, the whole lighting is quite different.

What I'm looking for is ANY wild guesses as to why this could be happening? It just doesn't make any sense! :(

The only logical conclusion I have come to, is that there must be some other totally unrelated parameter, perhaps of the video-driver or some device setting, which is causing this.

If anyone wants me to post the code, please let me know.

Any help would be really really aprpeciated!

Many thanks,

/regards
Last edited by xirtamatrix on Sun Apr 24, 2011 11:43 am, edited 2 times in total.
to live, is natural; to die, is not!
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

Imho the right one has per-vertex lighting while the left one has per-pixel
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
xirtamatrix
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Post by xirtamatrix »

ent1ty wrote:Imho the right one has per-vertex lighting while the left one has per-pixel
Thank you ent1ty, but could you elaborate a bit what you mean?
All 3 lights are dynamic lights obviously and so far as I know this means in both cases it has to be per-vertex lighting. Lights are created with exactly the same code. All the geometry is also loaded in both applications with excatly the same code.

Just to be complete, here's the code which creates the lights. The same code is used in both apps.

Code: Select all

	// light position marker 
	scene::IMeshSceneNode *lightMarker = smgr->addSphereSceneNode(0.2f, 16, 0);
	lightMarker->setPosition(stringcToVector3df(mPosition));
	lightMarker->setMaterialFlag(video::EMF_WIREFRAME, true); 
	lightMarker->setMaterialFlag(video::EMF_LIGHTING, false);

	scene::ILightSceneNode *pointLight = smgr->addLightSceneNode(lightMarker, core::vector3df(0,0,0), SColorf(stringcToSColor(mDiffuse)), mRadius);
	pointLight->setID(numBaseNodes);
	pointLight->setLightType(ELT_POINT);
	pointLight->setDebugDataVisible(EDS_BBOX);
	pointLight->setRadius(mRadius);
	pointLight->setName(mName);
	pointLight->getLightData().AmbientColor = SColorf(stringcToSColor(mAmbient));
	pointLight->getLightData().DiffuseColor = SColorf(stringcToSColor(mDiffuse));
	pointLight->getLightData().SpecularColor = SColorf(stringcToSColor(mSpecular));
	pointLight->getLightData().Attenuation = stringcToVector3df(mAttenuation);							
					
	pointLight->getLightData().CastShadows = mShadow;
	pointLight->setVisible(mVisible);
	
	//print out light data
	printf("\n\n LightType: %d  LightID: %d, LightVISIBLE: %d \n", pointLight->getLightType(), pointLight->getID(), pointLight->isVisible());
	printf("LightRADIUS: %2.2f, LightPOSITION: (%2.2f,%2.2f,%2.2f) \n", pointLight->getRadius(), lightMarker->getPosition().X, lightMarker->getPosition().Y, lightMarker->getPosition().Z);
	printf("LightATTENUATION: (%2.2f,%2.2f,%2.2f) \n\n", pointLight->getLightData().Attenuation.X, pointLight->getLightData().Attenuation.Y, pointLight->getLightData().Attenuation.Z);							
Clearly, an obvious mistake could'v been that the variables dont contain the right values, but thats why I'm writing out light data in the end and all these values are set correctly.
to live, is natural; to die, is not!
xirtamatrix
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Post by xirtamatrix »

After a good nights sleep and looking at it again, two things stand crystal clear:

One, that there MUST be something different between the two apps (doh!), because computers are not sentient beings and dont do things on their own accord.

Two, whatever difference there is, its not in the lights, because we know for sure that lights are created in exactly the same way and have exactly same parameters.

So, the question now becomes, what else, other than the lights, could have an effect on how lights appear?

Can someone plese help me figure that out?
Any ideas/wild-guesses are welcome.

/cheers!
to live, is natural; to die, is not!
Gorbstein
Posts: 37
Joined: Wed Nov 25, 2009 8:44 pm
Location: Scotland

Re: Mind-boggling problem with lights!

Post by Gorbstein »

xirtamatrix wrote: I have two applications. I load the same level with the same lights and they display the lights differently.
In what situation do you get the unwanted effect? Is it a different machine or something else?

D
Image
xirtamatrix
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Re: Mind-boggling problem with lights!

Post by xirtamatrix »

Gorbstein wrote:
xirtamatrix wrote: I have two applications. I load the same level with the same lights and they display the lights differently.
In what situation do you get the unwanted effect? Is it a different machine or something else?

D
I wish, then it would make SOME sense, but alas, no, exactly the same machine. So we can rule-out any hardware/driver related discrepencies.
to live, is natural; to die, is not!
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

I guess you're using some shaders in one of the apps...?
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
xirtamatrix
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Post by xirtamatrix »

ent1ty wrote:I guess you're using some shaders in one of the apps...?
Nopes, no shaders either.
to live, is natural; to die, is not!
xirtamatrix
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Post by xirtamatrix »

Oh My God!! I solved it!
Can someone please shoot me in the head? Serious!

It was right there in front of my eyes, and I went over it 20 zillion times but I didn't see it!

One of the apps was using Direct3d9, the other was using OpenGL.

Aaaahhhhrrrggg! (Digging a hole to burry myself in the ground)

So much for the 'mind-boggling' problem :S
We did learn something interesting though, that depending on which API you're using, your lights would look significantly different. Humm...

So, the app on the right, where the red light seems to be leaking beyond the light's radius, was using OpenGL. I changed it to Direct3D9 and now its ok.

So, those of the higher order please take notice, is it Irrlicht's problem or OpenGL's problem?

/cheers!
to live, is natural; to die, is not!
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

Well, OGL and D3D have different lighting formulas, so i guess it's expected behavior.
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, depends on what you want to achieve, but one of the two light models is just limited. Either it's OpenGL's because of the missing strict radius, or it's D3D's because of its unnatural strict radius. Anyway, without using shaders it's probably not possible to get these things exactly equal. You can alter the light attenuation to get close, though.
Post Reply