height = hmap[x, y] z_max = int(max(min(height + 8, 32), 0)) for z in range(32): voxel = chunk_array.get_voxel(x, y, z) voxel['flags'] = 0 if z_max < z else 1""" chunk_array.upload_buffers() buffer = pyopencl.Buffer(ctx, pyopencl.mem_flags.READ_ONLY|pyopencl.mem_flags.COPY_HOST_PTR, hostbuf = ihmap) #pyopencl.enqueue_copy(queue, buffer, hmap) heightmap_kernel(queue, (255, 255, 32), None, chunk_array.array_buffer._d_buffer, buffer) pyopencl.enqueue_copy(queue, chunk_array.voxel_data.level_buffers[0]._h_buffer, chunk_array.voxel_data.level_buffers[0]._d_buffer) chunk_array.upload_buffers() if __name__ == '__main__': from world.generate.diamondsquaregenerator import DiamondSquareGenerator from world.generate.perlinnoisegenerator import PerlinNoiseGenerator gen = DiamondSquareGenerator({ 'widthlog2': 8, 'roughness': 1, 'factor': 0.6 }) gen = PerlinNoiseGenerator({ 'widthlog2': 8 }) numpy.set_printoptions(threshold=100, linewidth=32 * 10, precision=1, ) hmap = gen._generate_hmap() import pygame surface = pygame.display.set_mode((256*3, 256*3)) for x in range(256): for y in range(256): pygame.draw.rect(surface, (int(max(min((hmap[x, y]+2)*80, 255), 0)),)*3, [x*3, y*3, x*3+3, y*3+3]) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False
import time import transformations import cmath import sys from world.generate.diamondsquaregenerator import DiamondSquareGenerator from world.generate.perlinnoisegenerator import PerlinNoiseGenerator if __name__ == '__main__': platform = pyopencl.get_platforms() my_gpu_devices = platform[0].get_devices(device_type=pyopencl.device_type.CPU) ctx = pyopencl.Context(devices=my_gpu_devices) print(ctx.devices[0].max_compute_units) queue = pyopencl.CommandQueue(ctx) scene = Scene(ctx, queue) gen = DiamondSquareGenerator({ 'widthlog2': 8, 'roughness': 1, 'factor': 0.6 }) #gen = PerlinNoiseGenerator({ 'widthlog2': 8, 'freq': 32, 'steps': 4, 'amplitude_factor': 1 }) gen.generate(scene._chunk_array, ctx, queue, scene.raytrace_pgrm.write_height_map) sphere = scene.create_object("sphere", position=(2,0,0), radius=2) #cube = scene.create_object("aacube", position=(0,0,0,0), width=6) scene.create_object("sphere", position=(-4,0,0), radius=1) scene.create_object("aacube", position=(-4,0,-5), width=1) scene.create_object("aacube", position=(-2, 0, 0), width=1.5) scene.create_object("aacube", position=(-2, 0, -5), width=1.5) scene.create_object("aacube", position=(-10, 3, -10), width=15) light = scene.create_light("directional", direction=(1,1,1), color=(1,1,1)) #scene.create_light("directional", direction=(1,1,1), color=(1,1,1)) size = (800, 600)