But I noticed that the "setSunIntensity()" changes colors only on models pie, and does not affect the landscape
Then i add another function to apply colors on the terrain too.
example: https://youtu.be/eXEyzpaHlmw
As you can see, I was faced with the problem of colour in the fog of war..
What I did:
I add one more function "setTerrCol(r,g,b)" in JS API addin to qtscriptfunc.cpp where i pass from JS vector3f with r,g,b
Then i simply in terrain.cpp add this vector to colour.byte.r/g/b:
Code: Select all
static void updateLightMap()
{
for (int j = 0; j < mapHeight; ++j)
{
for (int i = 0; i < mapWidth; ++i)
{
MAPTILE *psTile = mapTile(i, j);
PIELIGHT colour = psTile->colour;
if (psTile->tileInfoBits & BITS_GATEWAY && showGateways)
{
colour.byte.g = 255;
}
if (psTile->tileInfoBits & BITS_MARKED)
{
int m = getModularScaledGraphicsTime(2048, 255);
colour.byte.r = MAX(m, 255 - m);
}
lightmapPixmap[(i + j * lightmapWidth) * 3 + 0] = colour.byte.r + terrCol.r;
lightmapPixmap[(i + j * lightmapWidth) * 3 + 1] = colour.byte.g + terrCol.g;
lightmapPixmap[(i + j * lightmapWidth) * 3 + 2] = colour.byte.b + terrCol.b;
if (!pie_GetFogStatus())
{
// fade to black at the edges of the visible terrain area
const float playerX = map_coordf(player.p.x);
const float playerY = map_coordf(player.p.z);
const float distA = i - (playerX - visibleTiles.x / 2);
const float distB = (playerX + visibleTiles.x / 2) - i;
const float distC = j - (playerY - visibleTiles.y / 2);
const float distD = (playerY + visibleTiles.y / 2) - j;
float darken, distToEdge;
// calculate the distance to the closest edge of the visible map
// determine the smallest distance
distToEdge = distA;
if (distB < distToEdge)
{
distToEdge = distB;
}
if (distC < distToEdge)
{
distToEdge = distC;
}
if (distD < distToEdge)
{
distToEdge = distD;
}
darken = (distToEdge) / 2.0f;
if (darken <= 0)
{
lightmapPixmap[(i + j * lightmapWidth) * 3 + 0] = 0;
lightmapPixmap[(i + j * lightmapWidth) * 3 + 1] = 0;
lightmapPixmap[(i + j * lightmapWidth) * 3 + 2] = 0;
}
else if (darken < 1)
{
lightmapPixmap[(i + j * lightmapWidth) * 3 + 0] *= darken;
lightmapPixmap[(i + j * lightmapWidth) * 3 + 1] *= darken;
lightmapPixmap[(i + j * lightmapWidth) * 3 + 2] *= darken;
}
}
}
}
}
Code: Select all
lightmapPixmap[(i + j * lightmapWidth) * 3 + 0] = colour.byte.r;
lightmapPixmap[(i + j * lightmapWidth) * 3 + 1] = colour.byte.g;
lightmapPixmap[(i + j * lightmapWidth) * 3 + 2] = colour.byte.b;
Code: Select all
lightmapPixmap[(i + j * lightmapWidth) * 3 + 0] = colour.byte.r + terrCol.r;
lightmapPixmap[(i + j * lightmapWidth) * 3 + 1] = colour.byte.g + terrCol.g;
lightmapPixmap[(i + j * lightmapWidth) * 3 + 2] = colour.byte.b + terrCol.b;
Problem, is i do not find (or understand) where and why fog of war is reverse colors, when the terrain draw fine.
If I dynamically from JS API will clean to dark the r/g/b from the territory, the fog of war will be lighter. If I territory gradually dyed in red, the fog of war becomes green.