Lighting

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
ozrinaut
Posts: 28
Joined: Tue Sep 13, 2005 5:09 pm

Lighting

Post by ozrinaut »

Hello,

I am trying to light any of my own objects, but their lighting seems binary (either completely black, or completly illuminated if using the video::EMF_LIGHTING flag). I have made a simple object as follows:

Code: Select all

	
    //simple object
    scene::ISceneNode *simpObj = smgr->addCubeSceneNode(1);
    simpObj->setScale(core::vector3df(50,50,50));
    simpObj->setPosition(core::vector3df(0,25,0));
    simpObj->setMaterialFlag(video::EMF_LIGHTING, false);
    video::ITexture *simpTex = driver->getTexture("image.png");
    simpObj->setMaterialTexture( 0, simpTex );
This works fine, but the object doesn't light up when I add a light from the 'PerPixelLighting example' included with irrlicht. However. if I add the 'room.3ds', this inherits the light fine as the light flies around the room.

Is there another flag I need to apply to my simple object so that it too has light based on the flying light form the example?
Last edited by ozrinaut on Wed Jan 17, 2007 7:51 pm, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You probably have to subdivide your mesh to get more detailed gradients. At least under OpenGL large faces can make the shading impression quite ugly. The cube scene node does not support more detailed meshes, though.
ozrinaut
Posts: 28
Joined: Tue Sep 13, 2005 5:09 pm

Post by ozrinaut »

hybrid wrote:You probably have to subdivide your mesh to get more detailed gradients. At least under OpenGL large faces can make the shading impression quite ugly. The cube scene node does not support more detailed meshes, though.
But I have now loaded in the .x dwarf included in the examples. He light's up properly there, but when I load him into my scene he does not. Ideas?
ozrinaut
Posts: 28
Joined: Tue Sep 13, 2005 5:09 pm

Post by ozrinaut »

FIXED (sorta)
I commented out the two material flags below, on the dwarf, and now he lights up correctly as the lights fly around the room. However, if I uncomment the simple 'addCubeSceneNode(1)' it still appears black.

Code: Select all

	//dwarf man
	scene::IAnimatedMeshSceneNode* anms = smgr->addAnimatedMeshSceneNode(smgr->getMesh(	"../../media/dwarf.x"));
	scene::ISceneNodeAnimator* anim =	smgr->createFlyStraightAnimator(core::vector3df(0,50,0),core::vector3df(0,50,0), 2500, true);
	anms->addAnimator(anim);
	anim->drop();
	//anms->setMaterialFlag(video::EMF_LIGHTING, false);
	//anms->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
		//anms->setMD2Animation(scene::EMAT_RUN);
	anms->setFrameLoop(320, 367);
	anms->setAnimationSpeed(30);
	anms->setRotation(core::vector3df(0,180.0f,0));
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Of course you have to set LIGHTING to true (which is is by default). The NORMALIZE_NORMALS is only necessary if you scale the scene node. If you don't scale, this setting would only slow down your scene. But if you don't set it when scaling you might get weird lighting depending on your gfx card capabilities. But I don't know about the other problem.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Are you saying that the cube appears black when lighting is enabled and white when it is disabled?

There could be a problem locating the texture file or loading it. You can check the first thing easily by verifying that the pointer returned by getTexture() is a non-null pointer. If it is null, then the texture was not found or could not be loaded.

The other thing might be that the light is inside the cube. You're making a cube that is 50x50x50. Like putting a flashlight in a shoebox, if the light is inside the cube, the outside will not be lit.

As mentioned by hybrid, if you disable lighting on a node it won't appear properly. Usually they end up being solid white. Typically you want to leave lighting enabled and you set an ambient light so that it isn't pitch black in areas that aren't near the light sources.

Travis
ozrinaut
Posts: 28
Joined: Tue Sep 13, 2005 5:09 pm

Post by ozrinaut »

I am now able to light objects, however...I have exported the default cube from blender as a .3ds file and loaded fine in my scene. It appears to be lighting fine..

I have a few new issues:
1.] For some reason my cube is not inheriting textures.
2.] When I navigate the camera inside the cube, it clips and turns invisible [unlike the example room.3ds provided with irrlicht]

I appreciate your help!
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I don't know what you mean with the first issue.

The second issue is caused by backface culling. The cube has faces with normals that point out from the center of the cube. The side of the face that the normal comes out of is called the front face. The other side, on the inside of your cube, is called the back face. If you want the faces to always render the inside and outside, set the EMF_BACK_FACE_CULLING flag to false for your scene node.

The room.3ds mesh is essentially the inside of a cave. Each of the faces has the normal pointing into the center of the cave. If you move the camera out of the cave, you will see that the outside is not rendered.

Travis
nullterm
Posts: 14
Joined: Tue Feb 27, 2007 12:36 pm

Post by nullterm »

I'm running into the same binary lighting issue, see here:

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=19544
Post Reply