def create_context(): context = Context() context.set_ray_type_count(1) context['radiance_ray_type'] = np.array(0, dtype=np.uint32) context['scene_epsilon'] = np.array(1e-4, dtype=np.float32) context['output_buffer'] = Buffer.empty((height, width, 4), dtype=np.uint8, buffer_type='o', drop_last_dim=True) entry_point = EntryPoint(Program('pinhole_camera.cu', 'pinhole_camera'), Program('pinhole_camera.cu', 'exception')) cam_eye = [0.0, 0.0, 5.0] lookat = [0.0, 0.0, 0.0] up = [0.0, 1.0, 0.0] hfov = 60.0 aspect_ratio = width / height camera_u, camera_v, camera_w = calculate_camera_variables( cam_eye, lookat, up, hfov, aspect_ratio, True) context['eye'] = np.array(cam_eye, dtype=np.float32) context['U'] = np.array(camera_u, dtype=np.float32) context['V'] = np.array(camera_v, dtype=np.float32) context['W'] = np.array(camera_w, dtype=np.float32) context['bad_color'] = np.array([1.0, 0.0, 1.0], dtype=np.float32) context.set_miss_program(0, Program('constantbg.cu', 'miss')) context['bg_color'] = np.array([0.2, 0.1, 0.3], dtype=np.float32) return context, entry_point
def create_context(): context = Context() context.set_ray_type_count(1) context['radiance_ray_type'] = np.array(0, dtype=np.uint32) context['scene_epsilon'] = np.array(1e-4, dtype=np.float32) context['output_buffer'] = Buffer.empty((height, width, 4), dtype=np.uint8, buffer_type='o', drop_last_dim=True) entry_point = EntryPoint(Program('pinhole_camera.cu', 'pinhole_camera'), Program('pinhole_camera.cu', 'exception')) cam_eye = [0.0, 0.0, 5.0] lookat = [0.0, 0.0, 0.0] up = [0.0, 1.0, 0.0] hfov = 60.0 aspect_ratio = width / height camera_u, camera_v, camera_w = calculate_camera_variables(cam_eye, lookat, up, hfov, aspect_ratio, True) context['eye'] = np.array(cam_eye, dtype=np.float32) context['U'] = np.array(camera_u, dtype=np.float32) context['V'] = np.array(camera_v, dtype=np.float32) context['W'] = np.array(camera_w, dtype=np.float32) context['bad_color'] = np.array([1.0, 0.0, 1.0], dtype=np.float32) context.set_miss_program(0, Program('constantbg.cu', 'miss')) context['bg_color'] = np.array([0.2, 0.1, 0.3], dtype=np.float32) return context, entry_point
def create_context(): context = Context() context.set_ray_type_count(2) context.set_entry_point_count(1) context.set_stack_size(1800) context['scene_epsilon'] = np.array(1e-3, dtype=np.float32) context['pathtrace_ray_type'] = np.array(0, dtype=np.uint32) context['pathtrace_shadow_ray_type'] = np.array(1, dtype=np.uint32) context['rr_begin_depth'] = np.array(1, dtype=np.uint32) context['output_buffer'] = Buffer.empty((height, width, 4), dtype=np.float32, buffer_type='o', drop_last_dim=True) Program('optixPathTracer.cu', 'pathtrace_camera') entry_point = EntryPoint(Program('optixPathTracer.cu', 'pathtrace_camera'), Program('optixPathTracer.cu', 'exception'), Program('optixPathTracer.cu', 'miss')) context['sqrt_num_samples'] = np.array(2, dtype=np.uint32) context['bad_color'] = np.array([1000000., 0., 1000000.], dtype=np.float32) context['bg_color'] = np.zeros(3, dtype=np.float32) return context, entry_point
def create_context(): context = Context() context.set_ray_type_count(2) context.set_entry_point_count(1) context.set_stack_size(4640) context['max_depth'] = np.array(100, dtype=np.int32) context['radiance_ray_type'] = np.array(0, dtype=np.uint32) context['shadow_ray_type'] = np.array(1, dtype=np.uint32) context['scene_epsilon'] = np.array(1e-4, dtype=np.float32) context['importance_cutoff'] = np.array(0.01, dtype=np.float32) context['ambient_light_color'] = np.array([0.31, 0.33, 0.28], dtype=np.float32) context['output_buffer'] = Buffer.empty((height, width, 4), dtype=np.uint8, buffer_type='o', drop_last_dim=True) # Ray generation program camera_name = "env_camera" if tutorial_number >= 11 else "pinhole_camera" ray_generation_program = Program(tutorial_file, camera_name) # Exception program exception_program = Program(tutorial_file, "exception") # Miss program miss_name = "envmap_miss" if tutorial_number >= 5 else "miss" miss_program = Program(tutorial_file, miss_name) entry_point = EntryPoint(ray_generation_program, exception_program, miss_program) context['sqrt_num_samples'] = np.array(2, dtype=np.uint32) context['bad_color'] = np.array([1., 1., 1.], dtype=np.float32) context['bg_color'] = np.array([0.34, 0.55, 0.85], dtype=np.float32) hdr_image = load_hdr("../data/CedarCity.hdr") hdr_image = np.flip(hdr_image, axis=0) texture = np.zeros((hdr_image.shape[0], hdr_image.shape[1], 4), np.float32) texture[:, :, :3] = hdr_image tex_buffer = Buffer.from_array(texture, buffer_type='i', drop_last_dim=True) tex_sampler = TextureSampler(tex_buffer, wrap_mode='repeat', indexing_mode='normalized_coordinates', read_mode='normalized_float', filter_mode='linear') context['envmap'] = tex_sampler noise = np.random.uniform(0, 1, 64*64*64).astype(np.float32) tex_buffer = Buffer.from_array(noise.reshape(64, 64, 64), buffer_type='i', drop_last_dim=False) noise_sampler = TextureSampler(tex_buffer, wrap_mode='repeat', indexing_mode='normalized_coordinates', read_mode='normalized_float', filter_mode='linear') context["noise_texture"] = noise_sampler return context, entry_point
def create_context(): context = Context() context.set_ray_type_count(2) context.set_entry_point_count(1) context.set_stack_size(1800) context['scene_epsilon'] = np.array(1e-4, dtype=np.float32) context['radiance_ray_type'] = np.array(0, dtype=np.uint32) context['shadow_ray_type'] = np.array(1, dtype=np.uint32) context['output_buffer'] = Buffer.empty((height, width, 4), dtype=np.uint8, buffer_type='o', drop_last_dim=True) entry_point = EntryPoint(Program('pinhole_camera.cu', 'pinhole_camera'), Program('pinhole_camera.cu', 'exception'), Program('constantbg.cu', 'miss')) context['bad_color'] = np.array([1., 0., 1.], dtype=np.float32) context['bg_color'] = np.array([0.34, 0.55, 0.85], dtype=np.float32) return context, entry_point
def create_context(): context = Context() context.set_ray_type_count(2) context.set_stack_size(1200) context.set_print_enabled(True) context.set_all_exceptions_enabled(True) # here pyoptix won't be able to deduce types of these variables, # so we must put them inside numpy arrays with proper dtypes context['max_depth'] = np.array(5, dtype=np.int32) context['radiance_ray_type'] = np.array(0, dtype=np.uint32) context['shadow_ray_type'] = np.array(1, dtype=np.uint32) context['scene_epsilon'] = np.array(1e-4, dtype=np.float32) context['output_buffer'] = Buffer.empty((height, width, 4), dtype=np.uint8, buffer_type='o', drop_last_dim=True) cam_eye = [2.0, 1.5, -2.0] lookat = [0.0, 1.2, 0.0] up = [0.0, 1.0, 0.0] hfov = 60.0 aspect_ratio = width / height camera_u, camera_v, camera_w = calculate_camera_variables( cam_eye, lookat, up, hfov, aspect_ratio) context['eye'] = np.array(cam_eye, dtype=np.float32) context['U'] = np.array(camera_u, dtype=np.float32) context['V'] = np.array(camera_v, dtype=np.float32) context['W'] = np.array(camera_w, dtype=np.float32) ray_gen_program = Program('pinhole_camera.cu', 'pinhole_camera') exception_program = Program('pinhole_camera.cu', 'exception') entry_point = EntryPoint(ray_gen_program, exception_program) context['bad_color'] = np.array([0, 1, 1], dtype=np.float32) context.set_miss_program(0, Program('constantbg.cu', 'miss')) context['bg_color'] = np.array([0.4, 0.33, 0.21], dtype=np.float32) return context, entry_point
def main(): tex_width = 64 tex_height = 64 trace_width = 512 trace_height = 384 context = Context() tex_data = [] for j in range(tex_height): tex_data.append([]) for i in range(tex_width): tex_data[j].append([(i + j) / (tex_width + tex_height) * 255, i / tex_width * 255, j / tex_height * 255, 255]) tex_buffer = Buffer.from_array(np.array(tex_data, dtype=np.uint8), buffer_type='i', drop_last_dim=True) tex_sampler = TextureSampler(tex_buffer, wrap_mode='clamp_to_edge', indexing_mode='normalized_coordinates', read_mode='normalized_float', filter_mode='linear') context['input_texture'] = tex_sampler context['result_buffer'] = Buffer.empty((trace_height, trace_width, 4), dtype=np.float32, buffer_type='o', drop_last_dim=True) entry_point = EntryPoint(Program('draw_texture.cu', 'draw_texture'), Program('draw_texture.cu', 'exception')) entry_point.launch((trace_width, trace_height)) result_array = context['result_buffer'].to_array() result_array *= 255 result_array = result_array.astype(np.uint8) result_image = Image.fromarray(result_array) ImageWindow(result_image)
def main(): width = 512 height = 384 context = Context() context.set_ray_type_count(1) context['result_buffer'] = Buffer.empty((height, width, 4), buffer_type='o', dtype=np.float32, drop_last_dim=True) ray_gen_program = Program('draw_color.cu', 'draw_solid_color') ray_gen_program['draw_color'] = np.array([0.462, 0.725, 0.0], dtype=np.float32) entry_point = EntryPoint(ray_gen_program) entry_point.launch(size=(width, height)) result_array = context['result_buffer'].to_array() result_array *= 255 result_image = Image.fromarray(result_array.astype(np.uint8)[:, :, :3]) ImageWindow(result_image)
def create_context(): context = Context() context.set_ray_type_count(2) context.set_stack_size(1200) context.set_print_enabled(True) context.set_all_exceptions_enabled(True) # here pyoptix won't be able to deduce types of these variables, # so we must put them inside numpy arrays with proper dtypes context['max_depth'] = np.array(5, dtype=np.int32) context['radiance_ray_type'] = np.array(0, dtype=np.uint32) context['shadow_ray_type'] = np.array(1, dtype=np.uint32) context['scene_epsilon'] = np.array(1e-4, dtype=np.float32) context['output_buffer'] = Buffer.empty((height, width, 4), dtype=np.uint8, buffer_type='o', drop_last_dim=True) cam_eye = [2.0, 1.5, -2.0] lookat = [0.0, 1.2, 0.0] up = [0.0, 1.0, 0.0] hfov = 60.0 aspect_ratio = width / height camera_u, camera_v, camera_w = calculate_camera_variables(cam_eye, lookat, up, hfov, aspect_ratio) context['eye'] = np.array(cam_eye, dtype=np.float32) context['U'] = np.array(camera_u, dtype=np.float32) context['V'] = np.array(camera_v, dtype=np.float32) context['W'] = np.array(camera_w, dtype=np.float32) ray_gen_program = Program('pinhole_camera.cu', 'pinhole_camera') exception_program = Program('pinhole_camera.cu', 'exception') entry_point = EntryPoint(ray_gen_program, exception_program) context['bad_color'] = np.array([0, 1, 1], dtype=np.float32) context.set_miss_program(0, Program('constantbg.cu', 'miss')) context['bg_color'] = np.array([0.4, 0.33, 0.21], dtype=np.float32) return context, entry_point
def main(): tex_width = 64 tex_height = 64 trace_width = 512 trace_height = 384 context = Context() tex_data = [] for j in range(tex_height): tex_data.append([]) for i in range(tex_width): tex_data[j].append([ (i + j) / (tex_width + tex_height) * 255, i / tex_width * 255, j / tex_height * 255, 255 ]) tex_buffer = Buffer.from_array(np.array(tex_data, dtype=np.uint8), buffer_type='i', drop_last_dim=True) tex_sampler = TextureSampler(tex_buffer, wrap_mode='clamp_to_edge', indexing_mode='normalized_coordinates', read_mode='normalized_float', filter_mode='linear') context['input_texture'] = tex_sampler context['result_buffer'] = Buffer.empty((trace_height, trace_width, 4), dtype=np.float32, buffer_type='o', drop_last_dim=True) entry_point = EntryPoint(Program('draw_texture.cu', 'draw_texture'), Program('draw_texture.cu', 'exception')) entry_point.launch((trace_width, trace_height)) result_array = context['result_buffer'].to_array() result_array *= 255 result_array = result_array.astype(np.uint8) result_image = Image.fromarray(result_array) ImageWindow(result_image)
def main(): width = 512 height = 384 context = Context() context.set_ray_type_count(1) context['output_buffer'] = Buffer.empty((height, width, 4), buffer_type='o', dtype=np.float32, drop_last_dim=True) ray_gen_program = Program('draw_color.cu', 'draw_solid_color') ray_gen_program['draw_color'] = np.array([0.462, 0.725, 0.0], dtype=np.float32) entry_point = EntryPoint(ray_gen_program) entry_point.launch(size=(width, height)) window = ImageWindowBase(context, width, height) window.run()