示例#1
0
    // Use this for initialization
    void Start()
    {
        IModule mountainTerrain = new RidgedMulti();
        IModule baseFlatTerrain = new Billow();

        ((Billow)baseFlatTerrain).Frequency = 2.0;
        IModule flatTerrain = new ScaleBias(baseFlatTerrain, 0.125, -0.75);
        IModule terrainType = new Perlin();

        ((Perlin)terrainType).Frequency   = 0.5;
        ((Perlin)terrainType).Persistence = 0.25;
        IModule finalTerrain = new Select(flatTerrain, mountainTerrain, terrainType);

        ((Select)finalTerrain).SetBounds(0.0, 1000.0);
        ((Select)finalTerrain).SetEdgeFallOff(0.125);
        NoiseMapBuilderPlane heightMapBuilder = new NoiseMapBuilderPlane(256, 256);

        heightMapBuilder.SetBounds(6.0, 10.0, 1.0, 5.0);
        heightMapBuilder.Build(finalTerrain);
        RendererImage render = new RendererImage();

        render.SourceNoiseMap = heightMapBuilder.Map;
        render.ClearGradient();
        render.AddGradientPoint(-1.0000, new Color32(32, 160, 0, 255));
        render.AddGradientPoint(-0.2500, new Color32(224, 224, 0, 255));
        render.AddGradientPoint(0.2500, new Color32(128, 128, 128, 255));
        render.AddGradientPoint(1.0000, new Color32(255, 255, 255, 255));
        render.IsLightEnabled  = true;
        render.LightContrast   = 3.0;
        render.LightBrightness = 2.0;
        render.Render();
        tex = render.GetTexture();
    }
示例#2
0
        static void Tutorial4()
        {
            Console.WriteLine("Begin Tutorial 4");

            RiggedMultifractal mountainTerrain = new RiggedMultifractal();
            Billow             baseFlatTerrain = new Billow();

            baseFlatTerrain.Frequency = 2.0;

            ScaleBias flatTerrain = new ScaleBias();

            flatTerrain[0]    = baseFlatTerrain;
            flatTerrain.Scale = 0.125;
            flatTerrain.Bias  = -0.75;

            Perlin terrainType = new Perlin();

            terrainType.Frequency   = 0.5;
            terrainType.Persistence = 0.25;

            Select finalTerrain = new Select();

            finalTerrain[0]         = flatTerrain;
            finalTerrain[1]         = mountainTerrain;
            finalTerrain.Controller = terrainType;
            finalTerrain.SetBounds(0.0, 1000.0);
            finalTerrain.FallOff = 0.125;

            NoiseMap             heightMap        = new NoiseMap();
            NoiseMapBuilderPlane heightMapBuilder = new NoiseMapBuilderPlane();;

            heightMapBuilder.SetSourceModule(finalTerrain);
            heightMapBuilder.SetDestNoiseMap(heightMap);
            heightMapBuilder.SetDestSize(256, 256);
            heightMapBuilder.SetBounds(6.0, 10.0, 1.0, 5.0);
            heightMapBuilder.Build();

            RendererImage renderer = new RendererImage();
            NoiseImage    image    = new NoiseImage();

            renderer.SetSourceNoiseMap(heightMap);
            renderer.SetDestImage(image);
            renderer.ClearGradient();
            renderer.AddGradientPoint(-1.00, new Color(32, 160, 0, 255));   // grass
            renderer.AddGradientPoint(-0.25, new Color(224, 224, 0, 255));  // dirt
            renderer.AddGradientPoint(0.25, new Color(128, 128, 128, 255)); // rock
            renderer.AddGradientPoint(1.00, new Color(255, 255, 255, 255)); // snow
            renderer.EnableLight();
            renderer.SetLightContrast(3.0);
            renderer.SetLightBrightness(2.0);
            renderer.Render();

            WriterBMP writer = new WriterBMP();

            writer.SetSourceImage(image);
            writer.SetDestFilename("tutorial4.bmp");
            writer.WriteDestFile();

            Console.WriteLine("End Tutorial 4");
        }
示例#3
0
    private Texture2D RenderNorm(IModule module)
    {
        RendererNormal render = new RendererNormal();

        switch ((MAPTYPE)popMapTypes)
        {
        case MAPTYPE.Cylindirical:
            NoiseMapBuilderCylinder buildCylindirical = new NoiseMapBuilderCylinder(textureWidth, textureHeight);
            buildCylindirical.SetBounds(lowerXBound, upperXBound, lowerZBound, upperZBound);
            buildCylindirical.Build(module);
            render.SourceNoiseMap = buildCylindirical.Map;
            break;

        case MAPTYPE.Spherical:
            NoiseMapBuilderSphere buildSpherical = new NoiseMapBuilderSphere(textureWidth, textureHeight);
            buildSpherical.SetBounds(lowerXBound, upperXBound, lowerZBound, upperZBound);
            buildSpherical.Build(module);
            render.SourceNoiseMap = buildSpherical.Map;
            break;

        case MAPTYPE.Planar:
            NoiseMapBuilderPlane buildPlanar = new NoiseMapBuilderPlane(textureWidth, textureHeight);
            buildPlanar.SetBounds(lowerXBound, upperXBound, lowerZBound, upperZBound);
            buildPlanar.Build(module);
            render.SourceNoiseMap = buildPlanar.Map;
            break;

        default:
            break;
        }

        render.BumpHeight = bumpHeight;
        render.Render();
        return(render.GetTexture());
    }
示例#4
0
    private Texture2D RenderTex(IModule module)
    {
        switch ((MAPTYPE)popMapTypes)
        {
        case MAPTYPE.Cylindirical:
            NoiseMapBuilderCylinder buildCylindirical = new NoiseMapBuilderCylinder(textureWidth, textureHeight);
            buildCylindirical.SetBounds(lowerXBound, upperXBound, lowerZBound, upperZBound);
            buildCylindirical.Build(module);
            render.SourceNoiseMap = buildCylindirical.Map;
            break;

        case MAPTYPE.Spherical:
            NoiseMapBuilderSphere buildSpherical = new NoiseMapBuilderSphere(textureWidth, textureHeight);
            buildSpherical.SetBounds(lowerXBound, upperXBound, lowerZBound, upperZBound);
            buildSpherical.Build(module);
            render.SourceNoiseMap = buildSpherical.Map;
            break;

        case MAPTYPE.Planar:
            NoiseMapBuilderPlane buildPlanar = new NoiseMapBuilderPlane(textureWidth, textureHeight);
            buildPlanar.SetBounds(lowerXBound, upperXBound, lowerZBound, upperZBound);
            buildPlanar.IsSeamless = seamlessEnabled;
            buildPlanar.Build(module);
            render.SourceNoiseMap = buildPlanar.Map;
            break;

        default:
            break;
        }

        ImageMap backMap = null;

        if (backgroundTexture != null)
        {
            backMap = new ImageMap(backgroundTexture, Color.gray);
        }

        if (backMap != null)
        {
            render.BackgroundImage = backMap;
        }

        render.IsWrapEnabled   = wrapEnabled;
        render.IsLightEnabled  = lightEnabled;
        render.LightContrast   = lightContrast;
        render.LightAzimuth    = lightAzimuth;
        render.LightBrightness = lightBrightness;
        render.LightColor      = lightColor;
        render.LightContrast   = lightContrast;
        render.LightElev       = lightElevation;
        render.LightIntensity  = lightIntensity;
        render.Render();
        return(render.GetTexture());
    }
示例#5
0
        static void Tutorial3()
        {
            Console.WriteLine("Begin Tutorial 3");
            Perlin               myModule         = new Perlin();
            NoiseMap             heightMap        = new NoiseMap();
            NoiseMapBuilderPlane heightMapBuilder = new NoiseMapBuilderPlane();

            heightMapBuilder.SetSourceModule(myModule);
            heightMapBuilder.SetDestNoiseMap(heightMap);
            heightMapBuilder.SetDestSize(256, 256);
            heightMapBuilder.SetBounds(6.0, 10.0, 1.0, 5.0);

            RendererImage renderer = new RendererImage();
            NoiseImage    image    = new NoiseImage();

            renderer.SetSourceNoiseMap(heightMap);
            renderer.SetDestImage(image);

            WriterBMP writer = new WriterBMP();

            writer.SetSourceImage(image);

            renderer.ClearGradient();
            renderer.AddGradientPoint(-1.0000, new Color(0, 0, 128, 255));    // deeps
            renderer.AddGradientPoint(-0.2500, new Color(0, 0, 255, 255));    // shallow
            renderer.AddGradientPoint(0.0000, new Color(0, 128, 255, 255));   // shore
            renderer.AddGradientPoint(0.0625, new Color(240, 240, 64, 255));  // sand
            renderer.AddGradientPoint(0.1250, new Color(32, 160, 0, 255));    // grass
            renderer.AddGradientPoint(0.3750, new Color(224, 224, 0, 255));   // dirt
            renderer.AddGradientPoint(0.7500, new Color(128, 128, 128, 255)); // rock
            renderer.AddGradientPoint(1.0000, new Color(255, 255, 255, 255)); // snow
            renderer.EnableLight();
            renderer.SetLightContrast(3.0);                                   // Triple the contrast
            renderer.SetLightBrightness(2.0);                                 // Double the brightness
            for (int octave = 1; octave <= 6; octave++)
            {
                for (int frecuency = 1; frecuency <= 8; frecuency = frecuency * 2)
                {
                    for (int persistence = 1; persistence <= 3; persistence++)
                    {
                        myModule.OctaveCount = octave;
                        myModule.Frequency   = frecuency;
                        myModule.Persistence = persistence / 4.0f;
                        heightMapBuilder.Build();
                        renderer.Render();
                        writer.SetDestFilename("tutorial3-" + octave + "-" + frecuency + "-" + persistence + ".bmp");
                        writer.WriteDestFile();
                    }
                }
            }

            Console.WriteLine("End Tutorial 3");
        }
示例#6
0
    // Use this for initialization
    void Start()
    {
        IModule primaryGranite = new Billow();

        ((Billow)primaryGranite).Seed         = 0;
        ((Billow)primaryGranite).Frequency    = 8.0;
        ((Billow)primaryGranite).Persistence  = 0.625;
        ((Billow)primaryGranite).Lacunarity   = 2.18359375;
        ((Billow)primaryGranite).OctaveCount  = 6;
        ((Billow)primaryGranite).NoiseQuality = NoiseQuality.Standard;
        IModule baseGrains = new Voronoi();

        ((Voronoi)baseGrains).Seed           = 1;
        ((Voronoi)baseGrains).Frequency      = 16.0;
        ((Voronoi)baseGrains).EnableDistance = true;
        IModule scaledGrains = new ScaleBias(baseGrains);

        ((ScaleBias)scaledGrains).Scale = -0.5;
        ((ScaleBias)scaledGrains).Bias  = 0.0;
        IModule combinedGranite = new Add(primaryGranite, scaledGrains);
        IModule finalGranite    = new Turbulence(combinedGranite);

        ((Turbulence)finalGranite).Seed      = 2;
        ((Turbulence)finalGranite).Frequency = 4.0;
        ((Turbulence)finalGranite).Power     = 1.0 / 8.0;
        ((Turbulence)finalGranite).Roughness = 6;
        NoiseMapBuilderPlane plane = new NoiseMapBuilderPlane(256, 256);

        plane.SetBounds(-1.0, 1.0, -1.0, 1.0);
        plane.Build(finalGranite);
        RendererImage render = new RendererImage();

        render.SourceNoiseMap = plane.Map;
        render.ClearGradient();
        render.AddGradientPoint(-1.0000, new Color32(0, 0, 0, 255));
        render.AddGradientPoint(-0.9375, new Color32(0, 0, 0, 255));
        render.AddGradientPoint(-0.8750, new Color32(216, 216, 242, 255));
        render.AddGradientPoint(0.0000, new Color32(191, 191, 191, 255));
        render.AddGradientPoint(0.5000, new Color32(210, 116, 125, 255));
        render.AddGradientPoint(0.7500, new Color32(210, 113, 98, 255));
        render.AddGradientPoint(1.0000, new Color32(255, 176, 192, 255));
        render.IsLightEnabled = true;
        render.LightAzimuth   = 135.0;
        render.LightElev      = 60.0;
        render.LightContrast  = 2.0;
        render.LightColor     = new Color32(255, 255, 255, 0);
        render.Render();
        tex = render.GetTexture();
    }
示例#7
0
    private void SetTerrainHeights(IModule module)
    {
        TerrainData          terData     = terrain.terrainData;
        NoiseMapBuilderPlane buildPlanar = new NoiseMapBuilderPlane(terData.heightmapResolution, terData.heightmapResolution);

        buildPlanar.SetBounds(lowerXBound, upperXBound, lowerZBound, upperZBound);
        buildPlanar.Build(module);
        float[,] heights = new float[terData.heightmapResolution, terData.heightmapResolution];

        for (int z = 0; z < terData.heightmapResolution; z++)
        {
            for (int x = 0; x < terData.heightmapResolution; x++)
            {
                heights[x, z] = ConvertRange01(buildPlanar.Map.GetValue(x, z));
                //heights[x,z] *= terData.size.y;
            }
        }

        terData.SetHeights(0, 0, heights);
        //terData.splatPrototypes[0].texture = finalTexture;
        Debug.Log("Water Level is: " + terData.size.y / 2.0f);
    }
示例#8
0
        static void Tutorial2()
        {
            Console.WriteLine("Begin Tutorial 2");
            Perlin               myModule         = new Perlin();
            NoiseMap             heightMap        = new NoiseMap();
            NoiseMapBuilderPlane heightMapBuilder = new NoiseMapBuilderPlane();

            heightMapBuilder.SetSourceModule(myModule);
            heightMapBuilder.SetDestNoiseMap(heightMap);
            heightMapBuilder.SetDestSize(256, 256);
            heightMapBuilder.SetBounds(2.0, 6.0, 1.0, 5.0);
            heightMapBuilder.Build();

            RendererImage renderer = new RendererImage();
            NoiseImage    image    = new NoiseImage();

            renderer.SetSourceNoiseMap(heightMap);
            renderer.SetDestImage(image);
            renderer.Render();

            WriterBMP writer = new WriterBMP();

            writer.SetSourceImage(image);
            writer.SetDestFilename("tutorial2-1.bmp");
            writer.WriteDestFile();

            renderer.ClearGradient();
            renderer.AddGradientPoint(-1.0000, new Color(0, 0, 128, 255));    // deeps
            renderer.AddGradientPoint(-0.2500, new Color(0, 0, 255, 255));    // shallow
            renderer.AddGradientPoint(0.0000, new Color(0, 128, 255, 255));   // shore
            renderer.AddGradientPoint(0.0625, new Color(240, 240, 64, 255));  // sand
            renderer.AddGradientPoint(0.1250, new Color(32, 160, 0, 255));    // grass
            renderer.AddGradientPoint(0.3750, new Color(224, 224, 0, 255));   // dirt
            renderer.AddGradientPoint(0.7500, new Color(128, 128, 128, 255)); // rock
            renderer.AddGradientPoint(1.0000, new Color(255, 255, 255, 255)); // snow
            renderer.Render();
            writer.SetDestFilename("tutorial2-2.bmp");
            writer.WriteDestFile();

            renderer.EnableLight();
            renderer.Render();
            writer.SetDestFilename("tutorial2-3.bmp");
            writer.WriteDestFile();

            renderer.SetLightContrast(3.0); // Triple the contrast
            renderer.Render();
            writer.SetDestFilename("tutorial2-4.bmp");
            writer.WriteDestFile();

            renderer.SetLightBrightness(2.0); // Double the brightness
            renderer.Render();
            writer.SetDestFilename("tutorial2-5.bmp");
            writer.WriteDestFile();

            heightMapBuilder.SetDestSize(256 * 2, 256);
            heightMapBuilder.SetBounds(2.0, 10.0, 1.0, 5.0);
            heightMapBuilder.Build();
            renderer.Render();
            writer.SetDestFilename("tutorial2-6.bmp");
            writer.WriteDestFile();

            Console.WriteLine("End Tutorial 2");
        }