Page 1 of 1

sunset/sunrise need help

Posted: 16 Jan 2018, 15:03
by Prot
Since we are now using JS API, you can manage the position of the sun "setSunPosition()" and set colors "setSunIntensity()", I got the idea to make a sunset/sunrise in the game.
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;
				}
			}
		}
	}
}
There i change the

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;
to

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;
Thats all, i do not touch fog of war code.
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. :roll:

Re: sunset/sunrise need help

Posted: 17 Jan 2018, 00:28
by Per
I think you should just wait until some new version of the terrain renderer, like the one Vincent made, is merged. Trying to do this with the existing code just won't be any good.

Re: sunset/sunrise need help

Posted: 17 Jan 2018, 05:42
by Prot
Forgot to say, that is lastest master