public static SkyIslandVoxelPopulatorConfig.Builder CreatePreconfigured()
        {
            double scale = 10000;

            var caveShape        = NoiseDistorter.New().Frequency(50 / scale, 75 / scale, 50 / scale).Octaves(5);
            var environmentShape = NoiseDistorter.Combine(
                NoiseDistorter.New().Frequency(25 / scale, 100 / scale, 25 / scale).Octaves(5).Amplitude(.4),
                NoiseDistorter.New().Frequency(1000 / scale, 1000 / scale, 1000 / scale).Octaves(5).Amplitude(.01));
            var edgeSeam = NoiseDistorter.New().Frequency(800 / scale, 800 / scale).ConvertRange(20, 40);

            return(new SkyIslandVoxelPopulatorConfig.Builder()
            {
                EmptyAir = SkyIslandGenerationConstants.EmptyAir,
                TopGradientThickness = 60,
                AboveTopGradientThickness = 30,
                BottomGradientThickness = 30,
                BelowBottomGradientThickness = 15,
                GradiantBuffer = 2,
                CaveTunnelRadius = .4,
                CaveEntranceGradientThickness = 10,
                CaveShapeDistorter = caveShape,
                EnvironmentShapeDistorter = environmentShape,
                EdgeSeamDropoffScaleDistorter = edgeSeam,
            });
        }
Exemplo n.º 2
0
        public NoiseWorldVoxelGridChunkPopulator(
            INoise3D noise, double noiseScaling, int numberOfOctaves, TerrainMaterial material)
        {
            Contracts.Requires.That(noise != null);
            Contracts.Requires.That(noiseScaling > 0);
            Contracts.Requires.That(numberOfOctaves >= 1);

            this.noise     = noise;
            this.distorter = NoiseDistorter.New()
                             .Frequency(noiseScaling, noiseScaling, noiseScaling).Octaves(numberOfOctaves);
            this.material = material;
        }
        public static SkyIslandMapPopulatorConfig.Builder CreatePreconfigured(
            IStageBounds stageBounds, IRasterChunkConfig chunkConfig)
        {
            Contracts.Requires.That(stageBounds != null);
            Contracts.Requires.That(chunkConfig != null);

            double baselineHeightVariation = 50;
            double halfStageHeight         = stageBounds.InChunks.Dimensions.Y * chunkConfig.SideLength / 2.0;
            double baselineMin             = halfStageHeight - baselineHeightVariation;
            double baselineMax             = halfStageHeight + baselineHeightVariation;
            double scale = 10000;

            return(new SkyIslandMapPopulatorConfig.Builder()
            {
                SelectionGradientStartDistancePercent = .6,
                ShapeDistorter = NoiseDistorter.Combine(
                    NoiseDistorter.New().Frequency(20 / scale, 20 / scale).ConvertRange(-1, 1),
                    NoiseDistorter.New().Frequency(40 / scale, 40 / scale).ConvertRange(-.5, .5),
                    NoiseDistorter.New().Frequency(80 / scale, 80 / scale).ConvertRange(-.3, .3)),
                BaselineHeightDistorter =
                    NoiseDistorter.New().Frequency(10 / scale, 10 / scale).ConvertRange(baselineMin, baselineMax),
                MountainDistorter =
                    NoiseDistorter.New().Frequency(10 / scale, 10 / scale).ConvertRange(-6, 5).Clamp(1, 4),
                TopHeightDistorter = NoiseDistorter.Combine(
                    NoiseDistorter.New().Frequency(20 / scale, 20 / scale).ConvertRange(0, 10),
                    NoiseDistorter.New().Frequency(40 / scale, 40 / scale).ConvertRange(0, 40),
                    NoiseDistorter.New().Frequency(80 / scale, 80 / scale).ConvertRange(0, 20),
                    NoiseDistorter.New().Frequency(160 / scale, 160 / scale).ConvertRange(0, 10)),
                TopHeightNearEdgeDistorter = NoiseDistorter.Combine(
                    NoiseDistorter.New().Frequency(20 / scale, 20 / scale).ConvertRange(0, 7.5),
                    NoiseDistorter.New().Frequency(40 / scale, 40 / scale).ConvertRange(0, 30),
                    NoiseDistorter.New().Frequency(80 / scale, 80 / scale).ConvertRange(0, 15),
                    NoiseDistorter.New().Frequency(160 / scale, 160 / scale).ConvertRange(0, 7.5)),
                BottomHeightDistorter =
                    NoiseDistorter.New().Frequency(200 / scale, 200 / scale).ConvertRange(-200, -100),
                BottomHeightNearEdgeDistorter =
                    NoiseDistorter.New().Frequency(800 / scale, 800 / scale).ConvertRange(-100, -50),
            });
        }
        CreateMaterialPropertiesTable(IFactory <int, INoise3D> noiseFactory)
        {
            Contracts.Requires.That(noiseFactory != null);

            var textureAtlasBuilder = new EnumKeyTextureAtlasBuilder <TerrainTexture>(
                atlasPixelDimensions: new Index2D(128, 128),
                swatchPixelDimensions: new Index2D(16, 16),
                invertXAxis: true,
                invertYAxis: false);

            textureAtlasBuilder.AddSwatch(TerrainTexture.None, new Index2D(0, 0));
            textureAtlasBuilder.AddSwatch(TerrainTexture.GrassFull, new Index2D(0, 1));
            textureAtlasBuilder.AddSwatch(TerrainTexture.GrassTop, new Index2D(1, 1));
            textureAtlasBuilder.AddSwatch(TerrainTexture.GrassBottom, new Index2D(2, 1));
            textureAtlasBuilder.AddSwatch(TerrainTexture.Dirt, new Index2D(0, 2));
            textureAtlasBuilder.AddSwatch(TerrainTexture.Stone, new Index2D(0, 3));

            var textureAtlas            = textureAtlasBuilder.Build();
            var materialPropertiesTable =
                EnumDictionary.Create <TerrainMaterial, ITerrainMaterialProperties <TSurfaceData> >();

            float areaThreshold  = .8f;
            var   noiseDistorter = NoiseDistorter.New().Frequency(100, 100, 100);
            var   noTexture      = new TextureSwatchSurfaceGenerator <TerrainVoxel, TSurfaceData>(
                textureAtlas[TerrainTexture.None]);

            materialPropertiesTable[TerrainMaterial.Air] = new TerrainMaterialProperties <TSurfaceData>(
                false,
                new ConstantSurfaceGenerator <TerrainVoxel, TSurfaceData, Color>(Color.Pink),
                noTexture);

            materialPropertiesTable[TerrainMaterial.Dirt] = new TerrainMaterialProperties <TSurfaceData>(
                true,
                new ConstantSurfaceGenerator <TerrainVoxel, TSurfaceData, Color>(new Color(120, 96, 56)),
                new AreaThresholdSurfaceGenerator <TerrainVoxel, TSurfaceData, Vector2>(
                    new NoiseSeedSurfaceGenerator <TerrainVoxel, TSurfaceData, Vector2>(
                        new SeedSwitchSurfaceGenerator <TerrainVoxel, TSurfaceData, Vector2>(
                            noTexture,
                            new SeedRangeSurfaceGenerator <TerrainVoxel, TSurfaceData, Vector2>(
                                .85f, 1f, new TextureSwatchSurfaceGenerator <TerrainVoxel, TSurfaceData>(
                                    textureAtlas[TerrainTexture.Dirt]))),
                        noiseFactory,
                        noiseDistorter),
                    noTexture,
                    areaThreshold));

            materialPropertiesTable[TerrainMaterial.Grass] = new TerrainMaterialProperties <TSurfaceData>(
                true,
                new ConstantSurfaceGenerator <TerrainVoxel, TSurfaceData, Color>(new Color(72, 160, 72)),
                new AreaThresholdSurfaceGenerator <TerrainVoxel, TSurfaceData, Vector2>(
                    new NoiseSeedSurfaceGenerator <TerrainVoxel, TSurfaceData, Vector2>(
                        new SeedSwitchSurfaceGenerator <TerrainVoxel, TSurfaceData, Vector2>(
                            noTexture,
                            new SeedRangeSurfaceGenerator <TerrainVoxel, TSurfaceData, Vector2>(
                                .85f, 1f, new TextureSwatchSurfaceGenerator <TerrainVoxel, TSurfaceData>(
                                    textureAtlas[TerrainTexture.GrassFull]))),
                        noiseFactory,
                        noiseDistorter),
                    noTexture,
                    areaThreshold));

            materialPropertiesTable[TerrainMaterial.Stone] = new TerrainMaterialProperties <TSurfaceData>(
                true,
                new ConstantSurfaceGenerator <TerrainVoxel, TSurfaceData, Color>(Color.Gray),
                new AreaThresholdSurfaceGenerator <TerrainVoxel, TSurfaceData, Vector2>(
                    new NoiseSeedSurfaceGenerator <TerrainVoxel, TSurfaceData, Vector2>(
                        new SeedSwitchSurfaceGenerator <TerrainVoxel, TSurfaceData, Vector2>(
                            noTexture,
                            new SeedRangeSurfaceGenerator <TerrainVoxel, TSurfaceData, Vector2>(
                                .85f, 1f, new TextureSwatchSurfaceGenerator <TerrainVoxel, TSurfaceData>(
                                    textureAtlas[TerrainTexture.Stone]))),
                        noiseFactory,
                        noiseDistorter),
                    noTexture,
                    areaThreshold));

            ////materialPropertiesTable[TerrainMaterial.Coal] = new TerrainMaterialProperties<TSurfaceData>(
            ////	true,
            ////	new ConstantSurfaceGenerator<TerrainVoxel, TSurfaceData, Color>(Color.Black),
            ////	noTexture);

            ////materialPropertiesTable[TerrainMaterial.Iron] = new TerrainMaterialProperties<TSurfaceData>(
            ////	true,
            ////	new ConstantSurfaceGenerator<TerrainVoxel, TSurfaceData, Color>(Color.DarkGray),
            ////	noTexture);

            ////materialPropertiesTable[TerrainMaterial.Gold] = new TerrainMaterialProperties<TSurfaceData>(
            ////	true,
            ////	new ConstantSurfaceGenerator<TerrainVoxel, TSurfaceData, Color>(Color.Gold),
            ////	noTexture);

            ////materialPropertiesTable[TerrainMaterial.Diamond] = new TerrainMaterialProperties<TSurfaceData>(
            ////	true,
            ////	new ConstantSurfaceGenerator<TerrainVoxel, TSurfaceData, Color>(Color.BlueViolet),
            ////	noTexture);

            EnumDictionary.ThrowIfMissingEnumKey(materialPropertiesTable);
            return(materialPropertiesTable);
        }