Ambient light not working but other lights do

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
tuket
Posts: 11
Joined: Thu Jan 23, 2014 2:05 am

Ambient light not working but other lights do

Post by tuket »

Hello, I have made a very simple demo but I can't get ambient light working. However, point light is working.
In my application I put the point light at the right of a model I have loaded. So if I see the model from the right it is lightened and if I see it from the left I see it completely dark.

This is the code.

Code: Select all

 
#include <iostream>
#include <irrlicht/irrlicht.h>
 
using namespace std;
using namespace irr;
 
int main()
{
    
    IrrlichtDevice* device =
    createDevice
    (
        video::EDT_OPENGL,
        core::dimension2d<u32>(800, 600),
        16,
        false,  // fullscreen
        false,  // stencyl buffer
        false,  // vsync
        0       // IEventReceiver*
    );
    
    scene::ISceneManager* smgr = device->getSceneManager();
    video::IVideoDriver* driver = device->getVideoDriver();
    
    smgr->setAmbientLight( video::SColorf(0.1, 0.1, 0.1, 1) );
        
    // add camera
    scene::ICameraSceneNode* camera =
    smgr->addCameraSceneNodeFPS
    (
        0,  // parent
        15, // speed rotate
        0.004   // speed move
    );
    camera->setPosition(core::vector3df(-5, 3, 0));
    camera->setRotation(core::vector3df(-90, 0, 0));
    
    
    scene::IAnimatedMesh* mainCharMesh =
    smgr->getMesh("models/dcu_jimmy_olsen/Jimmy.ms3d");
    
    scene::IAnimatedMeshSceneNode* mainChar =
    smgr->addAnimatedMeshSceneNode( mainCharMesh );
    
    if( mainChar )
    {
        
        mainChar->setMaterialTexture
        (
            0,
            driver->getTexture( "models/dcu_jimmy_olsen/CHRNPCICOASC102_DIFFUSE.tga" )
        );
        
        
        video::ITexture* bumpTexture = driver->getTexture( "models/dcu_jimmy_olsen/CHRNPCICOASC102_NORMAL.tga" );
        driver->makeNormalMapTexture( bumpTexture, 1.5f );
        
        mainChar->setMaterialTexture
        (
            1,
            bumpTexture
        );
        mainChar->setMaterialType(video::EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA);
        mainChar->setMaterialFlag( video::EMF_LIGHTING, true );
        
        // mainChar->getMaterial(0).EmissiveColor.set(255, 255, 255, 255);
        mainChar->getMaterial(0).AmbientColor.set(255, 255, 255, 255);
        
    }
    
    scene::ILightSceneNode* light1 = 
    smgr->addLightSceneNode
    (
        0,
        core::vector3df(0, 0, -10),
        video::SColorf(1, 0.5, 0.5, 0),
        800
    );
    
    light1->setDebugDataVisible( scene::EDS_BBOX );
    
    while( device->run() )
    {
        
        driver->beginScene
        (
            true,
            true,
            video::SColor(255, 222, 255, 255)
        );
        
        smgr->drawAll();
                
        driver->endScene();
        
    }
    
}
 
 
left:
Image

right:
Image

front:
Image

The files:
http://www.mediafire.com/download/dxi3o ... v3i/be.zip

Thanks for making Irrlicht possible.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Ambient light not working but other lights do

Post by mongoose7 »

You have to set the ambient colour in the light as well.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Ambient light not working but other lights do

Post by CuteAlien »

No, he doesn't have to set it in the light. Ambient is light independent. But it could be that the materials are set in a way that they ignore the ambient factor. Sorry, no time for testing right now.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
tuket
Posts: 11
Joined: Thu Jan 23, 2014 2:05 am

Re: Ambient light not working but other lights do

Post by tuket »

Thanks for your responses.
mongoose7 wrote:You have to set the ambient colour in the light as well.
Thanks for your suggestion. I didn't know how to do that but the doxygen documentation helped me.

Code: Select all

 
light1->getLightData().AmbientColor = video::SColorf(0.3, 0.3, 0.3, 1.0);
 
That's what I've tried. But I get the same result.

Could it be an issue with the format? I am using .ms3d.

UPDATE: I have tried .b3d and doesn't work either.
tuket
Posts: 11
Joined: Thu Jan 23, 2014 2:05 am

Re: Ambient light not working but other lights do

Post by tuket »

I have tried other types of materials.
Using EMT_SOLID I get lighting but only from the light1. The global light doesn't work.

Code: Select all

 
smgr->setAmbientLight( video::SColorf(0.5, 0.5, 0.5, 1) );  // this line does nothing
...
mainCharacter.node->setMaterialType(video::EMT_SOLID);
...
light1->getLightData().AmbientColor = video::SColorf(0.1, 0.1, 0.1, 1.0);  // this works
 
Is this a bug or am I doing something wrong?

And if I use EMT_NORMAL_MAP_SOLID ambient light doen't work in the global ambient light neither in the light1.

Code: Select all

 
smgr->setAmbientLight( video::SColorf(0.5, 0.5, 0.5, 1) );  // this line does nothing
...
mainCharacter.node->setMaterialType(video::EMT_NORMAL_MAP_SOLID);
...
light1->getLightData().AmbientColor = video::SColorf(0.1, 0.1, 0.1, 1.0);  // this doesn't work either
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Ambient light not working but other lights do

Post by CuteAlien »

I didn't mean the material type. But the material itself has an AmbientColor component (http://irrlicht.sourceforge.net/docu/cl ... 18d30e6b4b). And if that is set to 0 then the material will ignore ambient color.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
tuket
Posts: 11
Joined: Thu Jan 23, 2014 2:05 am

Re: Ambient light not working but other lights do

Post by tuket »

Thanks CuteAlien.

I tried to do this.

Code: Select all

 
for
(
    int i=0;
    i < mainCharacter.node->getMaterialCount();
    i++
)
{
    mainCharacter.node->getMaterial(i).AmbientColor = video::SColor(255, 255, 255, 255);
}
 
But it doesn't work.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Ambient light not working but other lights do

Post by CuteAlien »

OK, I try to find some time to look at your example if I can reproduce it.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Ambient light not working but other lights do

Post by CuteAlien »

The normal map renderer does not seem to regard ambient light. I never learned the assembler used by graphic-cards, but from the comments it seems that shader only regards 2 dynamic lights. I suppose the only way around if you need normal-map + ambient light is to write your own shader for that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply