Hello everyone, i want to generate realistic procedural heightmap, i use perlin noise algo for this.
But i have problem, i have a random terrain, not “realistic” with not river, sea, mountain…
import sys
from noise import pnoise2, snoise2
Xstart=0
Xend=0
for i in range(0,2):
name="./heightmap"+str(i)+".pgm"
print(name)
f = open(name, 'wt')
octaves = 10
freq = 16.0 * octaves
f.write('P2\n')
f.write('256 256\n')
f.write('255\n')
Xend=Xend+256
for y in range(0,256):
for x in range(Xstart,Xend):
f.write("%s\n" % int(snoise2(x / freq, y / freq, octaves) * 127.0 + 128.0))
f.close()
Xstart=Xstart+256
print(Xstart)
print(Xend)
print("...")
You need more then one frequency, noise in different scales and more often then not some manipulations of the noise values.
Try this:
Its a simple random terrain generator, that I once made for a level editor but never integrated it, the noise generation runs on the gpu but the idea is the same. Run it with “main.py -edit” to get a preview and some sliders to edit the shape. You may need to add parentheses to print if you’re on python3
You could modify that function, you’d need to pass the size to the base.win.make_texture_buffer() function but wouldn’t it be simpler to cut the image into pieces after making the heightmap?
Or you could change your own code, I posted this to show how one can make use of noise to make different shapes, the core of it is in the shaders/noise_f.glsl: