Beispiel #1
0
        void ModifyFog(float[,] alphaMap, Vector3 position, float sightRadius, float strength, float falloff, bool invert)
        {
            Vector2 texturePosition  = WorldToPixel(position);
            float   pixelSightRadius = Mathf.Min(sightRadius * Definition, Mathf.Floor(mapDiagonal / 2 - 1));
            bool    insideRect       = currentArea.Contains(position);
            int     x = (int)texturePosition.x.Round();
            int     y = (int)texturePosition.y.Round();

            if (pixelSightRadius <= 0 || strength <= 0 || fadeSpeed <= 0)
            {
                return;
            }

            if (x >= 0 && x < alphaMap.GetLength(0) && y >= 0 && y < alphaMap.GetLength(1))
            {
                alphaMap[(int)texturePosition.x.Round(), (int)texturePosition.y.Round()] = invert ? 1 - strength : strength;
            }

            List <LineOfSightInfo> centerInfos = currentLineInfos[0, 0];

            for (int i = 0; i < centerInfos.Count; i++)
            {
                PrimaryLineOfSight lineOfSight = new PrimaryLineOfSight(centerInfos[i], x, y, pixelSightRadius, strength, falloff, invert, alphaMap, currentHeightMap, currentLineInfos);

                if (insideRect || (position.x < currentArea.xMin && lineOfSight.info.directionX >= 0) || (position.x > currentArea.xMax && lineOfSight.info.directionX <= 0) || (position.y < currentArea.yMin && lineOfSight.info.directionY >= 0) || (position.y > currentArea.yMax && lineOfSight.info.directionY <= 0))
                {
                    lineOfSight.Complete();
                }
            }
        }
Beispiel #2
0
        void ModifyFog(float[,] alphaMap, Vector3 position, float minRadius, float maxRadius, float cone, float angle, float strength, float preFalloff, float falloff, bool invert)
        {
            Vector2 texturePosition    = WorldToPixel(position);
            float   minPixelRadius     = Mathf.Min(minRadius * Definition, Mathf.Floor(mapDiagonal / 2 - 1));
            float   maxPixelRadius     = Mathf.Min(maxRadius * Definition, Mathf.Floor(mapDiagonal / 2 - 1));
            float   adjustedPrefalloff = preFalloff.Pow(1F / Definition);
            float   adjustedFalloff    = falloff.Pow(1F / Definition);
            bool    insideRect         = Area.Contains(position);
            int     x = (int)texturePosition.x.Round();
            int     y = (int)texturePosition.y.Round();

            if (maxPixelRadius <= 0 || cone <= 0 || strength <= 0 || FadeSpeed <= 0)
            {
                return;
            }

            if (x >= 0 && x < alphaMap.GetLength(0) && y >= 0 && y < alphaMap.GetLength(1))
            {
                alphaMap[(int)texturePosition.x.Round(), (int)texturePosition.y.Round()] = invert ? 1 - strength : strength;
            }

            List <LineOfSightInfo> centerInfos = currentLineInfos[0, 0];
            float halfCone = cone / 2;

            for (int i = 0; i < centerInfos.Count; i++)
            {
                float lineAngle        = i * 45;
                float deltaAngle       = Mathf.Abs(Mathf.DeltaAngle(lineAngle, angle));
                float difference       = deltaAngle - halfCone;
                float adjustedStrength = strength * (1 - Mathf.Clamp01(difference / 45)) * Mathf.Clamp01(halfCone / 45);

                PrimaryLineOfSight lineOfSight = new PrimaryLineOfSight(centerInfos[i], x, y, minPixelRadius, maxPixelRadius, adjustedStrength, adjustedPrefalloff, adjustedFalloff, invert, alphaMap, currentHeightMap, currentLineInfos);

                if (insideRect || (position.x < Area.xMin && lineOfSight.info.DirectionX >= 0) || (position.x > Area.xMax && lineOfSight.info.DirectionX <= 0) || (position.y < Area.yMin && lineOfSight.info.DirectionY >= 0) || (position.y > Area.yMax && lineOfSight.info.DirectionY <= 0))
                {
                    lineOfSight.Complete();
                }
            }
        }