예제 #1
0
def setup_envmap_render():
    """Creates a background scene for rendering environment textures.
    Use it as a context manager to automatically clean up on errors.
    """
    rpdat = arm.utils.get_rp()
    radiance_size = int(rpdat.arm_radiance_size)

    # Render worlds in a different scene so that there are no other
    # objects. The actual scene might be called differently if the name
    # is already taken
    scene = bpy.data.scenes.new("_arm_envmap_render")
    scene.render.engine = "CYCLES"
    scene.render.image_settings.file_format = ENVMAP_FORMAT
    if ENVMAP_FORMAT == 'HDR':
        scene.render.image_settings.color_depth = '32'

    # Export in linear space and with default color management settings
    scene.display_settings.display_device = "None"
    scene.view_settings.view_transform = "Standard"
    scene.view_settings.look = "None"
    scene.view_settings.exposure = 0
    scene.view_settings.gamma = 1

    scene.render.image_settings.quality = 100
    scene.render.resolution_x = radiance_size
    scene.render.resolution_y = radiance_size // 2

    # Set GPU as rendering device if the user enabled it
    if bpy.context.preferences.addons[
            "cycles"].preferences.compute_device_type == "CUDA":
        scene.cycles.device = "GPU"
    else:
        log.info(
            'Using CPU for environment render (might be slow). Enable CUDA if possible.'
        )

    # One sample is enough for world background only
    scene.cycles.samples = 1

    # Setup scene
    cam = bpy.data.cameras.new("_arm_cam_envmap_render")
    cam_obj = bpy.data.objects.new("_arm_cam_envmap_render", cam)
    scene.collection.objects.link(cam_obj)
    scene.camera = cam_obj

    cam_obj.location = [0.0, 0.0, 0.0]
    cam.type = "PANO"
    cam.cycles.panorama_type = "EQUIRECTANGULAR"
    cam_obj.rotation_euler = [math.radians(90), 0, math.radians(-90)]

    try:
        yield
    finally:
        bpy.data.objects.remove(cam_obj)
        bpy.data.cameras.remove(cam)
        bpy.data.scenes.remove(scene)
예제 #2
0
def parse_tex_sky(node: bpy.types.ShaderNodeTexSky, out_socket: bpy.types.NodeSocket, state: ParserState) -> vec3str:
    if state.context == ParserContext.OBJECT:
        # Pass through
        return c.to_vec3([0.0, 0.0, 0.0])

    state.world.world_defs += '_EnvSky'

    if node.sky_type == 'PREETHAM' or node.sky_type == 'HOSEK_WILKIE':
        if node.sky_type == 'PREETHAM':
            log.info('Info: Preetham sky model is not supported, using Hosek Wilkie sky model instead')

        return parse_sky_hosekwilkie(node, state)

    elif node.sky_type == 'NISHITA':
        return parse_sky_nishita(node, state)

    else:
        log.error(f'Unsupported sky model: {node.sky_type}!')
        return c.to_vec3([0.0, 0.0, 0.0])