Boundingbox of ILightSceneNode worries

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Boundingbox of ILightSceneNode worries

Post by randomMesh »

I wanted to debug my ILightSceneNode, so i set DebugDataVisible to scene::EDS_BBOX.
The radius of the light is 10.0f.

Code: Select all

irr::scene::ILightSceneNode* light = smgr->addLightSceneNode(
	0, irr::core::vector3df(5, 5, -5), irr::video::SColorf(1.0f, 1.0f, 1.0f), 10.0f);
light->setDebugDataVisible(irr::scene::EDS_BBOX);
In my understanding, the bounding box should be 20.f in width and height, according to the radius of 10.0f.

But in CLightSceneNode::doLightRecalc(), the box is computed like this

Code: Select all

const f32 r = LightData.Radius * LightData.Radius * 0.5f;
BBox.MaxEdge.set( r, r, r );
BBox.MinEdge.set( -r, -r, -r );
Means that r = 10*10*0.5 = 50.0f which results in a box that is 100 units wide.

What am i missing?
"Whoops..."
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I've noticed this before, but been to lazy to mention it. To get a minimum bounding box for a sphere with a radius r, it should be

Code: Select all

BBox.MaxEdge.set( r, r, r ); 
BBox.MinEdge.set( -r, -r, -r );
So at least part of the code is right... The whole (r*r)/2.f thing is garbage. It should be LightData.Radius.

Travis
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

Good that it's a bug. I almost went mad. ;)

Here's a patch against latest trunk:

Code: Select all

Index: source/Irrlicht/CLightSceneNode.cpp
===================================================================
--- source/Irrlicht/CLightSceneNode.cpp	(Revision 3273)
+++ source/Irrlicht/CLightSceneNode.cpp	(Arbeitskopie)
@@ -185,9 +185,8 @@
 	}
 	if ((LightData.Type == video::ELT_SPOT) || (LightData.Type == video::ELT_POINT))
 	{
-		const f32 r = LightData.Radius * LightData.Radius * 0.5f;
-		BBox.MaxEdge.set( r, r, r );
-		BBox.MinEdge.set( -r, -r, -r );
+		BBox.MaxEdge.set( LightData.Radius, LightData.Radius, LightData.Radius );
+		BBox.MinEdge.set( -LightData.Radius, -LightData.Radius, -LightData.Radius );
 		setAutomaticCulling( scene::EAC_BOX );
 		LightData.Position = getAbsolutePosition();
 	}

"Whoops..."
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Does the bounding box look correct? i.e., if you have a light with radius R, and a surface (with lighting enabled and a valid normal), does the light show up on the surface only when the surface intersects the bounding box?
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

vitek wrote:Does the bounding box look correct?
Yes.
vitek wrote:does the light show up on the surface only when the surface intersects the bounding box?
No.

Here's a screenshot. The light has a radius of 10.0f, the bounding box is correct.
But the floor tile outside the boundingbox (at the bottom of the image) is also lit.
Image

This one is from a different view and has some debug drawing enabled.
Image

This one is interesting:
I merged 2 floors and now it's not lit at all. Even though the wall at the left has some lighting.
Image


The floor is made with the geometry creator and are 'cube' meshes. I am using the OpenGL driver, latest trunk.

Seems like lighting is completely broken.
"Whoops..."
Post Reply