Flickering lights

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
Blynx
Posts: 16
Joined: Sat Apr 12, 2008 8:41 am

Flickering lights

Post by Blynx »

I have a fire and I wanted to simulate a flickering light.
The code I use is:

Code: Select all

//Lighting
smgr->setAmbientLight(video::SColorf(0.1,0.1,0.1,1));
ILightSceneNode* light1 = smgr->addLightSceneNode( 0, core::vector3df(-100,-120,100), video::SColorf(0.1f,0.0f,0.0f), 0.8f, 0 );
light1->getLightData().Attenuation.set(0,1.5f/200.0,0);
Any help is appreciated.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Basically you want to affect the brightness of the light every so often i think... i did have a go at this myself and never managed to get anything that looked good enough...

Basically increasing and decreasing the brightness smoothly (but quickly) every so often will make the light flicker to some extent...

I guess first of all you could try and get your light to loop from fully off to fully on (probably just changing the colour from 0,0,0 to 1,1,1 for off -> on) slowly. once you've got that code working then you can reduce the range of the light (so it's not off to on but darkish to your highest desired brightness) and make it change between them quicker. And you wouldn't want to always go between the same range of brightness, so you'd want a random number to be generated for the range and you'd want the timing to be pretty random too so it doesn't have predicatable flickering.

I don't know if that will make much sense as it's kinda like a brain dump but hopefully it will point you in the right direction, post back if you need more help!
Image Image Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I don't think that fire really flickers that much, at least not from off to on. It merely changes the position of the most intensive spots, which makes shadows move with high frequency.
For the actual flames you can use texture animation stuff, etc, and for the light changes you might try to move the light center very fast inside the flames. However, more authentic lighting will require some cubemap lights or some other shader based techniques.
cyberion
Posts: 30
Joined: Tue Oct 23, 2007 5:53 pm

Post by cyberion »

In loop try this:

Code: Select all

u32 time = device->getTimer()->getTime();
video::SColor(255,time % 255,time % 255,0)
Post Reply