示例#1
0
    def sync_auto_adapt_subdivision(self, width=0, height=0):
        camera = self.scene.subdivision_camera
        if not camera:
            camera = self.scene.camera
        if width == 0:
            width = self.width
        if height == 0:
            height = self.height

        objects_with_adaptive_subdivision = self._get_adaptive_subdivision_objects(
        )

        if not objects_with_adaptive_subdivision:
            return

        fb = self.frame_buffers_aovs[pyrpr.AOV_COLOR]['aov']
        if fb.width != width or fb.height != height:
            # creating temporary FrameBuffer of required size only to set subdivision
            fb = pyrpr.FrameBuffer(self.context, width, height)

        for obj in objects_with_adaptive_subdivision:
            obj.set_auto_adapt_subdivision_factor(fb, camera,
                                                  obj.subdivision['factor'])
            obj.set_subdivision_boundary_interop(obj.subdivision['boundary'])
            obj.set_subdivision_crease_weight(obj.subdivision['crease_weight'])
    def enable_aov(self, aov_type):
        if self.is_aov_enabled(aov_type):
            return

        fbs = {}
        fbs['aov'] = pyrpr.FrameBuffer(self.context, self.width, self.height)
        fbs['aov'].set_name("%d_aov" % aov_type)
        self.context.attach_aov(aov_type, fbs['aov'])
        if aov_type == pyrpr.AOV_COLOR and self.gl_interop:
            fbs['res'] = pyrpr.FrameBufferGL(self.context, self.width, self.height)
            fbs['gl'] = fbs['res']      # resolved and gl framebuffers are the same
            fbs['gl'].set_name("%d_gl" % aov_type)
        else:
            fbs['res'] = pyrpr.FrameBuffer(self.context, self.width, self.height)
            fbs['res'].set_name("%d_res" % aov_type)

        self.frame_buffers_aovs[aov_type] = fbs
    def enable_aov(self, aov_type):
        if aov_type == pyrpr.AOV_VARIANCE:
            log("Unsupported RPRContext.enable_aov(AOV_VARIANCE)")
            return

        if self.is_aov_enabled(aov_type):
            return

        fbs = {}
        fbs['aov'] = pyrpr.FrameBuffer(self.context, self.width, self.height)
        fbs['aov'].set_name("%d_aov" % aov_type)
        fbs['res'] = fbs['aov']
        self.context.attach_aov(aov_type, fbs['aov'])

        self.frame_buffers_aovs[aov_type] = fbs
示例#4
0
    def _enable_catchers(self):
        # Experimentally found the max value of shadow catcher,
        # we'll need it to normalize shadow catcher AOV
        SHADOW_CATCHER_MAX_VALUE = 2.0

        # Enable required AOVs
        self.enable_aov(pyrpr.AOV_COLOR)
        self.enable_aov(pyrpr.AOV_OPACITY)
        self.enable_aov(pyrpr.AOV_BACKGROUND)
        if self.use_shadow_catcher:
            self.enable_aov(pyrpr.AOV_SHADOW_CATCHER)
        if self.use_reflection_catcher:
            self.enable_aov(pyrpr.AOV_REFLECTION_CATCHER)

        # Composite frame buffer
        self.frame_buffers_aovs[
            pyrpr.AOV_COLOR]['composite'] = pyrpr.FrameBuffer(
                self.context, self.width, self.height)
        self.frame_buffers_aovs[pyrpr.AOV_COLOR]['composite'].set_name(
            'default_composite')
        if self.gl_interop:
            # splitting resolved and gl framebuffers
            self.frame_buffers_aovs[
                pyrpr.AOV_COLOR]['res'] = pyrpr.FrameBuffer(
                    self.context, self.width, self.height)
            self.frame_buffers_aovs[pyrpr.AOV_COLOR]['res'].set_name(
                'default_res')

        # Composite calculation elements frame buffers
        color = self.create_composite(pyrpr.COMPOSITE_FRAMEBUFFER, {
            'framebuffer.input':
            self.frame_buffers_aovs[pyrpr.AOV_COLOR]['res']
        })

        alpha = self.create_composite(pyrpr.COMPOSITE_FRAMEBUFFER, {
            'framebuffer.input':
            self.frame_buffers_aovs[pyrpr.AOV_OPACITY]['res']
        }).get_channel(0)
        full_alpha = alpha

        if self.use_reflection_catcher or self.use_shadow_catcher:
            if self.use_reflection_catcher:
                reflection_catcher = self.create_composite(
                    pyrpr.COMPOSITE_FRAMEBUFFER, {
                        'framebuffer.input':
                        self.frame_buffers_aovs[pyrpr.AOV_REFLECTION_CATCHER]
                        ['res']
                    }).get_channel(0)
                full_alpha += reflection_catcher

            background = self.create_composite(
                pyrpr.COMPOSITE_FRAMEBUFFER, {
                    'framebuffer.input':
                    self.frame_buffers_aovs[pyrpr.AOV_BACKGROUND]['res']
                })

            self.composite = background * (1.0 -
                                           full_alpha) + color * full_alpha

            if self.use_shadow_catcher:
                shadow_catcher = self.create_composite(
                    pyrpr.COMPOSITE_FRAMEBUFFER, {
                        'framebuffer.input':
                        self.frame_buffers_aovs[pyrpr.AOV_SHADOW_CATCHER]
                        ['res']
                    }).get_channel(0)
                shadow_catcher_norm = (shadow_catcher /
                                       SHADOW_CATCHER_MAX_VALUE).min(1.0)

                self.composite *= (1.0 - shadow_catcher_norm) * (1.0, 1.0, 1.0, 0.0) + \
                                  (0.0, 0.0, 0.0, 1.0)

                if self.use_transparent_background:
                    full_alpha = (full_alpha + shadow_catcher_norm).min(1.0)

        else:
            self.composite = color

        if self.use_transparent_background:
            self.composite = full_alpha * (
                (0.0, 0.0, 0.0, 1.0) + self.composite * (1.0, 1.0, 1.0, 0.0))