Lights problem

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
dankot
Posts: 9
Joined: Wed Sep 16, 2009 11:43 am

Lights problem

Post by dankot »

Dear reader,
I exported a google sketchup simple cube object and saved it as an obj file (plus mtl file)
I'm trying to draw this cube in a world which contains lights but the cube is drawn black and the lights don't effect it.
( Image )

from what I know, it is enough (in openGL and in OGRE for insatnce) to set the ambient light and then all of the objects are lit in a certain manner,
and offcourse if put another light it also effect the picture.

I noticed the in the mtl file each time the ambient (Ka) is 0,0,0 it apears black.

What should I do?
Is it good that in the .mtl the "Ka" is 0,0,0?
Should I change it manually to a different value?

Attached is the code,

thanks, Dan
code:


Code: Select all


#include <iostream>
#include <irrlicht.h>
using namespace std;
using namespace irr;
using namespace irr::core;
using namespace irr::scene;
using namespace irr::video;
using namespace irr::io;
using namespace irr::gui;

int main(int argc, char** argv)
{
	if ( argc != 2 )
	{
		cout << "Usage: " << argv[0] << "<file>" << endl;
		return -1;
	}
	IrrlichtDevice *device = createDevice( 
		//video::EDT_OPENGL, 
		//video::EDT_SOFTWARE, 
		//video::EDT_BURNINGSVIDEO,
		video::EDT_DIRECT3D9, 
		dimension2d<s32>(1000, 800), 16, false, false, false, 0);

	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();

	/*
	device->getFileSystem()->addZipFileArchive("awesome home.zip");
	scene::IAnimatedMesh* mesh = smgr->getMesh("awesome home.dae");
	//scene::IAnimatedMesh* mesh = smgr->getMesh("doc.kml");
	//*/
	scene::IAnimatedMesh* mesh = smgr->getMesh(argv[1]);
	//scene::IAnimatedMesh* mesh = smgr->getMesh("dan/stclairhighschool.obj");
	//scene::IAnimatedMesh* mesh = smgr->getMesh("stclairhighschool.obj");
	//scene::IAnimatedMesh* mesh = smgr->getMesh("stclairhighschool.dae");
	//scene::IAnimatedMesh* mesh = smgr->getMesh("stclairhighschool/stclairhighschool.3ds");
	
	scene::ISceneNode* node = 0;

	if (!mesh)
	{
		return -1;
	}

	node = smgr->addOctTreeSceneNode(mesh->getMesh(0));
	//node = smgr->addMeshSceneNode(mesh->getMesh(0));

	smgr->setAmbientLight(video::SColorf(1.0f,1.0f,1.0f,1.0f));
	/*
	ILightSceneNode* light1 = smgr->addLightSceneNode( 0, core::vector3df(0,-10,0));//, video::SColorf(0.7f,0.5f,0.3f), 1.0f, 1 );
	SLight l = light1->getLightData( );
	//vector3df dir(-0.0f, -10.0f, -0.0f);
	//dir.normalize();
	//l.Direction = dir;
	//light1->setLightData( l );
	//light1->setRotation( dir );
	light1->setLightType(irr::video::ELT_DIRECTIONAL);
	E_LIGHT_TYPE type = light1->getLightType();
	l = light1->getLightData();
	//*/

	if (!node)
	{
		return -1;
	}

	for ( size_t i = 0 ; i != node->getMaterialCount() ; ++i )
	{
		//node->getMaterial(i).Lighting = true;
		//node->getMaterial(i).SpecularColor.set(255,255,255,255);
		//node->getMaterial(i).AmbientColor.set(255,255,255,255); 
		//node->getMaterial(i).DiffuseColor.set(255,255,255,255); 
		//node->getMaterial(i).EmissiveColor.set(255,100,100,100);
		//node->getMaterial(i).Shininess = 20.0f;
		//node->getMaterial(i).NormalizeNormals = true;
		//*/
	}

	node->setMaterialFlag(EMF_LIGHTING, true);
	node->setMaterialFlag(video::EMF_BACK_FACE_CULLING, true); 
	//node->setMaterialFlag(video::EMF_FRONT_FACE_CULLING, true); 
	node->setPosition(core::vector3df(0, 0, 1000));
	//node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);

	//smgr->setShadowColor(video::SColor(150,0,255,0));

	smgr->addCameraSceneNodeFPS()->setFarValue(3000.0f);
	device->getCursorControl()->setVisible(false);
	int lastFPS = -1;

	while(device->run())
	{
		if (device->isWindowActive())
		{
			driver->beginScene(true, true, video::SColor(255,20,20,60));
			smgr->drawAll();
			driver->endScene();

			int fps = driver->getFPS();

			if (lastFPS != fps)
			{
				core::stringw str = L"Irrlicht Engine - Quake 3 Map example [";
				str += driver->getName();
				str += "] FPS:";
				str += fps;

				device->setWindowCaption(str.c_str());
				lastFPS = fps;
			}
		}
		else
			device->yield();
	}

	device->drop();

	return 0;
}
[/code]
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

The ambient color of the material defines how much of the ambient light of the scene manager is reflected. Not how much is emitted.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
dankot
Posts: 9
Joined: Wed Sep 16, 2009 11:43 am

Post by dankot »

Thanks for the answer,
It means the ambient color of the object should be the same color of the diffuse?
For realistic view?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, the values are often heavily related. However, with ambient (0,0,0) there's no effect of ambient light with your object. Moreover, you don't set ambient light in your scene, so it's also black - meaning no effect. Also make sure that when using direction light you look from a side of the object where light can be seen - directional light can be rather sharp and focused on a single side of an object.
DarkRage4
Posts: 31
Joined: Wed Jul 29, 2009 11:07 pm
Location: Ontario, Canada
Contact:

Post by DarkRage4 »

Code: Select all

node->setMaterialFlag(EMF_LIGHTING, false);
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

DarkRage4 wrote:

Code: Select all

node->setMaterialFlag(EMF_LIGHTING, false);
Wrong :wink:
He want to apply lightining to the object, not to disable it.
Working on game: Marrbles (Currently stopped).
Bear_130278
Posts: 237
Joined: Mon Jan 16, 2006 1:18 pm
Location: Odessa,Russian Federation

Post by Bear_130278 »

dankot, nice screenshot..
Have you ever planed to sell some of your art?
Do you like VODKA???
Image
Image
DarkRage4
Posts: 31
Joined: Wed Jul 29, 2009 11:07 pm
Location: Ontario, Canada
Contact:

Post by DarkRage4 »

serengeor wrote:
DarkRage4 wrote:

Code: Select all

node->setMaterialFlag(EMF_LIGHTING, false);
Wrong :wink:
He want to apply lightining to the object, not to disable it.
:wink: EMF LIGHTING is not normally lighting, its what is making the box black, I had this problem b4 and when I set it to false the texture/color of the object was back
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, EMF_LIGHTING tells Irrlicht that it should calculate the color based on the actual dynamical lighting setup. If you don't add a light to the scene it's pitch black. Just as if you're running out in the night with no light. Go and test it :P
If you don't want to dynamically light the scene (you could also use ambient lighting...) you should set EMF_LIGHTING to false, as it's simply quite black otherwise. But the tutorials also explain this thing in some detail, maybe go through those (again?).
Post Reply