Пример #1
0
        public static Texture2D CreateClipMask(InterpolatedArray2f heightMap, int width, int height, float shoreLevel, TextureFormat format)
        {
            Texture2D mask = new Texture2D(width, height, format, false, true);
            mask.filterMode = FilterMode.Bilinear;

            Color[] colors = new Color[width * height];

            bool matches = width == heightMap.SX && height == heightMap.SY;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int i = x + y * height;

                    float h = 0.0f;

                    if (matches)
                    {
                        h = Mathf.Clamp(heightMap.Data[i] - shoreLevel, 0.0f, 1.0f);
                    }
                    else
                    {
                        float fx = x / (width - 1.0f);
                        float fy = y / (height - 1.0f);
                        h = Mathf.Clamp(heightMap.Get(fx, fy, 0) - shoreLevel, 0.0f, 1.0f);
                    }

                    if (h > 0.0f) h = 1.0f;

                    colors[i].r = h;
                    colors[i].g = h;
                    colors[i].b = h;
                    colors[i].a = h;
                }
            }

            mask.SetPixels(colors);

            mask.Apply();

            return mask;
        }