summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2013-02-28 21:26:09 +0100
committerPiotr Dziwinski <piotrdz@gmail.com>2013-02-28 22:06:22 +0100
commit08c646bb929c7bc98b005521b6e0c14428f651d0 (patch)
treebd708ad596274bea8c387122bcd9fceadf620373
parentb361d27d332591c59b5f8613fbf724d82872b877 (diff)
downloadcolobot-08c646bb929c7bc98b005521b6e0c14428f651d0.tar.gz
colobot-08c646bb929c7bc98b005521b6e0c14428f651d0.tar.bz2
colobot-08c646bb929c7bc98b005521b6e0c14428f651d0.zip
Fixed stupid error, tweaked ambient light colors
* fixed stupid error in light manager * tweaked ambient light colors to 0.1 of diffuse; colors should not be oversaturated now
-rw-r--r--src/graphics/core/color.h10
-rw-r--r--src/graphics/engine/lightman.cpp22
-rw-r--r--src/graphics/engine/pyro.cpp9
-rw-r--r--src/object/object.cpp25
-rw-r--r--src/object/robotmain.cpp2
-rw-r--r--src/object/task/taskbuild.cpp17
-rw-r--r--src/object/task/taskshield.cpp13
-rw-r--r--src/ui/displayinfo.cpp1
-rw-r--r--test/unit/graphics/engine/lightman_test.cpp7
9 files changed, 48 insertions, 58 deletions
diff --git a/src/graphics/core/color.h b/src/graphics/core/color.h
index 7cbd175..5d059e5 100644
--- a/src/graphics/core/color.h
+++ b/src/graphics/core/color.h
@@ -76,6 +76,16 @@ struct Color
{
return ! this->operator==(other);
}
+
+ inline Color operator*(float scale) const
+ {
+ Color c = *this;
+ c.r *= scale;
+ c.g *= scale;
+ c.b *= scale;
+ c.a *= scale;
+ return c;
+ }
};
/**
diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp
index 628ebf5..eae622b 100644
--- a/src/graphics/engine/lightman.cpp
+++ b/src/graphics/engine/lightman.cpp
@@ -126,6 +126,7 @@ int CLightManager::CreateLight(LightPriority priority)
m_dynLights[index].light.type = LIGHT_DIRECTIONAL;
m_dynLights[index].light.diffuse = Color(0.5f, 0.5f, 0.5f);
+ m_dynLights[index].light.ambient = Color(0.0f, 0.0f, 0.0f);
m_dynLights[index].light.position = Math::Vector(-100.0f, 100.0f, -100.0f);
m_dynLights[index].light.direction = Math::Vector( 1.0f, -1.0f, 1.0f);
@@ -391,21 +392,21 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type)
std::sort(sortedLights.begin(), sortedLights.end(), LightsComparator(m_engine->GetEyePt(), type));
int lightMapIndex = 0;
- for (int i = 0; i < static_cast<int>( m_dynLights.size() ); i++)
+ for (int i = 0; i < static_cast<int>( sortedLights.size() ); i++)
{
- if (! m_dynLights[i].used)
+ if (! sortedLights[i].used)
continue;
- if (! m_dynLights[i].enabled)
+ if (! sortedLights[i].enabled)
continue;
- if (m_dynLights[i].intensity.current == 0.0f)
+ if (sortedLights[i].intensity.current == 0.0f)
continue;
bool enabled = true;
- if (m_dynLights[i].includeType != ENG_OBJTYPE_NULL)
- enabled = (m_dynLights[i].includeType == type);
+ if (sortedLights[i].includeType != ENG_OBJTYPE_NULL)
+ enabled = (sortedLights[i].includeType == type);
- if (m_dynLights[i].excludeType != ENG_OBJTYPE_NULL)
- enabled = (m_dynLights[i].excludeType != type);
+ if (sortedLights[i].excludeType != ENG_OBJTYPE_NULL)
+ enabled = (sortedLights[i].excludeType != type);
if (enabled)
{
@@ -422,7 +423,8 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type)
int rank = m_lightMap[i];
if (rank != -1)
{
- m_device->SetLight(i, m_dynLights[rank].light);
+ sortedLights[rank].light.ambient = Gfx::Color(0.2f, 0.2f, 0.2f);
+ m_device->SetLight(i, sortedLights[rank].light);
m_device->SetLightEnabled(i, true);
}
else
@@ -458,7 +460,7 @@ bool CLightManager::LightsComparator::operator()(const DynamicLight& left, const
float leftWeight = GetLightWeight(left);
float rightWeight = GetLightWeight(right);
- return leftWeight >= rightWeight;
+ return leftWeight <= rightWeight;
}
} // namespace Gfx
diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp
index 1d80fea..cab28b6 100644
--- a/src/graphics/engine/pyro.cpp
+++ b/src/graphics/engine/pyro.cpp
@@ -1318,12 +1318,9 @@ void CPyro::CreateLight(Math::Vector pos, float height)
Gfx::Light light;
light.type = LIGHT_SPOT;
- light.position.x = pos.x;
- light.position.y = pos.y+height;
- light.position.z = pos.z;
- light.direction.x = 0.0f;
- light.direction.y = -1.0f; // against the bottom
- light.direction.z = 0.0f;
+ light.ambient = Gfx::Color(0.0f, 0.0f, 0.0f);
+ light.position = Math::Vector(pos.x, pos.y+height, pos.z);
+ light.direction = Math::Vector(0.0f, -1.0f, 0.0f); // against the bottom
light.spotIntensity = 1.0f;
light.attenuation0 = 1.0f;
light.attenuation1 = 0.0f;
diff --git a/src/object/object.cpp b/src/object/object.cpp
index 8f2a4cc..d6ac681 100644
--- a/src/object/object.cpp
+++ b/src/object/object.cpp
@@ -2248,15 +2248,10 @@ bool CObject::CreateShadowLight(float height, Gfx::Color color)
Gfx::Light light;
light.type = Gfx::LIGHT_SPOT;
- light.diffuse.r = color.r;
- light.diffuse.g = color.g;
- light.diffuse.b = color.b;
- light.position.x = pos.x;
- light.position.y = pos.y+height;
- light.position.z = pos.z;
- light.direction.x = 0.0f;
- light.direction.y = -1.0f; // against the bottom
- light.direction.z = 0.0f;
+ light.diffuse = color;
+ light.ambient = color * 0.1f;
+ light.position = Math::Vector(pos.x, pos.y+height, pos.z);
+ light.direction = Math::Vector(0.0f, -1.0f, 0.0f); // against the bottom
light.spotIntensity = 128;
light.attenuation0 = 1.0f;
light.attenuation1 = 0.0f;
@@ -2291,15 +2286,9 @@ bool CObject::CreateEffectLight(float height, Gfx::Color color)
Gfx::Light light;
light.type = Gfx::LIGHT_SPOT;
- light.diffuse.r = color.r;
- light.diffuse.g = color.g;
- light.diffuse.b = color.b;
- light.position.x = 0.0f;
- light.position.y = 0.0f+height;
- light.position.z = 0.0f;
- light.direction.x = 0.0f;
- light.direction.y = -1.0f; // against the bottom
- light.direction.z = 0.0f;
+ light.diffuse = color;
+ light.position = Math::Vector(0.0f, height, 0.0f);
+ light.direction = Math::Vector(0.0f, -1.0f, 0.0f); // against the bottom
light.spotIntensity = 0.0f;
light.attenuation0 = 1.0f;
light.attenuation1 = 0.0f;
diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index 6efd853..29fdd31 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -4917,6 +4917,7 @@ int CRobotMain::CreateLight(Math::Vector direction, Gfx::Color color)
Gfx::Light light;
light.type = Gfx::LIGHT_DIRECTIONAL;
light.diffuse = color;
+ light.ambient = color * 0.1f;
light.direction = direction;
int obj = m_lightMan->CreateLight(Gfx::LIGHT_PRI_HIGH);
m_lightMan->SetLight(obj, light);
@@ -4934,6 +4935,7 @@ int CRobotMain::CreateSpot(Math::Vector pos, Gfx::Color color)
Gfx::Light light;
light.type = Gfx::LIGHT_SPOT;
light.diffuse = color;
+ light.ambient = color * 0.1f;
light.position = pos;
light.direction = Math::Vector(0.0f, -1.0f, 0.0f);
light.spotIntensity = 1.0f;
diff --git a/src/object/task/taskbuild.cpp b/src/object/task/taskbuild.cpp
index f209cd5..b9af475 100644
--- a/src/object/task/taskbuild.cpp
+++ b/src/object/task/taskbuild.cpp
@@ -114,7 +114,6 @@ bool CTaskBuild::CreateBuilding(Math::Vector pos, float angle)
void CTaskBuild::CreateLight()
{
- Gfx::Light light;
Gfx::Color color;
Math::Vector center, pos, dir;
Math::Point c, p;
@@ -141,18 +140,12 @@ void CTaskBuild::CreateLight()
pos.y = center.y+40.0f;
dir = center-pos;
- memset(&light, 0, sizeof(light));
+ Gfx::Light light;
light.type = Gfx::LIGHT_SPOT;
- light.diffuse.r = 0.0f;
- light.diffuse.g = 0.0f;
- light.diffuse.b = 0.0f; // white (invisible)
- light.position.x = pos.x;
- light.position.y = pos.y;
- light.position.z = pos.z;
- light.direction.x = dir.x;
- light.direction.y = dir.y;
- light.direction.z = dir.z;
- //TODO Is this value correct
+ light.ambient = Gfx::Color(0.0f, 0.0f, 0.0f);
+ light.diffuse = Gfx::Color(0.0f, 0.0f, 0.0f); // invisible
+ light.position = pos;
+ light.direction = dir;
light.spotIntensity = 128;
light.attenuation0 = 1.0f;
light.attenuation1 = 0.0f;
diff --git a/src/object/task/taskshield.cpp b/src/object/task/taskshield.cpp
index 4b2fccd..929dd5c 100644
--- a/src/object/task/taskshield.cpp
+++ b/src/object/task/taskshield.cpp
@@ -488,15 +488,10 @@ bool CTaskShield::CreateLight(Math::Vector pos)
memset(&light, 0, sizeof(light));
light.type = Gfx::LIGHT_SPOT;
- light.diffuse.r = 0.0f;
- light.diffuse.g = 1.0f;
- light.diffuse.b = 2.0f;
- light.position.x = pos.x;
- light.position.y = pos.y;
- light.position.z = pos.z;
- light.direction.x = 0.0f;
- light.direction.y = -1.0f; // against the bottom
- light.direction.z = 0.0f;
+ light.ambient = Gfx::Color(0.0f, 0.0f, 0.0f);
+ light.diffuse = Gfx::Color(0.0f, 1.0f, 2.0f);
+ light.position = pos;
+ light.direction = Math::Vector(0.0f, -1.0f, 0.0f); // against the bottom
light.spotIntensity = 128;
light.attenuation0 = 1.0f;
light.attenuation1 = 0.0f;
diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp
index a9e754f..9a31956 100644
--- a/src/ui/displayinfo.cpp
+++ b/src/ui/displayinfo.cpp
@@ -455,6 +455,7 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc
}
light.type = Gfx::LIGHT_DIRECTIONAL;
+ light.ambient = Gfx::Color(0.0f, 0.0f, 0.0f);
light.diffuse = Gfx::Color(1.0f, 0.1f, 0.1f);
light.direction = Math::Vector(1.0f, 0.0f, 1.0f);
diff --git a/test/unit/graphics/engine/lightman_test.cpp b/test/unit/graphics/engine/lightman_test.cpp
index 529cee8..b20b058 100644
--- a/test/unit/graphics/engine/lightman_test.cpp
+++ b/test/unit/graphics/engine/lightman_test.cpp
@@ -75,6 +75,7 @@ void LightManagerUT::AddLight(int type, LightPriority priority, bool used, bool
Light light;
light.type = static_cast<LightType>(type);
+ light.position = pos;
lightManager.SetLight(rank, light);
lightManager.SetLightEnabled(rank, enabled);
@@ -109,7 +110,7 @@ TEST_F(LightManagerUT, LightSorting_IncludeTypesAreIncluded)
AddLight(2, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_TERRAIN, ENG_OBJTYPE_NULL);
AddLight(3, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_QUARTZ, ENG_OBJTYPE_NULL);
- std::vector<int> expectedLights = { 1, 2 };
+ std::vector<int> expectedLights = { 2, 1 };
CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights);
}
@@ -123,7 +124,7 @@ TEST_F(LightManagerUT, LightSorting_ExcludeTypesAreExcluded)
AddLight(2, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_TERRAIN);
AddLight(3, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_QUARTZ);
- std::vector<int> expectedLights = { 1, 3 };
+ std::vector<int> expectedLights = { 3, 1 };
CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights);
}
@@ -140,6 +141,6 @@ TEST_F(LightManagerUT, LightSorting_SortingAccordingToDistance)
AddLight(5, LIGHT_PRI_LOW, true, true, Math::Vector(100.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
AddLight(6, LIGHT_PRI_HIGH, true, true, Math::Vector(21.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
- std::vector<int> expectedLights = { 1, 2, 3 };
+ std::vector<int> expectedLights = { 2, 1, 3 };
CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights);
}