Esempio n. 1
0
        private TextureWithSize CreateBaseTexture(float height, DebugTerrainCharacter character)
        {
            if (character == DebugTerrainCharacter.Noise)
            {
                var texture = new RenderTexture(241, 241, 0, RenderTextureFormat.RFloat);
                texture.wrapMode   = TextureWrapMode.Clamp;
                texture.filterMode = FilterMode.Point;

                var material = new Material(Shader.Find("Custom/Tool/FillHeightTextureWithRandomValues"));
                material.SetTexture("_HeightTexture", texture);
                Graphics.Blit(texture, (RenderTexture)texture, material);
                return(new TextureWithSize()
                {
                    Texture = texture,
                    Size = new IntVector2(241, 241)
                });
            }
            else
            {
                float[,] heightArray;

                if (character == DebugTerrainCharacter.Flat)
                {
                    heightArray = MyArrayUtils.CreateFilled(241, 241, height);
                }
                else //if (character == DebugTerrainCharacter.Volcano)
                {
                    heightArray = new float[241, 241];
                    float minHeight = height * 0.2f;
                    float maxHeight = height;
                    for (int x = 0; x < 241; x++)
                    {
                        for (int y = 0; y < 241; y++)
                        {
                            heightArray[x, y] = Mathf.Lerp(minHeight, maxHeight,
                                                           1 - Vector2.Distance(new Vector2(x, y), new Vector2(120, 120)) / 200f);
                        }
                    }
                }
                var heightTex = HeightmapUtils.CreateTextureFromHeightmap(new HeightmapArray(heightArray));

                var transformator      = new TerrainTextureFormatTransformator(new CommonExecutorUTProxy());
                var plainHeightTexture = transformator.EncodedHeightTextureToPlain(new TextureWithSize()
                {
                    Size    = new IntVector2(241, 241),
                    Texture = heightTex
                });
                plainHeightTexture.wrapMode = TextureWrapMode.Clamp;
                return(new TextureWithSize()
                {
                    Size = new IntVector2(241, 241),
                    Texture = plainHeightTexture
                });
            }
        }