Exemple #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 terrainSelector = new Select(flatTerrain, mountainTerrain, terrainType);
        ((Select)terrainSelector).SetBounds(0.0, 1000.0);
        ((Select)terrainSelector).SetEdgeFallOff(0.125);
        IModule finalTerrain = new Turbulence(terrainSelector);
        ((Turbulence)finalTerrain).Frequency = 4.0;
        ((Turbulence)finalTerrain).Power = 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();
    }
    // 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();
    }
Exemple #3
0
    public void Generate()
    {
        if (width < 1 || depth < 1 || height < 1 || maximumHeight < 1) {
            throw new Exception ("width or depth or height or maximumHeight < 1");
        }

        Clear ();

        gridWidth = (width + 11) / 12;
        gridDepth = (depth + 11) / 12;
        gridHeight = (height + 11) / 12;

        int realWidth = gridWidth * 12;
        int realDepth = gridDepth * 12;

        float naturalScale = 1.0f / Mathf.Sqrt ((float)width * depth);

        RidgedMulti mountainTerrain = new RidgedMulti ();
        mountainTerrain.Frequency = naturalScale * scale;
        Billow baseFlatTerrain = new Billow ();
        baseFlatTerrain.Frequency = naturalScale * scale * 2.0f;
        ScaleBias flatTerrain = new ScaleBias (baseFlatTerrain, 0.125, -0.75);
        Perlin terrainType = new Perlin ();
        terrainType.Frequency = naturalScale * scale * 0.5f;
        terrainType.Persistence = 0.25;
        if (!useSeed) {
            seed = (int)(DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);
        }
        terrainType.Seed = seed;
        Select finalTerrain = new Select (flatTerrain, mountainTerrain, terrainType);
        finalTerrain.SetBounds (0.0, 1000.0);
        finalTerrain.SetEdgeFallOff (smoothness);

        NoiseMapBuilderPlane heightMapBuilder = new NoiseMapBuilderPlane (realWidth, realDepth);
        heightMapBuilder.SetBounds (0, realWidth, 0, realDepth);
        heightMapBuilder.Build (finalTerrain);

        NoiseMap noiseMap = heightMapBuilder.Map;
        float halfAmplitude = (maximumHeight - minimumHeight) * 0.5f;

        gridCenter = new Vector3 (-width * 0.5f, 0.0f, -depth * 0.5f);

        float chunkSide = 12 * VoxelEngine.instance.voxelSize;
        float halfChunkSide = chunkSide * 0.5f;

        grid = new VoxelChunk[gridHeight * gridDepth * gridWidth];
        int gridDepth_x_gridWidth = gridWidth * gridDepth;
        for (int chunkZ = 0; chunkZ < gridDepth; chunkZ++) {
            int chunkZ1 = chunkZ * gridWidth;
            int chunkDepth = chunkZ * 12;
            for (int chunkX = 0; chunkX < gridWidth; chunkX++) {
                int chunkWidth = chunkX * 12;
                for (int chunkY = 0, chunkHeight = 0; chunkY < gridHeight; chunkY++, chunkHeight += 12) {
                    Voxel[] data = new Voxel[1728]; // 20736 bytes
                    bool filled = false;
                    for (int z = 0; z < 12; z++) {
                        int currentZ = chunkDepth + z;
                        for (int x = 0; x < 12; x++) {
                            int currentX = chunkWidth + x;

                            if (currentZ >= depth || currentX >= width) {
                                FillColumns (data, (byte)1, x, z, 0);
                                continue;
                            }

                            int terrainHeight = Mathf.RoundToInt (noiseMap.GetValue (currentX, currentZ) * halfAmplitude + halfAmplitude + minimumHeight);
                            int fillHeight = Mathf.Max (0, terrainHeight - chunkHeight);
                            if (fillHeight > 0 && !filled) {
                                filled = true;
                            }
                            FillColumns (data, (byte)1, x, z, fillHeight);
                        }
                    }

                    VoxelChunk chunk;
                    if (filled) {
                        Vector3 chunkPosition = gridCenter + new Vector3 (chunkWidth * VoxelEngine.instance.voxelSize + halfChunkSide, chunkY * chunkSide + halfChunkSide, chunkDepth * VoxelEngine.instance.voxelSize + halfChunkSide);
                        chunk = BuildChunk (chunkX, chunkY, chunkZ, chunkPosition, data);
                    } else {
                        chunk = null;
                    }
                    grid [chunkY * gridDepth_x_gridWidth + chunkZ1 + chunkX] = chunk;
                }
            }
        }
    }
 private void SetTerrainHeights(IModule module)
 {
     TerrainData terData = terrain.terrainData;
     NoiseMapBuilderPlane buildPlanar = new NoiseMapBuilderPlane(terData.heightmapWidth, terData.heightmapHeight);
     buildPlanar.SetBounds(lowerXBound, upperXBound, lowerZBound, upperZBound);
     buildPlanar.Build(module);
     float[,] heights = new float[terData.heightmapWidth, terData.heightmapHeight];
     for (int z=0; z < terData.heightmapHeight; z++) {
         for (int x=0; x < terData.heightmapWidth; 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);
 }
 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();
 }
 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();
 }