def set_cycles_renderer(scene: bpy.types.Scene, camera_object: bpy.types.Object, num_samples: int, use_denoising: bool = True, use_motion_blur: bool = False, use_transparent_bg: bool = False) -> None: scene.camera = camera_object scene.render.image_settings.file_format = 'PNG' scene.render.engine = 'CYCLES' scene.render.use_motion_blur = use_motion_blur scene.render.film_transparent = use_transparent_bg scene.view_layers[0].cycles.use_denoising = use_denoising scene.cycles.samples = num_samples
def set_cycles_renderer(scene: bpy.types.Scene, camera_object: bpy.types.Object, num_samples: int, use_denoising: bool = True, use_motion_blur: bool = False, use_transparent_bg: bool = False, prefer_cuda_use: bool = True, use_adaptive_sampling: bool = False) -> None: scene.camera = camera_object scene.render.image_settings.file_format = 'PNG' scene.render.engine = 'CYCLES' scene.render.use_motion_blur = use_motion_blur scene.render.film_transparent = use_transparent_bg scene.view_layers[0].cycles.use_denoising = use_denoising scene.cycles.use_adaptive_sampling = use_adaptive_sampling scene.cycles.samples = num_samples # Enable GPU acceleration # Source - https://blender.stackexchange.com/a/196702 if prefer_cuda_use: bpy.context.scene.cycles.device = "GPU" # Change the preference setting bpy.context.preferences.addons[ "cycles"].preferences.compute_device_type = "CUDA" # Call get_devices() to let Blender detects GPU device (if any) bpy.context.preferences.addons["cycles"].preferences.get_devices() # Let Blender use all available devices, include GPU and CPU for d in bpy.context.preferences.addons["cycles"].preferences.devices: d["use"] = 1 # Display the devices to be used for rendering print("----") print("The following devices will be used for path tracing:") for d in bpy.context.preferences.addons["cycles"].preferences.devices: print("- {}".format(d["name"])) print("----")
def set_cycles_renderer(scene: bpy.types.Scene, resolution_percentage: int, output_file_path: str, camera_object: bpy.types.Object, num_samples: int, use_denoising: bool = True, use_motion_blur: bool = False, use_transparent_bg: bool = False) -> None: scene.camera = camera_object scene.render.image_settings.file_format = 'PNG' scene.render.resolution_percentage = resolution_percentage scene.render.engine = 'CYCLES' scene.render.filepath = output_file_path scene.render.use_motion_blur = use_motion_blur if bpy.app.version >= (2, 80, 0): scene.render.film_transparent = use_transparent_bg scene.view_layers[0].cycles.use_denoising = use_denoising else: scene.cycles.film_transparent = use_transparent_bg scene.render.layers[0].cycles.use_denoising = use_denoising scene.cycles.samples = num_samples