Problems adding another sun
by Manoel Neto · in Torque Game Engine · 11/20/2005 (12:15 pm) · 3 replies
I noticed the shading on our characters wasn't quite showing all their detail, when in certain angles (they look flat under ambient color). So I decided to add another weaker sun at the opposite direction of the main sun, with zero ambient light and slightly blue color.
It dramatically improved the lighting (we have $pref::OpenGL::sgDynamicDTSVectorLighting set to TRUE to get better results form the TGE sun), but everything went to hell when I relit the scene: the terrain is much darker now, making the characters dark too. Only the TSStatics and the interiors are being lit properly.
I went down to the source and noticed LightManager::addLight would register whatever direcitonal light passed as the sun. I tried to change it, to only register the strongest directional light as the sun, but the terrain doesn't seem to care about it!
Could someone help me in getting the terrain to use the correct sun while relighting?
It dramatically improved the lighting (we have $pref::OpenGL::sgDynamicDTSVectorLighting set to TRUE to get better results form the TGE sun), but everything went to hell when I relit the scene: the terrain is much darker now, making the characters dark too. Only the TSStatics and the interiors are being lit properly.
I went down to the source and noticed LightManager::addLight would register whatever direcitonal light passed as the sun. I tried to change it, to only register the strongest directional light as the sun, but the terrain doesn't seem to care about it!
Could someone help me in getting the terrain to use the correct sun while relighting?
About the author
Recent Threads
#2
The weaker sun no longer messes the terrain lighting, and I can happily put it at negative azimuths without getting dark terrains and get some nice radiosity-style lighting on the DTS shapes *and* the outside of interiors. It looks like light reflected off the ground.
Here's the changes:
in lightManager.cc:
I changed:
To:
And in sgSceneLightingInsert.h, I changed:
To:
Not the cleanest solution, but it does it. The perfect solution would be rendering the multiple suns, but I have no idea what the terrain does from here on to get it's lightmap done, so that's out of my league, for now.
But it would be very nice, since multiple directional lights can be used to get a nice fake global illumination effect on outdoor areas, using weaker lights to act as reflected light/sky light.
11/22/2005 (12:24 pm)
Thanks John, that did it!The weaker sun no longer messes the terrain lighting, and I can happily put it at negative azimuths without getting dark terrains and get some nice radiosity-style lighting on the DTS shapes *and* the outside of interiors. It looks like light reflected off the ground.
Here's the changes:
in lightManager.cc:
I changed:
void LightManager::addLight(LightInfo * light)
{
mLights.push_back(light);
if(light->mType == LightInfo::Vector)
mSunLight = light;
}To:
void LightManager::addLight(LightInfo * light)
{
mLights.push_back(light);
//PRLD_MULTIPLE_SUNS_FIX_START
// ORIGINAL CODE:
//if(light->mType == LightInfo::Vector)
// mSunLight = light;
if(light->mType == LightInfo::Vector) {
if (!mSunLight)
mSunLight = light;
else {
//Check if this light is stronger than the current one, if so, set it as the sun
F32 oldValue = mSunLight->mColor.red + mSunLight->mColor.blue + mSunLight->mColor.green;
F32 newValue = light->mColor.red + light->mColor.blue + light->mColor.green;
if (newValue >= oldValue)
mSunLight = light;
}
}
//PRLD_MULTIPLE_SUNS_FIX_END
}And in sgSceneLightingInsert.h, I changed:
/// reroutes TerrainProxy::preLight for point light and TSStatic support.
bool SceneLighting::TerrainProxy::preLight(LightInfo * light)
{
if(!bool(mObj))
return(false);
if((light->mType != LightInfo::Vector) &&
(light->mType != LightInfo::SGStaticPoint) &&
(light->mType != LightInfo::SGStaticSpot))
return(false);
mShadowMask.clear();
return(true);
}To:
/// reroutes TerrainProxy::preLight for point light and TSStatic support.
bool SceneLighting::TerrainProxy::preLight(LightInfo * light)
{
if(!bool(mObj))
return(false);
if((light->mType != LightInfo::Vector) &&
(light->mType != LightInfo::SGStaticPoint) &&
(light->mType != LightInfo::SGStaticSpot))
return(false);
//PRLD_MULTIPLE_SUN_FIX
//The terrain can only be lit by one sun. The strongest sun will be used
if (light->mType == LightInfo::Vector)
if (light != gClientSceneGraph->getLightManager()->getSunLight())
return(false);
mShadowMask.clear();
return(true);
}Not the cleanest solution, but it does it. The perfect solution would be rendering the multiple suns, but I have no idea what the terrain does from here on to get it's lightmap done, so that's out of my league, for now.
But it would be very nice, since multiple directional lights can be used to get a nice fake global illumination effect on outdoor areas, using weaker lights to act as reflected light/sky light.
#3
11/22/2005 (2:42 pm)
Cool!
Torque Owner John Kabus (BobTheCBuilder)
Torque really isn't setup to do this, but it sounds like you have some of it working. Scene lighting doesn't use the light manager's sunlight object, instead it uses LightManager::getLights to get all lights, and because Torque isn't really setup to handle multiple suns the second sun overwrites the first (as far as I can tell).
You can try setting up the sun to only register its light if it's the brightest and the scene is not relighting. That way during relight only one registers, but then during rendering all of them register.
-John