Back to Blog
Terragen heightmap7/13/2023 Tldr: I would use a perlin noise generation with some tacked on biomes. Here is an image of the generation, and the generation code is in the Github project: What is my best option for generating a height map if I have square tiles to give some realism, not very resource intensive, and keep the code I have? The diamond square algorithm probably isn't going to work for my needs because I would like to be flexible in sizing. I am not sure about using a noise function just due to the fact that I would need to generate biomes within a continent to make it look realistic (A continent with just mountains would be unrealistic). Right now I am generating plates through my flood fill, but I am not sure where to go from there. I have seen the following methods attempted to make heightmaps: At this point I have a flood fill that works perfectly, however if I want to add any sort of realism I will need to add in height variables. The mesh will be created in the constructor of the HeightMapMesh class, which is defined like this.I am having troubles finding out the best way to add realism to a terrain generator. At the end, the terrain will be contained in a cube in the range, and. These parameters are not constant because we may want to change them at run time, independently of the scaling applied. Regarding y axis, we will set up two parameters, minY and maxY, for setting the lowest and highest value that the y coordinate can have. , that is, for the z axis.ĭon't worry too much about those values, later on the resulting mesh can be scaled to accommodate its size in the world.The mesh will be formed by a set of vertices (one per pixel) whose x and z coordinates will be in the range following range: Private static final float STARTZ = - 0.5f The next constants are: private static final float STARTX = - 0.5f We will choose the second approach so we are not limited to greyscale images. This may be enough precision for you, but if it’s not we can use the three RGB components to have more intermediate values, in this case the height can be calculated form a range that gets from 0 0 0 to 2 5 5 3 255^ 2 5 5 3 . Images are usually greyscale, for a PNG image that means that each RGB component for each pixel can vary from 0 0 0 to 2 5 5 255 2 5 5, so we have 2 5 6 256 2 5 6 discrete values to define different heights. Let’s first review the constants defined for that class: private static final int MAX_COLOUR = 255 * 255 * 255 Īs we have explained above, we will calculate the height of each vertex based on the colour of each pixel of the image used as height map. We will create a class named HeightMapMesh that will create a Mesh based on a height map image performing the steps described above. Set up the indices to draw the triangles associated to the vertex.Assign the correct texture coordinate to the vertex.
0 Comments
Read More
Leave a Reply. |