示例#1
0
    def __update_frame_size(self, depsgraph):
        frame_params = self.__translate_frame(depsgraph)

        self.__frame = asr.Frame("beauty", frame_params, asr.AOVContainer())

        self.__project.set_frame(self.__frame)
        self.__frame = self.__project.get_frame()
示例#2
0
    def __set_aovs(self, depsgraph):
        logger.debug("appleseed: Translating AOVs")

        asr_scene_props = depsgraph.scene_eval.appleseed

        aovs = asr.AOVContainer()

        if self.__export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            if asr_scene_props.albedo_aov:
                aovs.insert(asr.AOV('albedo_aov', {}))
            if asr_scene_props.diffuse_aov:
                aovs.insert(asr.AOV('diffuse_aov', {}))
            if asr_scene_props.direct_diffuse_aov:
                aovs.insert(asr.AOV('direct_diffuse_aov', {}))
            if asr_scene_props.direct_glossy_aov:
                aovs.insert(asr.AOV('direct_glossy_aov', {}))
            if asr_scene_props.emission_aov:
                aovs.insert(asr.AOV('emission_aov', {}))
            if asr_scene_props.glossy_aov:
                aovs.insert(asr.AOV('glossy_aov', {}))
            if asr_scene_props.indirect_diffuse_aov:
                aovs.insert(asr.AOV('indirect_diffuse_aov', {}))
            if asr_scene_props.indirect_glossy_aov:
                aovs.insert(asr.AOV('indirect_glossy_aov', {}))
            if asr_scene_props.invalid_samples_aov:
                aovs.insert(asr.AOV('invalid_samples_aov', {}))
            if asr_scene_props.normal_aov:
                aovs.insert(asr.AOV('normal_aov', {}))
            if asr_scene_props.npr_contour_aov:
                aovs.insert(asr.AOV('npr_contour_aov', {}))
            if asr_scene_props.npr_shading_aov:
                aovs.insert(asr.AOV('npr_shading_aov', {}))
            if asr_scene_props.pixel_sample_count_aov:
                aovs.insert(asr.AOV('pixel_sample_count_aov', {}))
            if asr_scene_props.pixel_time_aov:
                aovs.insert(asr.AOV('pixel_time_aov', {}))
            if asr_scene_props.pixel_variation_aov:
                aovs.insert(asr.AOV('pixel_variation_aov', {}))
            if asr_scene_props.position_aov:
                aovs.insert(asr.AOV('position_aov', {}))
            if asr_scene_props.screen_space_velocity_aov:
                aovs.insert(asr.AOV('screen_space_velocity_aov', {}))
            if asr_scene_props.uv_aov:
                aovs.insert(asr.AOV('uv_aov', {}))
            if asr_scene_props.cryptomatte_material_aov:
                aovs.insert(asr.AOV('cryptomatte_material_aov', {}))
            if asr_scene_props.cryptomatte_object_aov:
                aovs.insert(asr.AOV('cryptomatte_object_aov', {}))

        return aovs
示例#3
0
    def __translate_frame(self, context):
        """
        Convert image related settings (resolution, crop windows, AOVs, ...) to appleseed.
        :param context:
        """

        logger.debug("Translating frame")

        asr_scene_props = self.bl_scene.appleseed
        scale = self.bl_scene.render.resolution_percentage / 100.0
        if context is not None:
            width = int(context.region.width)
            height = int(context.region.height)
            self.__viewport_resolution = [width, height]
        else:
            width = int(self.bl_scene.render.resolution_x * scale)
            height = int(self.bl_scene.render.resolution_y * scale)

        noise_seed = (asr_scene_props.noise_seed + self.bl_scene.frame_current) if asr_scene_props.per_frame_noise else asr_scene_props.noise_seed

        frame_params = {
            'resolution': asr.Vector2i(width, height),
            'camera': "Camera",
            'tile_size': asr.Vector2i(asr_scene_props.tile_size, asr_scene_props.tile_size),
            'filter': asr_scene_props.pixel_filter,
            'filter_size': asr_scene_props.pixel_filter_size,
            'denoiser': asr_scene_props.denoise_mode,
            'noise_seed': noise_seed,
            'skip_denoised': asr_scene_props.skip_denoised,
            'random_pixel_order': asr_scene_props.random_pixel_order,
            'prefilter_spikes': asr_scene_props.prefilter_spikes,
            'spike_threshold': asr_scene_props.spike_threshold,
            'patch_distance_threshold': asr_scene_props.patch_distance_threshold,
            'denoise_scales': asr_scene_props.denoise_scales,
            'mark_invalid_pixels': asr_scene_props.mark_invalid_pixels}

        aovs = asr.AOVContainer()
        if self.export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            aovs = self.__set_aovs(aovs)

        # Create and set the frame in the project.
        self.__frame = asr.Frame("beauty",
                                 frame_params,
                                 aovs)

        if self.bl_scene.render.use_border and self.export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            min_x = int(self.bl_scene.render.border_min_x * width)
            max_x = int(self.bl_scene.render.border_max_x * width) - 1
            min_y = height - int(self.bl_scene.render.border_max_y * height)
            max_y = height - int(self.bl_scene.render.border_min_y * height) - 1
            self.__frame.set_crop_window([min_x, min_y, max_x, max_y])

        elif self.export_mode == ProjectExportMode.INTERACTIVE_RENDER and context.space_data.use_render_border and context.region_data.view_perspective in ('ORTHO', 'PERSP'):
            min_x = int(context.space_data.render_border_min_x * width)
            max_x = int(context.space_data.render_border_max_x * width) - 1
            min_y = height - int(context.space_data.render_border_max_y * height)
            max_y = height - int(context.space_data.render_border_min_y * height) - 1
            self.__frame.set_crop_window([min_x, min_y, max_x, max_y])

        elif self.export_mode == ProjectExportMode.INTERACTIVE_RENDER and self.bl_scene.render.use_border and context.region_data.view_perspective == 'CAMERA':
            """
            I can't explain how the following code produces the correct render window.
            I basically threw every parameter combination I could think of together 
            until the result looked right.
            """

            zoom = 4 / ((math.sqrt(2) + context.region_data.view_camera_zoom / 50)** 2)
            frame_aspect_ratio = width / height
            camera_aspect_ratio = calc_film_aspect_ratio(self.bl_scene)
            if frame_aspect_ratio > 1:
                camera_width = width / zoom
                camera_height = camera_width / camera_aspect_ratio
            else:
                camera_height = height / (zoom * camera_aspect_ratio)
                camera_width = camera_height * camera_aspect_ratio

            view_offset_x, view_offset_y = context.region_data.view_camera_offset
            view_shift_x = ((view_offset_x * 2) / zoom) * width
            view_shift_y = ((view_offset_y * 2) / zoom) * height
            window_shift_x = (width - camera_width) / 2
            window_shift_y = (height - camera_height) / 2

            window_x_min = int(camera_width * self.bl_scene.render.border_min_x + window_shift_x - view_shift_x)
            window_x_max = int(camera_width * self.bl_scene.render.border_max_x + window_shift_x - view_shift_x)
            window_y_min = height - int(camera_height * self.bl_scene.render.border_max_y + window_shift_y - view_shift_y)
            window_y_max = height - int(camera_height * self.bl_scene.render.border_min_y + window_shift_y - view_shift_y)

            # Check for coordinates outside the render window.
            window_x_min = clamp_value(window_x_min, 0, width - 1)
            window_x_max = clamp_value(window_x_max, 0, width - 1)
            window_y_min = clamp_value(window_y_min, 0, height - 1)
            window_y_max = clamp_value(window_y_max, 0, height - 1)

            self.__frame.set_crop_window([window_x_min, window_y_min, window_x_max, window_y_max])

        self.__project.set_frame(self.__frame)
        self.__frame = self.as_project.get_frame()

        if len(asr_scene_props.post_processing_stages) > 0 and self.export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            self.__set_post_process()
示例#4
0
    def __translate_frame(self):
        """
        Convert image related settings (resolution, crop windows, AOVs, ...) to appleseed.
        """

        logger.debug("Translating frame")

        asr_scene_props = self.bl_scene.appleseed
        scale = self.bl_scene.render.resolution_percentage / 100.0
        if self.__context:
            width = int(self.__context.region.width)
            height = int(self.__context.region.height)
            self.__viewport_resolution = [width, height]
        else:
            width = int(self.bl_scene.render.resolution_x * scale)
            height = int(self.bl_scene.render.resolution_y * scale)

        frame_params = {
            'resolution':
            asr.Vector2i(width, height),
            'camera':
            self.bl_scene.camera.name,
            'tile_size':
            asr.Vector2i(asr_scene_props.tile_size, asr_scene_props.tile_size),
            'filter':
            asr_scene_props.pixel_filter,
            'filter_size':
            asr_scene_props.pixel_filter_size,
            'denoiser':
            asr_scene_props.denoise_mode,
            'skip_denoised':
            asr_scene_props.skip_denoised,
            'random_pixel_order':
            asr_scene_props.random_pixel_order,
            'prefilter_spikes':
            asr_scene_props.prefilter_spikes,
            'spike_threshold':
            asr_scene_props.spike_threshold,
            'patch_distance_threshold':
            asr_scene_props.patch_distance_threshold,
            'denoise_scales':
            asr_scene_props.denoise_scales,
            'mark_invalid_pixels':
            asr_scene_props.mark_invalid_pixels
        }

        # AOVs
        aovs = asr.AOVContainer()
        if self.export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            if asr_scene_props.diffuse_aov:
                aovs.insert(asr.AOV('diffuse_aov', {}))
            if asr_scene_props.direct_diffuse_aov:
                aovs.insert(asr.AOV('direct_diffuse_aov', {}))
            if asr_scene_props.indirect_diffuse_aov:
                aovs.insert(asr.AOV('indirect_diffuse_aov', {}))
            if asr_scene_props.glossy_aov:
                aovs.insert(asr.AOV('glossy_aov', {}))
            if asr_scene_props.direct_glossy_aov:
                aovs.insert(asr.AOV('direct_glossy_aov', {}))
            if asr_scene_props.indirect_glossy_aov:
                aovs.insert(asr.AOV('indirect_glossy_aov', {}))
            if asr_scene_props.normal_aov:
                aovs.insert(asr.AOV('normal_aov', {}))
            if asr_scene_props.position_aov:
                aovs.insert(asr.AOV('position_aov', {}))
            if asr_scene_props.uv_aov:
                aovs.insert(asr.AOV('uv_aov', {}))
            if asr_scene_props.depth_aov:
                aovs.insert(asr.AOV('depth_aov', {}))
            if asr_scene_props.pixel_time_aov:
                aovs.insert(asr.AOV('pixel_time_aov', {}))
            if asr_scene_props.invalid_samples_aov:
                aovs.insert(asr.AOV('invalid_samples_aov', {}))
            if asr_scene_props.pixel_sample_count_aov:
                aovs.insert(asr.AOV('pixel_sample_count_aov', {}))
            if asr_scene_props.pixel_variation_aov:
                aovs.insert(asr.AOV('pixel_variation_aov', {}))
            if asr_scene_props.albedo_aov:
                aovs.insert(asr.AOV('albedo_aov', {}))
            if asr_scene_props.emission_aov:
                aovs.insert(asr.AOV('emission_aov', {}))
            if asr_scene_props.npr_shading_aov:
                aovs.insert(asr.AOV('npr_shading_aov', {}))
            if asr_scene_props.npr_contour_aov:
                aovs.insert(asr.AOV('npr_contour_aov', {}))

        # Create and set the frame in the project.
        frame = asr.Frame("beauty", frame_params, aovs)

        if len(
                asr_scene_props.post_processing_stages
        ) > 0 and self.export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            for index, stage in enumerate(
                    asr_scene_props.post_processing_stages):
                if stage.model == 'render_stamp_post_processing_stage':
                    params = {
                        'order': index,
                        'format_string': stage.render_stamp
                    }
                else:
                    params = {
                        'order': index,
                        'color_map': stage.color_map,
                        'auto_range': stage.auto_range,
                        'range_min': stage.range_min,
                        'range_max': stage.range_max,
                        'add_legend_bar': stage.add_legend_bar,
                        'legend_bar_ticks': stage.legend_bar_ticks,
                        'render_isolines': stage.render_isolines,
                        'line_thickness': stage.line_thickness
                    }

                    if stage.color_map == 'custom':
                        params[
                            'color_map_file_path'] = stage.color_map_file_path

                post_process = asr.PostProcessingStage(stage.model, stage.name,
                                                       params)

                frame.post_processing_stages().insert(post_process)

        if self.bl_scene.render.use_border and self.export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            min_x = int(self.bl_scene.render.border_min_x * width)
            max_x = int(self.bl_scene.render.border_max_x * width) - 1
            min_y = height - int(self.bl_scene.render.border_max_y * height)
            max_y = height - int(
                self.bl_scene.render.border_min_y * height) - 1
            frame.set_crop_window([min_x, min_y, max_x, max_y])

        elif self.export_mode == ProjectExportMode.INTERACTIVE_RENDER and self.__context.space_data.use_render_border \
                and self.__context.region_data.view_perspective in ('ORTHO', 'PERSP'):
            min_x = int(self.__context.space_data.render_border_min_x * width)
            max_x = int(
                self.__context.space_data.render_border_max_x * width) - 1
            min_y = height - int(
                self.__context.space_data.render_border_max_y * height)
            max_y = height - int(
                self.__context.space_data.render_border_min_y * height) - 1
            frame.set_crop_window([min_x, min_y, max_x, max_y])

        self.__project.set_frame(frame)