Пример #1
0
        public static BiomeParams mountains(ivec3 chunkPos)
        {
            BiomeParams biomeParams = new BiomeParams
            {
                heightMap         = new float[16, 16],
                fullRockHeightMap = new float[16, 16],

                minY = 64,
                maxY = 255,

                rockMin = 160,
                rockMax = 180
            };

            ivec2 chunkPos2d = new ivec2(chunkPos.x, chunkPos.z);

            for (int x = 0; x < 16; x++)
            {
                for (int y = 0; y < 16; y++)
                {
                    biomeParams.heightMap[x, y]         = getNoise(chunkPos2d, new ivec2(x, y), 6, 12, persistance: 0.4f);
                    biomeParams.fullRockHeightMap[x, y] = getNoise(chunkPos2d, new ivec2(x, y), 1, 4);
                }
            }

            return(biomeParams);
        }
Пример #2
0
    public static BiomeParams mountains(int2 chunkPos)
    {
        BiomeParams biomeParams = new BiomeParams
        {
            heightMap         = new float[16, 16],
            fullRockHeightMap = new float[16, 16],

            minY = 10,
            maxY = 256,

            rockMin = 110,
            rockMax = 130
        };

        for (int x = 0; x < 16; x++)
        {
            for (int y = 0; y < 16; y++)
            {
                biomeParams.heightMap[x, y]         = getNoise(chunkPos, new int2(x, y), 8, 8, persistance: 0.4f);
                biomeParams.fullRockHeightMap[x, y] = getNoise(chunkPos, new int2(x, y), 1, 4);
            }
        }

        return(biomeParams);
    }
Пример #3
0
//		private static readonly SimplexPerlin _noiseGen = new SimplexPerlin(0, NoiseQuality.Standard);

        public static NativeArray <byte> generateChunkBlocks(ivec3 chunkPos, Func <ivec3, BiomeParams> biome)
        {
            BiomeParams biomeParams = biome(chunkPos);

            NativeArray <byte> blocks = new NativeArray <byte>(4096, BlockType.AIR);

            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    int surfaceHeight  = biomeParams.minY + (int)(biomeParams.heightMap[x, z] * (biomeParams.maxY - biomeParams.minY));
                    int fullRockHeight = biomeParams.rockMin + (int)(biomeParams.fullRockHeightMap[x, z] * (biomeParams.rockMax - biomeParams.rockMin));

                    for (int y = 0; y < 16; y++)
                    {
                        ivec3 blockWorldPos = MathUtils.getBlockWorldPos(chunkPos, new ivec3(x, y, z));

                        if (surfaceHeight > fullRockHeight)
                        {
                            if (blockWorldPos.y < surfaceHeight)
                            {
                                blocks[x + y * 16 + z * 256] = BlockType.STONE;
                            }
                        }
                        else
                        {
                            if (blockWorldPos.y < surfaceHeight - 4)
                            {
                                blocks[x + y * 16 + z * 256] = BlockType.STONE;
                            }
                            else if (blockWorldPos.y < surfaceHeight - 1)
                            {
                                blocks[x + y * 16 + z * 256] = BlockType.DIRT;
                            }
                            else if (blockWorldPos.y < surfaceHeight)
                            {
                                blocks[x + y * 16 + z * 256] = BlockType.GRASS;
                            }
                        }
                    }
                }
            }

            return(blocks);
        }
Пример #4
0
    public static void generateChunkBlocks(NativeArray <byte> blocks, int2 chunkPos, Func <int2, BiomeParams> biome)
    {
        BiomeParams biomeParams = biome(chunkPos);

        for (int x = 0; x < 16; x++)
        {
            for (int z = 0; z < 16; z++)
            {
                int surfaceHeight  = Math.Min(biomeParams.minY + (int)(biomeParams.heightMap[x, z] * (biomeParams.maxY - biomeParams.minY)), 256);
                int fullRockHeight = biomeParams.rockMin + (int)(biomeParams.fullRockHeightMap[x, z] * (biomeParams.rockMax - biomeParams.rockMin));

                for (int y = 0; y < surfaceHeight; y++)
                {
                    if (surfaceHeight > fullRockHeight)
                    {
                        blocks[y + z * 256 + x * 4096] = BlockType.STONE;
                    }
                    else
                    {
                        if (y < surfaceHeight - 4)
                        {
                            blocks[y + z * 256 + x * 4096] = BlockType.STONE;
                        }
                        else if (y < surfaceHeight - 1)
                        {
                            blocks[y + z * 256 + x * 4096] = BlockType.DIRT;
                        }
                        else
                        {
                            blocks[y + z * 256 + x * 4096] = BlockType.GRASS;
                        }
                    }
                }
            }
        }
    }