From 597f4153e69f5490527d06f6b90bfb8ceb71cb44 Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Wed, 28 Feb 2018 21:55:01 -0500 Subject: [PATCH 1/2] Reverse terrain lighting direction Previously, the terrain lighting was the opposite direction of the object (structure, droid, etc) lighting. --- src/lighting.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lighting.cpp b/src/lighting.cpp index 2bd12ca2795..370ea5b4fb9 100644 --- a/src/lighting.cpp +++ b/src/lighting.cpp @@ -52,6 +52,7 @@ /* The vector that holds the sun's lighting direction - planar */ static Vector3f theSun; +static Vector3f theSun_ForTileIllumination; /* Module function Prototypes */ static UDWORD calcDistToTile(UDWORD tileX, UDWORD tileY, Vector3i *pos); @@ -60,6 +61,7 @@ static void calcTileIllum(UDWORD tileX, UDWORD tileY); void setTheSun(Vector3f newSun) { theSun = normalise(newSun) * float(FP12_MULTIPLIER); + theSun_ForTileIllumination = Vector3f(-theSun.x, -theSun.y, theSun.z); } Vector3f getTheSun() @@ -212,7 +214,7 @@ static void calcTileIllum(UDWORD tileX, UDWORD tileY) finalVector = finalVector + normals[i]; } - dotProduct = glm::dot(normalise(finalVector), theSun); + dotProduct = glm::dot(normalise(finalVector), theSun_ForTileIllumination); val = abs(dotProduct) / 16; if (val == 0) From 44f73efecb08c89623aa55c224f0ee5b732474d7 Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Wed, 28 Feb 2018 21:58:13 -0500 Subject: [PATCH 2/2] Recalculate tile illumination when the sun vector changes --- src/lighting.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lighting.cpp b/src/lighting.cpp index 370ea5b4fb9..68345bd356a 100644 --- a/src/lighting.cpp +++ b/src/lighting.cpp @@ -60,8 +60,14 @@ static void calcTileIllum(UDWORD tileX, UDWORD tileY); void setTheSun(Vector3f newSun) { + Vector3f oldSun = theSun; theSun = normalise(newSun) * float(FP12_MULTIPLIER); theSun_ForTileIllumination = Vector3f(-theSun.x, -theSun.y, theSun.z); + if(oldSun != theSun) + { + // The sun has changed - must relcalulate lighting + initLighting(0, 0, mapWidth, mapHeight); + } } Vector3f getTheSun()