def prepare_scene(): """ Prepare the rendering scene including setting the render engine, sample ratio and color management """ reset_blend() scene=bpy.data.scenes['Scene'] scene.render.engine='CYCLES' avail_devices = _cycles.available_devices('CUDA') print(avail_devices) prop = bpy.context.preferences.addons['cycles'].preferences prop.get_devices(prop.compute_device_type) prop.compute_device_type = 'CUDA' for device in prop.devices: if device.type == 'CUDA': print('device: ', device) device.use = True scene.cycles.samples=128 scene.cycles.use_square_samples=False scene.display_settings.display_device='sRGB' if random.random() > 0.4: scene.view_settings.view_transform='Filmic' else: scene.view_settings.view_transform='Standard' return
def get_devices(self): import _cycles # Layout of the device tuples: (Name, Type, Persistent ID) device_list = _cycles.available_devices() cuda_devices = [] opencl_devices = [] for device in device_list: if not device[1] in {'CUDA', 'OPENCL'}: continue entry = None # Try to find existing Device entry for dev in self.devices: if dev.id == device[2] and dev.type == device[1]: entry = dev break # Create new entry if no existing one was found if not entry: entry = self.devices.add() entry.id = device[2] entry.name = device[0] entry.type = device[1] # Sort entries into lists if entry.type == 'CUDA': cuda_devices.append(entry) elif entry.type == 'OPENCL': opencl_devices.append(entry) return cuda_devices, opencl_devices
def get_num_gpu_devices(self): import _cycles device_list = _cycles.available_devices() num = 0 for device in device_list: if device[1] != self.compute_device_type: continue for dev in self.devices: if dev.use and dev.id == device[2]: num += 1 return num
def setToGPU(): print('threads: ', bpy.data.scenes["Scene"].render.threads) print('cycles available devices: ', _cycles.available_devices()) print('compute_device: ', bpy.context.user_preferences.system.bl_rna.properties['compute_device'].enum_items.keys()) print('before changing settings: ', bpy.context.scene.cycles.device) bpy.data.scenes['Scene'].cycles.samples=20 bpy.data.scenes["Scene"].render.tile_x=256 bpy.data.scenes["Scene"].render.tile_y=256 bpy.data.scenes['Scene'].cycles.max_bounces=5 bpy.data.scenes['Scene'].cycles.caustics_reflective=False bpy.data.scenes['Scene'].cycles.caustics_refractive=False print('max bounces: ', bpy.data.scenes['Scene'].cycles.max_bounces) print('Samples: ', bpy.data.scenes['Scene'].cycles.samples) bpy.data.scenes["Scene"].render.engine='CYCLES' bpy.context.user_preferences.system.compute_device_type = 'CUDA' # bpy.context.user_preferences.system.compute_device = 'CUDA_0' bpy.context.scene.cycles.device = 'GPU' bpy.context.scene.render.engine = 'CYCLES' bpy.context.user_preferences.system.compute_device_type = 'CUDA' bpy.data.scenes["Scene"].cycles.device='GPU' print('after changing settings: ', bpy.context.scene.cycles.device)
def get_devices(self, compute_device_type=''): import _cycles # Layout of the device tuples: (Name, Type, Persistent ID) device_list = _cycles.available_devices(compute_device_type) # Make sure device entries are up to date and not referenced before # we know we don't add new devices. This way we guarantee to not # hold pointers to a resized array. self.update_device_entries(device_list) # Sort entries into lists cuda_devices = [] opencl_devices = [] cpu_devices = [] for device in device_list: entry = self.find_existing_device_entry(device) if entry.type == 'CUDA': cuda_devices.append(entry) elif entry.type == 'OPENCL': opencl_devices.append(entry) elif entry.type == 'CPU': cpu_devices.append(entry) # Extend all GPU devices with CPU. cuda_devices.extend(cpu_devices) opencl_devices.extend(cpu_devices) return cuda_devices, opencl_devices
def available_devices(): import _cycles return _cycles.available_devices()
import bpy, _cycles print(_cycles.available_devices()) import bpy bpy.context.user_preferences.addons[ 'cycles'].preferences.compute_device_type = 'CUDA' bpy.context.user_preferences.addons[ 'cycles'].preferences.compute_device = 'xxxxxx'
-o, --render-output -E, --engine LINKS: https://www.blenderguru.com/articles/4-easy-ways-to-speed-up-cycles http://www.dalaifelinto.com/?p=746 ''' import os import sys import bpy, _cycles from bpy_extras.image_utils import load_image # FORCE GPU # https://blenderartists.org/t/blender-2-8-amazon-aws-ec2-cycles-gpu/1156408/3 avail_devices = _cycles.available_devices('CUDA') print('Devices: ', avail_devices) prop = bpy.context.preferences.addons['cycles'].preferences prop.get_devices(prop.compute_device_type) prop.compute_device_type = 'CUDA' for device in prop.devices: if device.type == 'CUDA': print('device: ', device) device.use = True def run():
def blender_init(render_engine='BLENDER', resolution=[537, 244], fov=[2.93, 2.235], focal_length=167.35, asteroid_name='itokawa_low'): r"""Initialize the Blender scene for a camera around an asteroid This function will initialize the objects for a scene involving a camera, asteroid, and light source Parameters ---------- render_engine : string Option to choose the type of rendering engine 'BLENDER' - Default Blender render - fast 'CYCLES' - Better rendering at the expense of speed/computation resolution : list or array_like The x,y pixel resolution of the resulting output image. The default matches the MSI camera on NEAR fov : list or array_like Field of View of the camera sensor in degrees - default is chosen to math NEAR focal_length : float Focal length of camera in millimeters Returns ------- camera : Blender camera Camera which lets you set camera properties camera_obj : Blender object Camera object - move it/rotation lamp : Blender Lamp Use to set lamp specific properties lamp_obj : Blender object Use to move and position itokawa_obj : Blender object Asteroid object scene : Blender scene Use to set general parameters for rendering See Also -------- blender_example : Example for rendering an image Author ------ Shankar Kulumani GWU [email protected] """ # setup the scene bpy.ops.wm.read_homefile() # start new empty scene scene = bpy.context.scene # delete the cube bpy.data.objects['Cube'].select = True bpy.ops.object.delete() # empty object for camera tracking purposes empty = bpy.data.objects.new('Empty', None) bpy.context.scene.objects.link(empty) bpy.context.scene.update() itokawa_obj = load_asteroid(asteroid=asteroid_name) # render options bpy.data.worlds['World'].horizon_color = [0, 0, 0] bpy.types.UnitSettings.system = 'METRIC' bpy.types.UnitSettings.scale_length = 1e3 scene.render.resolution_x = resolution[0] scene.render.resolution_y = resolution[1] scene.render.resolution_percentage = 100 if render_engine == 'BLENDER': scene.render.engine = 'BLENDER_RENDER' else: scene.render.engine = 'CYCLES' # setup the camera camera_obj = bpy.data.objects['Camera'] camera = bpy.data.cameras['Camera'] camera.angle_x = np.deg2rad(fov[0]) camera.angle_y = np.deg2rad(fov[1]) camera.lens = focal_length # focal length in mm camera_obj.rotation_mode = 'XYZ' # setup the lamp lamp = bpy.data.lamps['Lamp'] lamp_obj = bpy.data.objects['Lamp'] lamp.type = 'SUN' lamp.energy = 0.8 lamp.use_specular = False lamp.use_diffuse = True # use spiceypy here to determine location of the light source lamp_obj.location.x = -5 lamp_obj.location.y = 0 lamp_obj.location.z = 1 lamp_con = lamp_obj.constraints.new('TRACK_TO') lamp_con.target = itokawa_obj lamp_con.track_axis = 'TRACK_NEGATIVE_Z' lamp_con.up_axis = 'UP_Y' # set cuda device if available if len(_cycles.available_devices()) > 1: bpy.context.user_preferences.addons[ 'cycles'].preferences.compute_device_type = 'CUDA' bpy.context.user_preferences.addons['cycles'].preferences.devices[ 0].use = True bpy.context.scene.cycles.device = 'GPU' bpy.context.scene.update() return (camera_obj, camera, lamp_obj, lamp, itokawa_obj, scene)
import bpy, _cycles print(_cycles.available_devices()) bpy.context.user_preferences.system.compute_device = 'BLABLABLA'