Lighting a terrain generated from a heightmap

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
Guest

Lighting a terrain generated from a heightmap

Post by Guest »

Is there a way to light a terrain generated from a heightmap? I tried to add a light scene node onto my terrain and moved it close to the surface of the terrain, but the light doesn't seem to...uhh...light the terrain.

Any ideas?

thanks in advance
Guest

Post by Guest »

enable the lightning of the terrain and place a dynamic light high above the terrain with a big radius, then it should get the light (i do it the same way)

if you setup the lightning right you can get some pretty good looking results. i remember that one of my first irrlicht screenshots was this one here where i did the exact same thing:

http://mitglied.lycos.de/animespy2003/s ... hading.JPG

hope you like it :) bye and good night, i need some sleep
Guest

Post by Guest »

thanks for the tip GFXstyLER! I got the lighting to work..heh i had to figure out how to get and set light data using SLight. Oh and that image you attached was awesome. Nice work.

thanks again
Guest

Post by Guest »

ok i have another problem. How do you change the light's settings at runtime? I made a little function that changes the radius of the light at runtime, BUT there's one problem, the light doesn't update in real time, i.e. it only updates when the dos-console is the active window.
I know that the radius changes works, since when i alt+tab and switch between the dos console and the main window i see that the light radius has changed.I may have placed the function in the wrong location. Currently i have the following:

Code: Select all

	while(device->run() && isRunning == true)
	{
        enviroObj.runtimeEnvironment(0,0,0);
                   
    	if (device->isWindowActive())
    	{
    
    		driver->beginScene(true, true, 0 );

    		smgr->drawAll();
    		env->drawAll();
    
    		driver->endScene();
...etc
enviroObj.runtimeEnvironment() is the function that updates the light's radius.

any help would be appreciated
[/code]
Guest

Post by Guest »

Code: Select all

    while(device->run() && isRunning == true)
   {                  
       if (device->isWindowActive())
       {
   
          driver->beginScene(true, true, 0 );

          smgr->drawAll();
          env->drawAll();
   
          driver->endScene();

        enviroObj.runtimeEnvironment(0,0,0);
...etc
it has to be inside the if(device ... bla) i think.
Guest

Post by Guest »

weird. i tried what you suggested and now the radius won't change at all. Maybe it's my function's code. this is what the function has:

Code: Select all

void classEnvironment::runtimeEnvironment(int a, int b, int c)
{
     timerCounter++;
     
     if (timerCounter >= 1000000)
     {
        timerCounter = 0;
        
        // darken light
        if (brightnessIsDescending == true)
        {
           lightData = &light->getLightData();                
           lightData->Radius--;
        }
        else if (brightnessIsDescending == false)
        {
             lightData = &light->getLightData();
             lightData->Radius++;
        }
     
        if (lightData->Radius >= 10)
        {
         brightnessIsDescending = true;
         }
         else if (lightData->Radius <= 0)
         {
              brightnessIsDescending = false;
         }
     }
     
}
i was browsing the API and there doesn't seem to be any function that updates the light, so i'm assuming that changing the light data values directly would automatically update the light.
Guest

Post by Guest »

weird. i tried what you suggested and now the radius won't change at all. Maybe it's my function's code. this is what the function has:

Code: Select all

void classEnvironment::runtimeEnvironment(int a, int b, int c)
{
     timerCounter++;
     
     if (timerCounter >= 1000000)
     {
        timerCounter = 0;
        
        // darken light
        if (brightnessIsDescending == true)
        {
           lightData = &light->getLightData();                
           lightData->Radius--;
        }
        else if (brightnessIsDescending == false)
        {
             lightData = &light->getLightData();
             lightData->Radius++;
        }
     
        if (lightData->Radius >= 10)
        {
         brightnessIsDescending = true;
         }
         else if (lightData->Radius <= 0)
         {
              brightnessIsDescending = false;
         }
     }
     
}
i was browsing the API and there doesn't seem to be any function that updates the light, so i'm assuming that changing the light data values directly would automatically update the light.
rsdl
Posts: 13
Joined: Wed May 05, 2004 6:57 am
Location: Soviet Canuckistan

Post by rsdl »

heh n/m...it works...the iteration run was too slow :P

thanks again for the help man!
Post Reply