Skip to main content

C# Produceral Terrain Generation 1

New Project:


- Generate random terain with noise
- user input to get certain structures
- use fractals to get more nature-like structures
- use erosion to get even more accurate results
- use weather to get biomes and direct erosion
- export to heightmap
- export to .obj

By designable i mean that if you need a big mountain in the middle for example, you can give the data and it generates a random terrain, but with the mountain(aslo random) always present in the right place, so you can have random terrain and design so the game doesnt break.

I making heighmaps now.
the engine can produce maps in 24 bit. red is low green is mid and blue is high. there are around 16m heights. if you see lots of red, it still can me a big number on that pixel, because the blue is low and red is high, but blue counts more as 10000 is more than 10. so visualy it can be weird but evertthing is right example: RGB(234, 2, 4) this will result in a red color. though because of the blue part of 4 this is a large number: 1001011101010 = 4842 now RGB(240, 0 ,0) will look similar but its only worth 240. same with black. now the engine can do these things:

- Create a map
- copy a map. 
- print a map
- save a map as 24bit image

- average maps
- add maps
- subtract maps
- multiply maps
- divide maps

- make random noise
- cubic smooth  maps
- round smooth maps
- make a bulbs/hills from points with a diffrence function(hill noise, my invention :D)


random noise

noise with min and max defined

cubic smooth of  noise

1 iterartion of smoothing

2 iterations of smoothing

a hill made by my hill algorithm

2 hills made with my algorithm.
points can me chosen, so here is the design part


public void make128intermap(ref int[,] m,int max, int p1x, int p1y, int p2x, int p2y,int stencilsize)
            for (int x = 0; x < 128; x++)
                for (int y = 0; y < 128; y++)
                    int x1d = System.Math.Abs(x - p1x);
                    int y1d = System.Math.Abs(y - p1y);
                    float dist1 = (float)System.Math.Sqrt(x1d * x1d + y1d * y1d);
                    int x2d = System.Math.Abs(x - p2x);
                    int y2d = System.Math.Abs(y - p2y);
                    float dist2 = (float)System.Math.Sqrt(x2d * x2d + y2d * y2d);
                    float temp1 = max / dist1 / (100/stencilsize);
                    float temp2 = max / dist2 / (100/ stencilsize);
                    m[x, y] = (int)(temp1 + temp2);

quite simple he

now get some maps added:
very un-agressive noise (max = max pixel number / 1200)added to a hill map which was made stronger by adding it to its self.

DONE: Get some good stuff to begin with.
TODO: get perlin noise, and nice fractals with DLA to get lightning like structures to make rivers and mountains.

Cody Bloemhard

[tag: c#] [tag: OpenGL] [tag: Tortoise2D Engine] [tag: 2D] [tag: Game Engine] [tag: ocdy1001] [tag: ocdy1001official] [tag: Unity] [tag: Unity3D] [tag: Unity5] [tag: 3D] [tag: Cody Bloemhard]


Popular posts from this blog

Neural Network 0: handwriting learner and sin(x)

Here is a project from a while ago, it recognises characters:

This is the network class:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;publicclass NeuralNetwork {publicdouble learnRate;publicdouble momentum;public List<Neuron> inputLayer;public List<Neuron> hiddenLayer;public List<Neuron> outputLayer;static Random random =new Random();public NeuralNetwork(int inputSize,int hiddenSize,int outputSize,string file =""){ learnRate =.9d; momentum =.04d; inputLayer =new List<Neuron>(); hiddenLayer =new List<Neuron>(); outputLayer =new List<Neuron>();for(int i =0; i < inputSize; i++) inputLayer.Add(new Neuron());for(int i =0; i < hiddenSize; i++) hiddenLayer.Add(new Neuron(inputLayer));for(int i =0; i < outputSize; i++) outputLayer.Add(new Neuron(hiddenLayer));if(file !=…

C# produceral terrain generation 3

I have been working on a raindrop algorithm for erosion on the heighmap. firstit went wrong: spikes is not what you want
The better version uses 150 * 150 * 150 * 8  raindrops for a total of 27M drops. this takes 8000 milli seconds on one core(3.8ghz). Second try, not very good On the third try a river was created naturally. this is more promising.
here is a Fault-terrain that was "raindropped" and smoothed and i added small detail noise. Again a rivver. i add some materials and a water plane for fun. doesnt look too bad.

Here i am experimenting with parameters in the raindrop function.
DONE: Get basic raindrop erosion setup TODO: tweak till i get decent and realistic results.
Cody Bloemhard [tag: c#] [tag: OpenGL] [tag: Tortoise2D Engine] [tag: 2D] [tag: Game Engine] [tag: ocdy1001] [tag: ocdy1001official] [tag: Unity] [tag: Unity3D] [tag: Unity5] [tag: 3D] [tag: Cody Bloemhard]