Lights from .irr scenes not working

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
scgtrp
Posts: 16
Joined: Sun Jun 15, 2008 1:25 am

Lights from .irr scenes not working

Post by scgtrp »

I have an .irr scene exported from Blender (http://pastebin.ca/1466626) with a light and an empty room. The light is indeed in the XML, but when I load it (either via my code or the LoadIrrFile example) and enable lighting on the mesh, it acts as if the light isn't there at all. If I create a light it works fine, so I know lighting works, but why isn't the light defined in the scene file working?

My .irr loading code:

Code: Select all

	void load_world(const char* map_path)
	{
		scene_manager->loadScene(map_path);
		
		IMetaTriangleSelector* meta = scene_manager->createMetaTriangleSelector();
		array<ISceneNode*> nodes;
		scene_manager->getSceneNodesFromType(ESNT_ANY, nodes);

		for (u32 i = 0; i < nodes.size(); i++)
		{
			scene::ISceneNode* node = nodes[i];
			scene::ITriangleSelector* selector = NULL;
			
			u32 t = node->getType();
			if (node->getType() != ESNT_SKY_BOX)
				node->setMaterialFlag(EMF_LIGHTING, true);

			switch (node->getType())
			{
			case scene::ESNT_CUBE:
			case scene::ESNT_ANIMATED_MESH:
				// Because the selector won't animate with the mesh,
				// and is only being used for camera collision, we'll just use an approximate
				// bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)->getMesh(0)
				selector = scene_manager->createTriangleSelectorFromBoundingBox(node);
				break;

			case scene::ESNT_MESH:
			case scene::ESNT_SPHERE: // Derived from IMeshSceneNode
				selector = scene_manager->createTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
				break;

			case scene::ESNT_TERRAIN:
				selector = scene_manager->createTerrainTriangleSelector((scene::ITerrainSceneNode*)node);
				break;

			case scene::ESNT_OCT_TREE:
				selector = scene_manager->createOctTreeTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
				break;

			default:
				// Assume it's a light or the skybox. In any case it doesn't need to collide.
				break;
			}

			if (selector)
			{
				meta->addTriangleSelector(selector);
				selector->drop();
			}
		}
		
		scene::ISceneNodeAnimator* anim = scene_manager->createCollisionResponseAnimator(meta, camera,
			vector3df(5, 5, 5), vector3df(0, -9.81, 0));
        meta->drop();

        camera->addAnimator(anim);
        anim->drop();
	}
pc0de
Posts: 300
Joined: Wed Dec 05, 2007 4:41 pm

Post by pc0de »

hey scgtrp - can you post a link to your .blend file and the generated "maps/Cube.001.irrmesh" file?
scgtrp
Posts: 16
Joined: Sun Jun 15, 2008 1:25 am

Post by scgtrp »

pc0de
Posts: 300
Joined: Wed Dec 05, 2007 4:41 pm

Post by pc0de »

It looks like Irrlicht's vertex lighting doesn't like scaling (for point lights). If you apply the scale to your mesh in Blender (CTRL-A) before exporting, it should work as expected.

Also, if you add a material to your mesh, you won't need to manipulate the lighting flag in your code. For more info - have a look at the "Material ID Properties" section in the irrb user guide.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Lighting on scaled meshes will only work if you enable normalize_normals in the material. I'm also not sure if all the light properties are correctly handled, because the defaults have changed between 1.4 and 1.5
scgtrp
Posts: 16
Joined: Sun Jun 15, 2008 1:25 am

Post by scgtrp »

It looks like Irrlicht's vertex lighting doesn't like scaling (for point lights). If you apply the scale to your mesh in Blender (CTRL-A) before exporting, it should work as expected.

Also, if you add a material to your mesh, you won't need to manipulate the lighting flag in your code. For more info - have a look at the "Material ID Properties" section in the irrb user guide.
Interesting. Didn't know about the ctrl-A thing. It does indeed work as expected now. [edit: removed stupid stuff about me not knowing the difference between a material and a texture]
Lighting on scaled meshes will only work if you enable normalize_normals in the material. I'm also not sure if all the light properties are correctly handled, because the defaults have changed between 1.4 and 1.5
Stupid question: where's normalize_normals?
Hirte
Posts: 73
Joined: Sat Apr 01, 2006 1:32 pm

Post by Hirte »

node->setMaterialFlag(NORMALIZE_NORMALS, true);
scgtrp
Posts: 16
Joined: Sun Jun 15, 2008 1:25 am

Post by scgtrp »

Thanks. By the way, any idea how to stop the GUI from recieving events when the game isn't paused? (Returning true from my event reciever won't work, I need them to go to the FPS camera.)
scgtrp
Posts: 16
Joined: Sun Jun 15, 2008 1:25 am

Post by scgtrp »

Okay, I've done all that, but now the intensity of the light appears to depend on the intensity of the ambient light. If it's pitch dark (no ambient light) the light doesn't show up at all, and if I set the ambient light to (0.2, 0.2, 0.2) the light is there, but much dimmer than it looks in Blender. Any idea what's going on here?
pc0de
Posts: 300
Joined: Wed Dec 05, 2007 4:41 pm

Post by pc0de »

This looks like a bug in irrb... Here's how irrb currently exports lights:
-------
LightType. Based on Blenders lamp type:
• lamp -> Point
• area -> Directional
• spot -> Spot
• sun -> Directional
• hemi -> Directional

AmbientColor. Constant (0,0,0).

DiffuseColor. Set to the R,G,B components of the light color.

SpecularColor. Constant (1,1,1).

Attenuation. Set to (0.5 / (Blenders Energy Value)).

Radius. Set to (2.0 * (Blenders Distance Value)).

CastShadows. Constant "True".
------
The next irrb update will allow you to control the "Constant" values with Blender ID properties.
Post Reply