Directional light shadows acting like from point light

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
Lighthink
Posts: 3
Joined: Mon Nov 24, 2014 2:16 pm

Directional light shadows acting like from point light

Post by Lighthink »

Hello!
I've set up a directional light to mimic the sun in an open area and that's how I'm doing it:

Code: Select all

    irr::scene::ILightSceneNode *pLight = pSceneMgr->addLightSceneNode( 0, irr::core::vector3df( 0, 0, 0 ), irr::video::SColorf( 0.8, 0.8, 0.8 ) );
 
    pLight->setLightType( irr::video::ELT_DIRECTIONAL );
    pLight->enableCastShadow( 1 );
    pLight->getLightData().Direction = irr::core::vector3df( -1, -1, 0 ).normalize();
The thing is that, although it lights my scene as it should, it casts shadows as if it was a point light at ( 0, 0, 0 ). To convince myself, I modified the position and I got the same shadows as for a point light. If I switch the type to ELT_POINT, the scene is lighted as it should be, but the shadows just remain the same.

Also, that's how I initialize the shadow volumes:

Code: Select all

pNode = pScnMgr->addMeshSceneNode( pMesh );
pShadow = ( (irr::scene::IMeshSceneNode*)pNode )->addShadowVolumeSceneNode();
I did not post any pics of my situation as it's pretty clear what's happening, but I can also post some and even some more code if you think that would be useful.

Thanks in advance
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Directional light shadows acting like from point light

Post by mongoose7 »

There is no code to handle directional lights.
Lighthink
Posts: 3
Joined: Mon Nov 24, 2014 2:16 pm

Re: Directional light shadows acting like from point light

Post by Lighthink »

mongoose7 wrote:There is no code to handle directional lights.
What does that mean? Does ti mean that there is no code to handle shadows from directional lights, so we should not even use it, and the point-like behavior is left as a security measure to prevent crashes or other malfunctions when trying to cast shadows from directional lights? If so, how do I get shadows in my scene?

Thanks for the quick response though
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Directional light shadows acting like from point light

Post by mongoose7 »

I mean, there is no code specifically for shadows from directional lights and the code just uses the point-light code. There is a TODO in the code which has not been TODOne. I am a bit surprised that you can get point-light shadows as I thought directional lights have no centre. But if you do get point-light shadows, move the centre a long way away to approximate a directional light.
Lighthink
Posts: 3
Joined: Mon Nov 24, 2014 2:16 pm

Re: Directional light shadows acting like from point light

Post by Lighthink »

Thanks for the quick answer, it really shed some light on that matter for me. Now I do get correct shadows in my scene by setting the position of the light to ( -direction * 100000 ). I've also noticed that when I tried to set the position of the light scene node after creating it, it did not make any difference ( it was still using the value in addLightSceneNode() for calculating shadows ), so it seems that if I want to change the direction of the light, I have to re-create the light.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Directional light shadows acting like from point light

Post by mongoose7 »

Directional lights have no position. It appears that the create call can (erroneously?) take a position. But, yes, the interface should not allow you to set a position for a directional light. But you could hack the source to allow it, since it is clearly stored (once) and used.
Post Reply