def main(): # 1) Render and shader settings: w, h = 1000, 1000 amb, lamb, refl, refl_depth = 0.0, 0.6, 0.3, 2 aliasing = True # 2) Generate scene: scene = Scene.default_scene() spheres_host, light_host, planes_host = scene.generate_scene() # Send the data arrays to GPU memory: spheres = cuda.to_device(spheres_host) lights = cuda.to_device(light_host) planes = cuda.to_device(planes_host) # 3) Set up camera and rays camera = Camera(resolution=(w, h), position=[-2, 0, 2.0], euler=[0, -30, 0]) # Send the camera data to GPU memory: camera_origin = cuda.to_device(camera.position) camera_rotation = cuda.to_device(camera.rotation) pixel_loc = cuda.to_device(camera.generate_pixel_locations()) # 4) Memory Allocation for the result: result = cuda.to_device(np.zeros((3, w, h), dtype=np.uint8)) # 5) Setup the cuda kernel grid: threadsperblock = (16, 16) blockspergrid_x = int(np.ceil(result.shape[1] / threadsperblock[0])) blockspergrid_y = int(np.ceil(result.shape[2] / threadsperblock[1])) blockspergrid = (blockspergrid_x, blockspergrid_y) # 6) Call JIT compiled renderer: render[blockspergrid, threadsperblock](pixel_loc, result, camera_origin, camera_rotation, spheres, lights, planes, amb, lamb, refl, refl_depth, aliasing) import time st = time.time() render[blockspergrid, threadsperblock](pixel_loc, result, camera_origin, camera_rotation, spheres, lights, planes, amb, lamb, refl, refl_depth + 2, aliasing) et = time.time() print(f"time: {1000 * (et - st):,.1f} ms") # 7) Present the result as a .png result = result.copy_to_host() image = convert_array_to_image(result) image.save('../output/test_sampled_highres_utlra_aliasing_testing.png') return 0
def test_render(self): renderer = LuxRenderer(samples_per_pixel=1000) scene = Scene() scene.camera = Camera(loc=(0, -10, 0), to=(0, 0, 0)) scene.objects.append(Sphere()) scene.objects.append( Sphere(center=(1, -1, 0.5), radius=0.5, light=AreaLight(color=(1, 1, 1)))) renderer.render(scene, generate_only=True)
def set_camera(self): Camera.move_to(self.controllable_entities[0].tile.pos) Camera.offset_y = self.controllable_entities[0].y
def main(args): # mkdir(os.path.abspath(OUTPUT)) # Create output dir out_dir = os.getcwd().replace("\\", "/") + OUTPUT try: # LOG.debug("Setting up folder {}".format(dst_dir)) os.makedirs(out_dir, exist_ok=True) except Exception as e: print(e) # Assets assets = os.getcwd().replace("\\", "/") + ASSETS if not os.path.exists(assets): print("No valid assets folder provided.") # envmaps = os.path.join(assets, "envmaps.txt") textures = os.path.join(assets, "textures.txt") # models = os.path.join(assets, "models.txt") # envmaps = load_from_filelist(envmaps) textures = load_from_filelist(textures) # models = load_from_filelist(models) print("Assets in:" + ASSETS) # LOG.debug(" - %d envmaps" % len(self.envmaps)) print(" - %d textures" % len(textures)) # LOG.debug(" - %d models" % len(self.models)) # file_name = secrets.token_urlsafe(8) file_name = "1kpVZww7_S8" if os.path.exists(out_dir + f"/{file_name}.pbrt"): os.remove(out_dir + f"/{file_name}.pbrt") # Create random scene name if args.output is None: args.output = file_name if (args.topng): args.output += ".png" else: args.output += ".exr" #Init random camera cam = sample_camera() dist = np.linalg.norm(np.array(cam["position"]) - np.array([0, 0, -1])) cam["focaldistance"] = dist camera = Camera(**cam) material_list = [] geometry_list = [] light_list = [] obj = geometry.Sphere(radius=0.5) xforms.translate(obj, [0, 0, -1]) mat = materials.UberMaterial(id="diff", diffuse=[0.1, 0.3, 0.9]) # mat = materials.MirrorMaterial(id="Mirror") obj.assign_material(mat) #Motion blur on sphere radius = 1 mvec_r = np.random.uniform(0.00, 2) * radius mvec_dir = np.random.uniform(size=(3, )) mvec_dir /= np.linalg.norm(mvec_dir) mvec = mvec_dir * mvec_r xforms.translate(obj, mvec, target="end") geometry_list.append(obj) material_list.append(mat) obj = geometry.Plane(scale=15) xforms.translate(obj, [0, -1, -2]) # tex = texture.Checkerboard("check", "spectrum", uscale=8, vscale=8, tex1=[0.1]*3, tex2=[0.8]*3) tex = matrandomizers.random_texture(textures) mat = materials.MatteMaterial(id="checkers", diffuse_texture=tex) obj.assign_material(mat) geometry_list.append(obj) material_list.append(mat) obj = geometry.Plane(scale=4) xforms.rotate(obj, [1, 0, 0], 90) xforms.translate(obj, [0, 0, -5]) # tex = texture.Checkerboard("check", "spectrum", uscale=8, vscale=8, tex1=[0.1]*3, tex2=[0.8]*3) mat = mat = materials.MirrorMaterial(id="Mirror") obj.assign_material(mat) geometry_list.append(obj) material_list.append(mat) pbrt = create_pbrt(args, camera, out_dir, material_list, geometry_list, light_list) f = open(out_dir + f"/{file_name}.pbrt", "a") f.write(pbrt) f.close()
def render_scene_with_plane(): floor = Plane() floor.set_transform(scaling(10, 0.01, 10)) # floor.set_transform( # multiply_matrix(translation(0, 0.33, 0), scaling(10, 0.01, 10))) floor.material = Material() floor.material.color = color(1, 0.9, 0.9) floor.material.specular = 0 # left_wall = Plane() # left_wall.set_transform( # multiply_matrix( # translation(0, 0, 5), # multiply_matrix(rotation_y(-pi / 4), # multiply_matrix(rotation_x(pi / 2), scaling(10, 0.01, 10))))) # left_wall.material = floor.material # right_wall = Plane() # right_wall.set_transform( # multiply_matrix( # translation(0, 0, 5), # multiply_matrix(rotation_y(pi / 4), # multiply_matrix(rotation_x(pi / 2), scaling(10, 0.01, 10))))) middle = Sphere() middle.set_transform(translation(-0.5, 1, 0.5)) middle.material = Material() middle.material.pattern = StripePattern(color(0.6, 1.0, 0.6), color(0.3, 0.6, 0.3)) middle.material.color = color(0.1, 1, 0.5) middle.material.diffuse = 0.7 middle.material.specular = 0.3 middle.material.pattern.set_transform( multiply_matrix(scaling(0.2, 0.2, 0.2), rotation_y(pi / 4))) right = Sphere() right.set_transform( multiply_matrix(translation(1.5, 0.5, -0.5), scaling(0.5, 0.5, 0.5))) right.material = Material() right.material.color = color(0.5, 1, 0.1) # right.material.diffuse = 0.7 right.material.diffuse = 0.2 right.material.specular = 0.3 right.material.reflective = 0.7 left = Sphere() left.set_transform( multiply_matrix(translation(-1.5, 0.33, -0.75), scaling(0.33, 0.33, 0.33))) left.material = Material() left.material.color = color(1, 0.8, 0.1) left.material.diffuse = 0.7 left.material.specular = 0.3 world = World() world.add_light(PointLight(point(-10, 10, -10), color(1, 1, 1))) world.objects.append(floor) # world.objects.append(left_wall) # world.objects.append(right_wall) world.objects.append(middle) world.objects.append(right) world.objects.append(left) camera = Camera(600, 500, pi / 3) camera.set_transform( view_transform(point(0, 1.5, -5), point(0, 1, 0), vector(0, 1, 0))) # camera.set_transform( # view_transform(point(0, 4, -1), point(0, 1, 0), vector(0, 1, 0))) canvas = RayTracer().render(camera, world) ppm = canvas.to_ppm() outf = open('render_scene_with_plane.ppm', 'w') outf.write(ppm)
def step_create_camera_c(context, hsize, vsize): context.c = Camera(hsize, vsize, pi / 2)
def step_create_camera_c_from_yaml(context): context.c = Camera.from_yaml(context.data)
def render_simple_scene(): floor = Sphere() floor.set_transform(scaling(10, 0.01, 10)) floor.material = Material() floor.material.color = color(1, 0.9, 0.9) floor.material.specular = 0 left_wall = Sphere() left_wall.set_transform( multiply_matrix( translation(0, 0, 5), multiply_matrix( rotation_y(-pi / 4), multiply_matrix(rotation_x(pi / 2), scaling(10, 0.01, 10))))) left_wall.material = floor.material right_wall = Sphere() right_wall.set_transform( multiply_matrix( translation(0, 0, 5), multiply_matrix( rotation_y(pi / 4), multiply_matrix(rotation_x(pi / 2), scaling(10, 0.01, 10))))) right_wall.material = floor.material middle = Sphere() middle.set_transform(translation(-0.5, 1, 0.5)) middle.material = Material() middle.material.color = color(0.1, 1, 0.5) middle.material.diffuse = 0.7 middle.material.specular = 0.3 right = Sphere() right.set_transform( multiply_matrix(translation(1.5, 0.5, -0.5), scaling(0.5, 0.5, 0.5))) right.material = Material() right.material.color = color(0.5, 1, 0.1) right.material.diffuse = 0.7 right.material.specular = 0.3 left = Sphere() left.set_transform( multiply_matrix(translation(-1.5, 0.33, -0.75), scaling(0.33, 0.33, 0.33))) left.material = Material() left.material.color = color(1, 0.8, 0.1) left.material.diffuse = 0.7 left.material.specular = 0.3 world = World() world.add_light(PointLight(point(-10, 10, -10), color(1, 1, 1))) world.objects.append(floor) world.objects.append(left_wall) world.objects.append(right_wall) world.objects.append(middle) world.objects.append(right) world.objects.append(left) camera = Camera(600, 500, pi / 3) camera.set_transform( view_transform(point(0, 1.5, -5), point(0, 1, 0), vector(0, 1, 0))) canvas = RayTracer().render(camera, world) with open('render_simple_scene.ppm', 'w') as out_file: out_file.write(canvas.to_ppm())