Unsuccessful attempt to use ambient lighting in OpenGL

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
Spinland
Posts: 32
Joined: Fri May 14, 2010 1:06 pm
Location: Upstate NY, USA

Unsuccessful attempt to use ambient lighting in OpenGL

Post by Spinland »

I have a simple .obj mesh whose material color is defined as yellow on the .mtl file. I've brought it into Irrlicht using the OpenGL option. I've then added ambient lighting as follows:

Code: Select all

smgr->setAmbientLight(video::SColorf(1.0f,1.0f,1.0f));
My understanding was the object would be lit by white ambient light, showing it as the yellow I defined for the material, but it renders as black. Is there some other setting or definition I need to use so all objects in the scene are uniformly lit?

Many thanks in advance!
loki1985
Posts: 214
Joined: Thu Mar 31, 2005 2:36 pm

Post by loki1985 »

try activating lighting on the scene node first.
example:

Code: Select all

node->setMaterialFlag(EMF_LIGHTING, true);
Spinland
Posts: 32
Joined: Fri May 14, 2010 1:06 pm
Location: Upstate NY, USA

Post by Spinland »

Hmm. Thanks, but that didn't seem to make any difference. Puzzling.

I can get the color to show if I throw an explicit light into the scene with addLightSceneNode(), but it's shadowed and has to be placed and the size set. I'm just trying to get a universal, even lighting across all the surfaces of the model regardless of how large it is or where it's placed. Normally an ugly lighting situation, I know, but it's to test something out.
Spinland
Posts: 32
Joined: Fri May 14, 2010 1:06 pm
Location: Upstate NY, USA

Post by Spinland »

Okay, I officially feel silly now. The answer was in the "Movement" tutorial code. Without dynamic lighting you actually have to do the opposite of what I tried above:

Code: Select all

node1->setMaterialFlag(EMF_LIGHTING, false);
Otherwise the mesh on node1 is rendered in black.

Hopefully this will help someone. 8)
DeM0nFiRe
Posts: 117
Joined: Thu Oct 16, 2008 11:59 pm

Post by DeM0nFiRe »

Well, setting EMF_LIGHTING to false will make it so it will render in the full color of the original mesh and texture, but that is not the same as being lit by a full ambient light. I mean, if all you care about is seeing the mesh in full color, then that will work, but if you actually meant to use an ambient light (like so later you could use a different light color, perhaps) then that's not the way to fix it.
ArakisTheKitsune
Posts: 73
Joined: Sat Jun 27, 2009 6:52 am

Post by ArakisTheKitsune »

DeM0nFiRe wrote:Well, setting EMF_LIGHTING to false will make it so it will render in the full color of the original mesh and texture, but that is not the same as being lit by a full ambient light. I mean, if all you care about is seeing the mesh in full color, then that will work, but if you actually meant to use an ambient light (like so later you could use a different light color, perhaps) then that's not the way to fix it.
On that note I want to add that instead using

Code: Select all

node->setMaterialFlag(EMF_LIGHTING, false);
I am using

Code: Select all

node->getMaterial(i).EmissiveColor.set(0, 255, 255, 255);
Because in first case textures are more darker but in second case texture color is good.
Knowledge is power, understanding is wisdom.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Spinland wrote:Okay, I officially feel silly now. The answer was in the "Movement" tutorial code. Without dynamic lighting you actually have to do the opposite of what I tried above:

Code: Select all

node1->setMaterialFlag(EMF_LIGHTING, false);
Otherwise the mesh on node1 is rendered in black.

Hopefully this will help someone. 8)
This is wrong, with lighting enabled you shouldn't get a black scene node if you set the ambient color correctly. There may be some slight differences atm with the OpenGL and D3D implementations and the way they handle this. Although you could just use EmissiveColor if ambient is giving you troubles...
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Post Reply