Esempio n. 1
0
def test_fbquality_rgba64():
    # Make sure that we don't get a 64-bit configuration if we request
    # an unspecific number of color bits.  See:
    #   https://www.panda3d.org/forums/viewtopic.php?t=20192
    # This issue occurs if we are requesting 1 bit, not if we are requesting
    # a specific amount.  There are several ways to do that, so we want to
    # assert that none of them will yield a 64-bit color buffer.
    req_color0 = FrameBufferProperties()
    req_color0.color_bits = 0

    req_color1 = FrameBufferProperties()
    req_color1.color_bits = 1

    req_color0_alpha0 = FrameBufferProperties()
    req_color0_alpha0.color_bits = 0
    req_color0_alpha0.alpha_bits = 0

    req_color1_alpha1 = FrameBufferProperties()
    req_color1_alpha1.color_bits = 1
    req_color1_alpha1.alpha_bits = 1

    req_rgb0 = FrameBufferProperties()
    req_rgb0.set_rgba_bits(0, 0, 0, 0)

    req_rgb1 = FrameBufferProperties()
    req_rgb1.set_rgba_bits(1, 1, 1, 0)

    req_rgb0_alpha0 = FrameBufferProperties()
    req_rgb0_alpha0.set_rgba_bits(0, 0, 0, 0)

    req_rgb1_alpha1 = FrameBufferProperties()
    req_rgb1_alpha1.set_rgba_bits(1, 1, 1, 1)

    fb_rgba8 = FrameBufferProperties()
    fb_rgba8.rgb_color = True
    fb_rgba8.set_rgba_bits(8, 8, 8, 8)

    fb_rgba16 = FrameBufferProperties()
    fb_rgba16.rgb_color = True
    fb_rgba16.set_rgba_bits(16, 16, 16, 16)

    assert fb_rgba8.get_quality(req_color0) > fb_rgba16.get_quality(req_color0)
    assert fb_rgba8.get_quality(req_color1) > fb_rgba16.get_quality(req_color1)
    assert fb_rgba8.get_quality(req_color0_alpha0) > fb_rgba16.get_quality(
        req_color0_alpha0)
    assert fb_rgba8.get_quality(req_color1_alpha1) > fb_rgba16.get_quality(
        req_color1_alpha1)
    assert fb_rgba8.get_quality(req_rgb0) > fb_rgba16.get_quality(req_rgb0)
    assert fb_rgba8.get_quality(req_rgb1) > fb_rgba16.get_quality(req_rgb1)
    assert fb_rgba8.get_quality(req_rgb0_alpha0) > fb_rgba16.get_quality(
        req_rgb0_alpha0)
    assert fb_rgba8.get_quality(req_rgb1_alpha1) > fb_rgba16.get_quality(
        req_rgb1_alpha1)
Esempio n. 2
0
    def create(self):
        winprops = WindowProperties.size(self.size, self.size)
        props = FrameBufferProperties()
        props.setRgbColor(0)
        props.setAlphaBits(0)
        props.setDepthBits(1)
        self.buffer = base.graphicsEngine.makeOutput(
            base.pipe, "shadowsBuffer", -2, props, winprops,
            GraphicsPipe.BFRefuseWindow, base.win.getGsg(), base.win)

        if not self.buffer:
            print("Video driver cannot create an offscreen buffer.")
            return
        self.depthmap = Texture()
        self.buffer.addRenderTexture(self.depthmap,
                                     GraphicsOutput.RTMBindOrCopy,
                                     GraphicsOutput.RTPDepthStencil)

        self.depthmap.setMinfilter(Texture.FTShadow)
        self.depthmap.setMagfilter(Texture.FTShadow)
        self.depthmap.setBorderColor(LColor(1, 1, 1, 1))
        self.depthmap.setWrapU(Texture.WMBorderColor)
        self.depthmap.setWrapV(Texture.WMBorderColor)

        self.cam = base.makeCamera(self.buffer, lens=OrthographicLens())
        self.cam.reparent_to(render)
        self.node = self.cam.node()
        self.node.setInitialState(
            RenderState.make(
                CullFaceAttrib.make_reverse(),
                ColorWriteAttrib.make(ColorWriteAttrib.M_none),
            ))
        self.node.setScene(render)
        if settings.debug_shadow_frustum:
            self.node.showFrustum()
Esempio n. 3
0
 def createBuffer(self, name, xsize, ysize, texgroup, depthbits=1):
     winprops = WindowProperties()
     winprops.setSize(xsize, ysize)
     props = FrameBufferProperties(FrameBufferProperties.getDefault())
     props.setBackBuffers(0)
     props.setRgbColor(1)
     props.setDepthBits(depthbits)
     props.setStereo(self.win.isStereo())
     depthtex, colortex, auxtex0, auxtex1 = texgroup
     if auxtex0 != None:
         props.setAuxRgba(1)
     if auxtex1 != None:
         props.setAuxRgba(2)
     buffer = base.graphicsEngine.makeOutput(self.win.getPipe(), name, -1, props, winprops, GraphicsPipe.BFRefuseWindow | GraphicsPipe.BFResizeable, self.win.getGsg(), self.win)
     if buffer == None:
         return buffer
     if depthtex:
         buffer.addRenderTexture(depthtex, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPDepth)
     if colortex:
         buffer.addRenderTexture(colortex, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPColor)
     if auxtex0:
         buffer.addRenderTexture(auxtex0, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPAuxRgba0)
     if auxtex1:
         buffer.addRenderTexture(auxtex1, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPAuxRgba1)
     buffer.setSort(self.nextsort)
     buffer.disableClears()
     self.nextsort += 1
     return buffer
Esempio n. 4
0
    def create_buffer(self, name, texture, width, height, fbprops):
        """
        Create a render buffer with the given properties.
        """

        winprops = WindowProperties()
        winprops.set_size(width, height)
        props = FrameBufferProperties(FrameBufferProperties.get_default())
        props.set_back_buffers(0)
        props.set_rgb_color(1)
        if fbprops is not None:
            props.add_properties(fbprops)

        buffer = self.base.win.make_texture_buffer(name,
                                                   width,
                                                   height,
                                                   to_ram=False,
                                                   fbp=props)
        if buffer is not None:
            buffer.clear_render_textures()
            buffer.set_sort(self.nextsort)
            self.nextsort += 1
            buffer.add_render_texture(texture, GraphicsOutput.RTMBindOrCopy,
                                      GraphicsOutput.RTPColor)
        else:
            print("COULD NOT CREATE BUFFER")
        return buffer
Esempio n. 5
0
    def __init__(self,
                 base,
                 color=True,
                 depth=False,
                 size=None,
                 near_far=None,
                 hfov=None,
                 title=None):
        if size is None:
            size = (640, 480)
        if near_far is None:
            near_far = (0.01, 10000.0)
        if hfov is None:
            hfov = 60
        winprops = WindowProperties.size(*size)
        winprops.setTitle(title or 'Camera Sensor')
        fbprops = FrameBufferProperties()
        # Request 8 RGB bits, 8 alpha bits, and a depth buffer.
        fbprops.setRgbColor(True)
        fbprops.setRgbaBits(8, 8, 8, 8)
        fbprops.setDepthBits(24)
        self.graphics_engine = GraphicsEngine(base.pipe)

        window_type = base.config.GetString('window-type', 'onscreen')
        flags = GraphicsPipe.BFFbPropsOptional
        if window_type == 'onscreen':
            flags = flags | GraphicsPipe.BFRequireWindow
        elif window_type == 'offscreen':
            flags = flags | GraphicsPipe.BFRefuseWindow

        self.buffer = self.graphics_engine.makeOutput(base.pipe,
                                                      "camera sensor buffer",
                                                      -100, fbprops, winprops,
                                                      flags)

        if not color and not depth:
            raise ValueError("At least one of color or depth should be True")
        if color:
            self.color_tex = Texture("color_texture")
            self.buffer.addRenderTexture(self.color_tex,
                                         GraphicsOutput.RTMCopyRam,
                                         GraphicsOutput.RTPColor)
        else:
            self.color_tex = None
        if depth:
            self.depth_tex = Texture("depth_texture")
            self.buffer.addRenderTexture(self.depth_tex,
                                         GraphicsOutput.RTMCopyRam,
                                         GraphicsOutput.RTPDepth)
        else:
            self.depth_tex = None

        self.cam = base.makeCamera(self.buffer,
                                   scene=base.render,
                                   camName='camera_sensor')
        self.lens = self.cam.node().getLens()
        self.lens.setFov(hfov)
        self.lens.setFilmSize(
            *size)  # this also defines the units of the focal length
        self.lens.setNearFar(*near_far)
Esempio n. 6
0
    def _configure_window(self, window_size):
        if self._window is not None:
            if not np.array_equal(window_size, self._window_size):
                self._delete_window()

        if self._window is None:
            # framebuffer
            fbp = FrameBufferProperties(self._fb_props)
            fbp.set_rgba_bits(8, 8, 8, 8)
            fbp.set_depth_bits(16)
            self._window = self._engine.make_output(
                self._pipe, 'buffer', 0, fbp,
                WindowProperties.size(*window_size),
                GraphicsPipe.BFRefuseWindow)
            if self._window is None:
                raise RuntimeError(
                    "GraphicsPipe cannot make offscreen buffers")
            self._window_size = window_size
            self._window.set_clear_color_active(False)
            # bind textures
            self._color_tex = Texture("colortex")
            self._depth_tex = Texture("depthtex")
            self._window.add_render_texture(self._color_tex,
                                            GraphicsOutput.RTMBindOrCopy,
                                            GraphicsOutput.RTPColor)
            self._window.add_render_texture(self._depth_tex,
                                            GraphicsOutput.RTMBindOrCopy,
                                            GraphicsOutput.RTPDepth)
            # viewport
            self._viewport = self._window.make_display_region((0, 1, 0, 1))
            self._viewport.set_sort(-100)
            self._viewport.set_clear_color_active(True)
Esempio n. 7
0
 def create_renderer(self,
                     name,
                     camera,
                     width,
                     height,
                     msaa,
                     callback,
                     cc=None):
     texture = Texture()
     texture.set_wrap_u(Texture.WMClamp)
     texture.set_wrap_v(Texture.WMClamp)
     texture.set_minfilter(Texture.FT_linear)
     texture.set_magfilter(Texture.FT_linear)
     fbprops = FrameBufferProperties()
     fbprops.setRgbaBits(1, 1, 1, 1)
     if msaa > 0:
         fbprops.setMultisamples(msaa)
     buffer = self.create_buffer(name,
                                 texture,
                                 width,
                                 height,
                                 fbprops=fbprops)
     dr = buffer.make_display_region()
     dr.set_camera(camera)
     dr.set_active(1)
     self.buffers.append(buffer)
     if callback is not None:
         dr.set_draw_callback(PythonCallbackObject(callback))
     if cc is not None:
         dr.setClearColorActive(1)
         dr.setClearColor(cc)
     return texture
    def __init__(self):
        ShowBase.__init__(self)

        # Load the environment model.
        self.scene = self.loader.loadModel("models/environment")
        # Reparent the model to render.
        self.scene.reparentTo(self.render)
        # Apply scale and position transforms on the model.
        self.scene.setScale(0.25, 0.25, 0.25)
        self.scene.setPos(-8, 42, 0)

        # Needed for camera image
        self.dr = self.camNode.getDisplayRegion(0)

        # Needed for camera depth image
        winprops = WindowProperties.size(self.win.getXSize(),
                                         self.win.getYSize())
        fbprops = FrameBufferProperties()
        fbprops.setDepthBits(1)
        self.depthBuffer = self.graphicsEngine.makeOutput(
            self.pipe, "depth buffer", -2, fbprops, winprops,
            GraphicsPipe.BFRefuseWindow, self.win.getGsg(), self.win)
        self.depthTex = Texture()
        self.depthTex.setFormat(Texture.FDepthComponent)
        self.depthBuffer.addRenderTexture(self.depthTex,
                                          GraphicsOutput.RTMCopyRam,
                                          GraphicsOutput.RTPDepth)
        lens = self.cam.node().getLens()
        # the near and far clipping distances can be changed if desired
        # lens.setNear(5.0)
        # lens.setFar(500.0)
        self.depthCam = self.makeCamera(self.depthBuffer,
                                        lens=lens,
                                        scene=render)
        self.depthCam.reparentTo(self.cam)
Esempio n. 9
0
    def createBuffer(self,
                     name,
                     xsize,
                     ysize,
                     texgroup,
                     depthbits=1,
                     scene=False):
        """ Low-level buffer creation.  Not intended for public use. """

        winprops = WindowProperties()
        winprops.setSize(xsize, ysize)
        props = FrameBufferProperties(FrameBufferProperties.getDefault())
        #if scene:
        #    props = FrameBufferProperties(FrameBufferProperties.getDefault())
        #else:
        #    props = FrameBufferProperties()
        props.setBackBuffers(0)
        if not scene:
            props.setMultisamples(0)
            props.setBackBuffers(0)
            props.setAccumBits(0)
            props.setAuxFloat(0)
            props.setAuxRgba(0)
            props.setAuxHrgba(0)
            props.setCoverageSamples(0)
        props.setRgbColor(1)
        props.setColorBits(48)
        if depthbits:
            props.setDepthBits(32)
            props.setFloatDepth(True)
        props.setStereo(self.win.isStereo())
        depthtex, colortex, auxtex0, auxtex1 = texgroup
        if (auxtex0 != None):
            props.setAuxRgba(1)
        if (auxtex1 != None):
            props.setAuxRgba(2)
        buffer = base.graphicsEngine.makeOutput(
            self.win.getPipe(), name, -1, props, winprops,
            GraphicsPipe.BFRefuseWindow | GraphicsPipe.BFResizeable,
            self.win.getGsg(), self.win)
        if (buffer == None):
            return buffer
        if (depthtex):
            buffer.addRenderTexture(depthtex, GraphicsOutput.RTMBindOrCopy,
                                    GraphicsOutput.RTPDepth)
        if (colortex):
            buffer.addRenderTexture(colortex, GraphicsOutput.RTMBindOrCopy,
                                    GraphicsOutput.RTPColor)
        if (auxtex0):
            buffer.addRenderTexture(auxtex0, GraphicsOutput.RTMBindOrCopy,
                                    GraphicsOutput.RTPAuxRgba0)
        if (auxtex1):
            buffer.addRenderTexture(auxtex1, GraphicsOutput.RTMBindOrCopy,
                                    GraphicsOutput.RTPAuxRgba1)
        buffer.setSort(self.nextsort)
        buffer.disableClears()
        self.nextsort += 1
        return buffer
Esempio n. 10
0
    def __init__(self, init_x, pbase=None):
        self.x = np.array(init_x)
        self.v_i = np.array([0] * 3)
        self.a_i = np.array([0] * 3)
        self.q = np.array([0, 1, 0, 0])
        self.omega = np.array([0]*3)
        self.omega_dot = np.array([0]*3)

        self.time = None

        # Explicit runge-kutta method of order (4)5 due to Dormand & Prince
        self.integrator = ode(self.rhs_equation).set_integrator('dopri5')

        self.pbase = pbase

        # Create quadcopter node.
        self.node_path = pbase.render.attachNewNode("Quadcopter")
        self.node_path.setPos(*self.x)
        self.q = np.array(self.node_path.getQuat())

        # Configure front camera
        fb_prop = FrameBufferProperties()
        # Request 8 RGB bits, no alpha bits, and a depth buffer.
        fb_prop.setRgbColor(True)
        fb_prop.setRgbaBits(8, 8, 8, 0)
        # fb_prop.setDepthBits(16)

        self.front_buffer = self.pbase.win.makeTextureBuffer("front_buffer", 256, 256, to_ram=True, fbp=fb_prop)
        self.front_camera = self.pbase.makeCamera(self.front_buffer)
        self.front_camera.reparentTo(self.node_path)

        # self.front_camera.setH(-90)

        # Configure bottom camera
        self.bottom_buffer = self.pbase.win.makeTextureBuffer("bottom_buffer", 256, 256)
        self.bottom_camera = self.pbase.makeCamera(self.bottom_buffer)
        self.bottom_camera.reparentTo(self.node_path)
        # self.bottom_camera.setP(-90)

        self.pbase.accept("v", self.pbase.bufferViewer.toggleEnable)
        self.pbase.accept("V", self.pbase.bufferViewer.toggleEnable)
        self.pbase.bufferViewer.setPosition("llcorner")
        self.pbase.bufferViewer.setCardSize(.5, 0.0)

        self.pbase.accept("u", self.update_textures)

        # Load in quadcopter model
        self.model = pbase.loader.loadModel("models/plane.egg")
        self.model.reparentTo(self.node_path)
        self.model.setH(90)
        # self.model.setScale(1/8., 1/8., 1/8.)

        self.error = None

        self.v_pid = PIDControl(20.0, 10.0, 0.0)
        self.omega_pid = PIDControl(5.0, 0.0, 0.0)

        self.__tmat_ib = Mat4()
Esempio n. 11
0
    def _initDepthCapture(self):

        for camera in self.cameras:

            camNode = Camera('Depth camera')
            camNode.setCameraMask(self.cameraMask)
            lens = PerspectiveLens()
            lens.setFov(self.fov)
            lens.setAspectRatio(float(self.size[0]) / float(self.size[1]))
            lens.setNear(self.zNear)
            lens.setFar(self.zFar)
            camNode.setLens(lens)
            camNode.setScene(self.scene.scene)
            cam = camera.attachNewNode(camNode)

            winprops = WindowProperties.size(self.size[0], self.size[1])
            fbprops = FrameBufferProperties.getDefault()
            fbprops = FrameBufferProperties(fbprops)
            fbprops.setRgbColor(False)
            fbprops.setRgbaBits(0, 0, 0, 0)
            fbprops.setStencilBits(0)
            fbprops.setMultisamples(0)
            fbprops.setBackBuffers(0)
            fbprops.setDepthBits(16)

            flags = GraphicsPipe.BFFbPropsOptional
            if self.mode == 'onscreen':
                flags = flags | GraphicsPipe.BFRequireWindow
            elif self.mode == 'offscreen':
                flags = flags | GraphicsPipe.BFRefuseWindow
            else:
                raise Exception('Unsupported rendering mode: %s' % (self.mode))

            buf = self.graphicsEngine.makeOutput(self.pipe, 'Depth buffer', 0,
                                                 fbprops, winprops, flags)
            if buf is None:
                raise Exception('Unable to create depth buffer')

            # Set to render at the end
            buf.setSort(10000)

            dr = buf.makeDisplayRegion()
            dr.setSort(0)
            dr.setCamera(cam)
            dr = camNode.getDisplayRegion(0)

            tex = Texture()
            tex.setFormat(Texture.FDepthComponent)
            tex.setComponentType(Texture.TFloat)
            buf.addRenderTexture(tex, GraphicsOutput.RTMCopyRam,
                                 GraphicsOutput.RTPDepth)
            # XXX: should use tex.setMatchFramebufferFormat(True)?

            agent = camera.getParent()
            self.depthBuffers[agent.getName()] = buf
            self.depthTextures[agent.getName()] = tex
Esempio n. 12
0
def test_fbquality_depth():
    # We check common framebuffer depth configurations to make sure they
    # are rated predictably with respect to each other when requesting 1 bit.
    # In particular, we make sure that we don't get a 16-bit depth buffer if
    # the driver only gives extra depth in combination with a stencil buffer.
    req = FrameBufferProperties()
    req.depth_bits = 1

    #NB. we need to set rgb_color=True when testing the quality of framebuffer
    # properties, lest it return a quality of 0.
    fb_d16s8 = FrameBufferProperties()
    fb_d16s8.rgb_color = True
    fb_d16s8.depth_bits = 16
    fb_d16s8.stencil_bits = 8

    fb_d24s8 = FrameBufferProperties()
    fb_d24s8.rgb_color = True
    fb_d24s8.depth_bits = 24
    fb_d24s8.stencil_bits = 8

    fb_d32 = FrameBufferProperties()
    fb_d32.rgb_color = True
    fb_d32.depth_bits = 32

    fb_d32s8 = FrameBufferProperties()
    fb_d32s8.rgb_color = True
    fb_d32s8.depth_bits = 32
    fb_d32s8.stencil_bits = 8

    # 16-bit depth is terrible for most applications and should not be chosen.
    assert fb_d16s8.get_quality(req) < fb_d24s8.get_quality(req)
    assert fb_d16s8.get_quality(req) < fb_d32.get_quality(req)
    assert fb_d16s8.get_quality(req) < fb_d32s8.get_quality(req)

    # Getting extra depth should be better than getting an unwanted bitplane.
    assert fb_d32.get_quality(req) > fb_d16s8.get_quality(req)
    assert fb_d32.get_quality(req) > fb_d24s8.get_quality(req)

    # If we're getting stencil anyway, we'll prefer to maximize our depth.
    assert fb_d32s8.get_quality(req) > fb_d24s8.get_quality(req)

    # However, unnecessary stencil bits are still a waste.
    assert fb_d32s8.get_quality(req) < fb_d32.get_quality(req)
Esempio n. 13
0
    def apply(self):
        winprops = WindowProperties.size(2048, 2048)
        props = FrameBufferProperties()
        props.setRgbColor(1)
        props.setAlphaBits(1)
        props.setDepthBits(1)
        lbuffer = base.graphicsEngine.makeOutput(base.pipe, 'offscreen buffer',
                                                 -2, props, winprops,
                                                 GraphicsPipe.BFRefuseWindow,
                                                 base.win.getGsg(), base.win)
        self.buffer = lbuffer
        ldepthmap = Texture()
        lbuffer.addRenderTexture(ldepthmap, GraphicsOutput.RTMBindOrCopy,
                                 GraphicsOutput.RTPDepthStencil)
        ldepthmap.setMinfilter(Texture.FTShadow)
        ldepthmap.setMagfilter(Texture.FTShadow)

        base.camLens.setNearFar(1.0, 10000)
        base.camLens.setFov(75)

        self.lcam = base.makeCamera(lbuffer)
        self.lcam.node().setScene(render)
        self.lcam.node().getLens().setFov(45)
        self.lcam.node().getLens().setNearFar(1, 100)

        render.setShaderInput('light', self.lcam)
        render.setShaderInput('depthmap', ldepthmap)
        render.setShaderInput('ambient', .15, .15, .15, 1.0)

        lci = NodePath(PandaNode('light camera initializer'))
        with open('yyagl/assets/shaders/caster.vert') as f:
            vert = f.read()
        with open('yyagl/assets/shaders/caster.frag') as f:
            frag = f.read()
        lci.setShader(Shader.make(Shader.SLGLSL, vert, frag))
        self.lcam.node().setInitialState(lci.getState())

        mci = NodePath(PandaNode('main camera initializer'))
        with open('yyagl/assets/shaders/main.vert') as f:
            vert = f.read()
        with open('yyagl/assets/shaders/main.frag') as f:
            frag = f.read()
        frag = frag.replace('<LIGHTS>', str(len(self.lights)))
        # use PTALVecBaseX instead
        # setShaderInput('vec3argname', PTALVecBase3(((0, 0, 0), (1, 1, 1))))
        render.setShader(Shader.make(Shader.SLGLSL, vert, frag))
        render.setShaderInput('num_lights', len(self.lights))
        map(lambda lgt: self.set_lgt_args(*lgt), enumerate(self.lights))
        mci.setShader(Shader.make(Shader.SLGLSL, vert, frag))
        base.cam.node().setInitialState(mci.getState())

        self.lcam.setPos(15, 30, 45)
        self.lcam.lookAt(0, 15, 0)
        self.lcam.node().getLens().setNearFar(1, 100)
Esempio n. 14
0
def check_and_create_rendering_buffers(showbase):
    if not settings.render_scene_to_buffer:
        return

    if not settings.buffer_texture:
        print("Render to buffer not supported")
        return

    print("Render scene to buffer")

    buffer_multisamples = 0
    if settings.render_scene_to_buffer and not settings.disable_multisampling and settings.use_multisampling and settings.multisamples > 0:
        buffer_multisamples = settings.multisamples

    manager = FilterManager(showbase.win, showbase.cam)
    color_buffer = Texture()
    if settings.use_inverse_z:
        render.set_attrib(DepthTestAttrib.make(DepthTestAttrib.M_greater))
        depth_buffer = Texture()
        showbase.win.set_clear_depth(0)
        float_depth = True
        depth_bits = 24
    else:
        depth_buffer = None
        float_depth = False
        depth_bits = 1
    if settings.render_scene_to_float:
        if settings.floating_point_buffer:
            rgba_bits = (32, 32, 32, 32)
            float_colors = True
        else:
            print(
                "Floating point buffer not available, sRBG conversion will show artifacts"
            )
            rgba_bits = (1, 1, 1, 1)
            float_colors = False
    else:
        rgba_bits = (1, 1, 1, 1)
        float_colors = False
    textures = {'color': color_buffer, 'depth': depth_buffer}
    fbprops = FrameBufferProperties()
    fbprops.setFloatColor(float_colors)
    fbprops.setRgbaBits(*rgba_bits)
    fbprops.setSrgbColor(settings.srgb_buffer)
    fbprops.setDepthBits(depth_bits)
    fbprops.setFloatDepth(float_depth)
    fbprops.setMultisamples(buffer_multisamples)
    final_quad = manager.render_scene_into(textures=textures, fbprops=fbprops)
    final_quad_shader = PostProcessShader(
        gamma_correction=settings.software_srgb,
        hdr=settings.use_hdr).create_shader()
    final_quad.set_shader(final_quad_shader)
    final_quad.set_shader_input("color_buffer", color_buffer)
    final_quad.set_shader_input("exposure", 2)
Esempio n. 15
0
 def createBuffer(self,
                  name,
                  xsize,
                  ysize,
                  texgroup,
                  depthbits=1,
                  fbprops=None):
     """
     overload direct.filters.FilterManager.createBuffer
     :param name:
     :param xsize:
     :param ysize:
     :param texgroup:
     :param depthbits:
     :param fbprops:
     :return:
     """
     winprops = WindowProperties()
     winprops.setSize(xsize, ysize)
     props = FrameBufferProperties(FrameBufferProperties.getDefault())
     props.setBackBuffers(0)
     props.setRgbColor(1)
     props.setDepthBits(depthbits)
     props.setStereo(self.win.isStereo())
     if fbprops is not None:
         props.addProperties(fbprops)
     depthtex, colortex, auxtex0, auxtex1 = texgroup
     if (auxtex0 != None):
         props.setAuxRgba(1)
     if (auxtex1 != None):
         props.setAuxRgba(2)
     buffer = base.graphicsEngine.makeOutput(
         self.win.getPipe(), name, -1, props, winprops,
         GraphicsPipe.BFRefuseWindow | GraphicsPipe.BFResizeable,
         self.win.getGsg(), self.win)
     if (buffer == None):
         return buffer
     if (colortex):
         buffer.addRenderTexture(colortex, GraphicsOutput.RTMBindOrCopy,
                                 GraphicsOutput.RTPColor)
     if (depthtex):
         buffer.addRenderTexture(depthtex, GraphicsOutput.RTMBindOrCopy,
                                 GraphicsOutput.RTPDepth)
     if (auxtex0):
         buffer.addRenderTexture(auxtex0, GraphicsOutput.RTMBindOrCopy,
                                 GraphicsOutput.RTPAuxRgba0)
     if (auxtex1):
         buffer.addRenderTexture(auxtex1, GraphicsOutput.RTMBindOrCopy,
                                 GraphicsOutput.RTPAuxRgba1)
     buffer.setSort(self.nextsort)
     buffer.disableClears()
     self.nextsort += 1
     return buffer
Esempio n. 16
0
    def createBuffer(self,
                     name,
                     xsize,
                     ysize,
                     texgroup,
                     rgbabits=(1, 1, 1, 1),
                     floatcolor=False,
                     srgb=False,
                     depthbits=1,
                     floatdepth=False,
                     multisamples=0):
        """ Low-level buffer creation.  Not intended for public use. """

        depthtex, colortex, auxtex0, auxtex1 = texgroup
        winprops = WindowProperties()
        winprops.setSize(xsize, ysize)
        props = FrameBufferProperties(FrameBufferProperties.getDefault())
        props.setBackBuffers(0)
        props.setRgbColor(colortex is not None)
        props.setFloatColor(floatcolor)
        props.setRgbaBits(*rgbabits)
        props.setSrgbColor(srgb)
        props.setDepthBits(depthbits)
        props.setFloatDepth(floatdepth)
        props.setStereo(self.win.isStereo())
        props.setMultisamples(multisamples)
        if (auxtex0 != None):
            props.setAuxRgba(1)
        if (auxtex1 != None):
            props.setAuxRgba(2)
        buffer = base.graphicsEngine.makeOutput(
            self.win.getPipe(), name, -1, props, winprops,
            GraphicsPipe.BFRefuseWindow | GraphicsPipe.BFResizeable,
            self.win.getGsg(), self.win)
        if (buffer == None):
            return buffer
        if (depthtex):
            buffer.addRenderTexture(depthtex, GraphicsOutput.RTMBindOrCopy,
                                    GraphicsOutput.RTPDepth)
        if (colortex):
            buffer.addRenderTexture(colortex, GraphicsOutput.RTMBindOrCopy,
                                    GraphicsOutput.RTPColor)
        if (auxtex0):
            buffer.addRenderTexture(auxtex0, GraphicsOutput.RTMBindOrCopy,
                                    GraphicsOutput.RTPAuxRgba0)
        if (auxtex1):
            buffer.addRenderTexture(auxtex1, GraphicsOutput.RTMBindOrCopy,
                                    GraphicsOutput.RTPAuxRgba1)
        buffer.setSort(self.nextsort)
        buffer.disableClears()
        self.nextsort += 1
        return buffer
Esempio n. 17
0
    def init_fbp():
        """Initial / default FrameBufferProperties.

        Return:
            (FrameBufferProperties): FrameBufferProperties object.

        """
        fbp = FrameBufferProperties()
        fbp.setRgbColor(1)
        fbp.setColorBits(1)
        fbp.setAlphaBits(1)
        fbp.setDepthBits(1)
        return fbp
Esempio n. 18
0
    def _initRgbCapture(self):

        for camera in self.cameras:

            camNode = Camera('Semantic camera')
            camNode.setCameraMask(self.cameraMask)
            lens = PerspectiveLens()
            lens.setFov(self.fov)
            lens.setAspectRatio(float(self.size[0]) / float(self.size[1]))
            lens.setNear(self.zNear)
            lens.setFar(self.zFar)
            camNode.setLens(lens)
            camNode.setScene(self.scene.scene)
            cam = camera.attachNewNode(camNode)

            winprops = WindowProperties.size(self.size[0], self.size[1])
            fbprops = FrameBufferProperties.getDefault()
            fbprops = FrameBufferProperties(fbprops)
            fbprops.setRgbaBits(8, 8, 8, 8)

            flags = GraphicsPipe.BFFbPropsOptional
            if self.mode == 'onscreen':
                flags = flags | GraphicsPipe.BFRequireWindow
            elif self.mode == 'offscreen':
                flags = flags | GraphicsPipe.BFRefuseWindow
            else:
                raise Exception('Unsupported rendering mode: %s' % (self.mode))

            buf = self.graphicsEngine.makeOutput(self.pipe,
                                                 'RGB-buffer-Semantics', 0,
                                                 fbprops, winprops, flags)
            if buf is None:
                raise Exception('Unable to create RGB buffer')

            # Set to render at the end
            buf.setSort(10000)

            dr = buf.makeDisplayRegion()
            dr.setSort(0)
            dr.setCamera(cam)
            dr = camNode.getDisplayRegion(0)

            tex = Texture()
            tex.setFormat(Texture.FRgba8)
            tex.setComponentType(Texture.TUnsignedByte)
            buf.addRenderTexture(tex, GraphicsOutput.RTMCopyRam,
                                 GraphicsOutput.RTPColor)
            # XXX: should use tex.setMatchFramebufferFormat(True)?

            self.rgbBuffers[camera.getNetTag('agent-id')] = buf
            self.rgbTextures[camera.getNetTag('agent-id')] = tex
Esempio n. 19
0
    def createBuffer(self,
                     name,
                     xsize,
                     ysize,
                     texgroup,
                     depthbits=True,
                     fbprops=None):
        """ Low-level buffer creation.  Not intended for public use. """

        winprops = WindowProperties()
        winprops.setSize(xsize, ysize)
        props = FrameBufferProperties(FrameBufferProperties.getDefault())
        props.setBackBuffers(0)
        props.setRgbColor(1)
        if depthbits is True:
            # Respect depth-bits from Config.prc
            if props.getDepthBits() == 0:
                props.setDepthBits(1)
        else:
            props.setDepthBits(depthbits)
        props.setStereo(self.win.isStereo())
        if fbprops is not None:
            props.addProperties(fbprops)

        depthtex, colortex, auxtex0, auxtex1 = texgroup
        if auxtex0 is not None:
            props.setAuxRgba(1)
        if auxtex1 is not None:
            props.setAuxRgba(2)
        buffer = base.graphicsEngine.makeOutput(
            self.win.getPipe(), name, -1, props, winprops,
            GraphicsPipe.BFRefuseWindow | GraphicsPipe.BFResizeable,
            self.win.getGsg(), self.win)
        if buffer is None:
            return buffer
        if depthtex:
            buffer.addRenderTexture(depthtex, GraphicsOutput.RTMBindOrCopy,
                                    GraphicsOutput.RTPDepth)
        if colortex:
            buffer.addRenderTexture(colortex, GraphicsOutput.RTMBindOrCopy,
                                    GraphicsOutput.RTPColor)
        if auxtex0:
            buffer.addRenderTexture(auxtex0, GraphicsOutput.RTMBindOrCopy,
                                    GraphicsOutput.RTPAuxRgba0)
        if auxtex1:
            buffer.addRenderTexture(auxtex1, GraphicsOutput.RTMBindOrCopy,
                                    GraphicsOutput.RTPAuxRgba1)
        buffer.setSort(self.nextsort)
        buffer.disableClears()
        self.nextsort += 1
        return buffer
Esempio n. 20
0
    def build_offscreen_camera(
        self,
        name: str,
        mask: int,
        width: int,
        height: int,
        resolution: float,
    ) -> Renderer.OffscreenCamera:
        """Generates a new offscreen camera."""
        # setup buffer
        win_props = WindowProperties.size(width, height)
        fb_props = FrameBufferProperties()
        fb_props.setRgbColor(True)
        fb_props.setRgbaBits(8, 8, 8, 1)
        # XXX: Though we don't need the depth buffer returned, setting this to 0
        #      causes undefined behavior where the ordering of meshes is random.
        fb_props.setDepthBits(8)

        buffer = self._showbase_instance.win.engine.makeOutput(
            self._showbase_instance.pipe,
            "{}-buffer".format(name),
            -100,
            fb_props,
            win_props,
            GraphicsPipe.BFRefuseWindow,
            self._showbase_instance.win.getGsg(),
            self._showbase_instance.win,
        )
        buffer.setClearColor((0, 0, 0, 0))  # Set background color to black

        # setup texture
        tex = Texture()
        region = buffer.getDisplayRegion(0)
        region.window.addRenderTexture(tex, GraphicsOutput.RTM_copy_ram,
                                       GraphicsOutput.RTP_color)

        # setup camera
        lens = OrthographicLens()
        lens.setFilmSize(width * resolution, height * resolution)

        camera_np = self._showbase_instance.makeCamera(buffer,
                                                       camName=name,
                                                       scene=self._root_np,
                                                       lens=lens)
        camera_np.reparentTo(self._root_np)

        # mask is set to make undesirable objects invisible to this camera
        camera_np.node().setCameraMask(camera_np.node().getCameraMask() & mask)

        return Renderer.OffscreenCamera(camera_np, buffer, tex, self)
Esempio n. 21
0
 def makeFBO(self, name):
     # This routine creates an offscreen buffer.  All the complicated
     # parameters are basically demanding capabilities from the offscreen
     # buffer - we demand that it be able to render to texture on every
     # bitplane, that it can support aux bitplanes, that it track
     # the size of the host window, that it can render to texture
     # cumulatively, and so forth.
     winprops = WindowProperties()
     props = FrameBufferProperties()
     props.setRgbColor(1)
     return self.graphicsEngine.makeOutput(
         self.pipe, "model buffer", -2, props, winprops,
         GraphicsPipe.BFSizeTrackHost | GraphicsPipe.BFRefuseWindow,
         self.win.getGsg(), self.win)
Esempio n. 22
0
def makeOffscreenBuffer() -> GraphicsOutput:
    fb_prop = FrameBufferProperties()
    fb_prop.setRgbColor(True)
    fb_prop.setRgbaBits(8, 8, 8, 8)
    fb_prop.setDepthBits(16)

    # Create a WindowProperties object set to 512x512 size.
    win_prop = WindowProperties.size(w, h)

    # Don't open a window - force it to be an offscreen buffer.
    flags = GraphicsPipe.BF_refuse_window

    return base.graphicsEngine.make_output(base.pipe, "My Buffer", -100,
                                           fb_prop, win_prop, flags,
                                           base.win.getGsg(), base.win)
Esempio n. 23
0
def test_aux_buffer(base):
    props = FrameBufferProperties()
    props.set_aux_rgba(1)
    buffer = base.win.make_texture_buffer("testBuffer",
                                          256,
                                          256,
                                          to_ram=False,
                                          fbp=props)
    if buffer is not None:
        supported = True
        buffer.set_active(False)
        base.graphicsEngine.removeWindow(buffer)
    else:
        supported = False
    return supported
Esempio n. 24
0
    def _make_properties(self):
        """ Creates the window and buffer properties """
        window_props = WindowProperties.size(self._size.x, self._size.y)
        buffer_props = FrameBufferProperties()

        if self._size_constraint.x == 0 or self._size_constraint.y == 0:
            window_props = WindowProperties.size(1, 1)

        if self._color_bits == (16, 16, 16, 0):
            if RenderTarget.USE_R11G11B10:
                buffer_props.set_rgba_bits(11, 11, 10, 0)
            else:
                buffer_props.set_rgba_bits(*self._color_bits)
        elif 8 in self._color_bits:
            # When specifying 8 bits, specify 1 bit, this is a workarround
            # to a legacy logic in panda
            buffer_props.set_rgba_bits(
                *[i if i != 8 else 1 for i in self._color_bits])
        else:
            buffer_props.set_rgba_bits(*self._color_bits)

        buffer_props.set_accum_bits(0)
        buffer_props.set_stencil_bits(0)
        buffer_props.set_back_buffers(0)
        buffer_props.set_coverage_samples(0)
        buffer_props.set_depth_bits(self._depth_bits)

        if self._depth_bits == 32:
            buffer_props.set_float_depth(True)

        buffer_props.set_float_color(max(self._color_bits) > 8)

        buffer_props.set_force_hardware(True)
        buffer_props.set_multisamples(0)
        buffer_props.set_srgb_color(False)
        buffer_props.set_stereo(False)
        buffer_props.set_stencil_bits(0)

        if self._aux_bits == 8:
            buffer_props.set_aux_rgba(self._aux_count)
        elif self._aux_bits == 16:
            buffer_props.set_aux_hrgba(self._aux_count)
        elif self._aux_bits == 32:
            buffer_props.set_aux_float(self._aux_count)
        else:
            self.error("Invalid aux bits")

        return window_props, buffer_props
Esempio n. 25
0
 def make_buffer(self, width, height, texture_format):
     self.width = width
     self.height = height
     self.root = NodePath("root")
     props = FrameBufferProperties()
     props.set_srgb_color(False)
     if texture_format == Texture.F_rgb:
         props.set_float_color(False)
         props.set_rgba_bits(8, 8, 8, 0)
     elif texture_format == Texture.F_rgba:
         props.set_float_color(False)
         props.set_rgba_bits(8, 8, 8, 8)
     elif texture_format == Texture.F_r32:
         props.set_float_color(True)
         props.set_rgba_bits(32, 0, 0, 0)
     elif texture_format == Texture.F_rgb32:
         props.set_float_color(True)
         props.set_rgba_bits(32, 32, 32, 0)
     elif texture_format == Texture.F_rgba32:
         props.set_float_color(True)
         props.set_rgba_bits(32, 32, 32, 32)
     self.buffer = base.win.make_texture_buffer("generatorBuffer",
                                                width,
                                                height,
                                                to_ram=True,
                                                fbp=props)
     #print(self.buffer.get_fb_properties(), self.buffer.get_texture())
     self.buffer.setOneShot(True)
     #the camera for the buffer
     cam = base.makeCamera(win=self.buffer)
     cam.reparent_to(self.root)
     cam.set_pos(width / 2, height / 2, 100)
     cam.set_p(-90)
     lens = OrthographicLens()
     lens.set_film_size(width, height)
     cam.node().set_lens(lens)
     #plane with the texture
     cm = CardMaker("plane")
     cm.set_frame(0, width, 0, height)
     x_margin = 1.0 / width / 2.0
     y_margin = 1.0 / height / 2.0
     cm.set_uv_range((-x_margin, -y_margin), (1 + x_margin, 1 + y_margin))
     self.quad = self.root.attach_new_node(cm.generate())
     self.quad.look_at(0, 0, -1)
     taskMgr.add(self.check_generation, 'check_generation', sort=-10000)
     taskMgr.add(self.callback, 'callback', sort=-9999)
     print("Created offscreen buffer, size: %dx%d" % (width, height),
           "format:", Texture.formatFormat(texture_format))
Esempio n. 26
0
    def _build_offscreen_camera(
        self,
        name: str,
        mask: int,
        width: int,
        height: int,
        resolution: float,
    ):
        # setup buffer
        win_props = WindowProperties.size(width, height)
        fb_props = FrameBufferProperties()
        fb_props.setRgbColor(True)
        fb_props.setRgbaBits(8, 8, 8, 1)
        fb_props.setDepthBits(0)

        buffer = self._showbase.win.engine.makeOutput(
            self._showbase.pipe,
            "{}-buffer".format(name),
            -100,
            fb_props,
            win_props,
            GraphicsPipe.BFRefuseWindow,
            self._showbase.win.getGsg(),
            self._showbase.win,
        )
        buffer.setClearColor((0, 0, 0, 0))  # Set background color to black

        # setup texture
        tex = Texture()
        region = buffer.getDisplayRegion(0)
        region.window.addRenderTexture(tex, GraphicsOutput.RTM_copy_ram,
                                       GraphicsOutput.RTP_color)

        # setup camera
        lens = OrthographicLens()
        lens.setFilmSize(width * resolution, height * resolution)

        camera_np = self._showbase.makeCamera(buffer,
                                              camName=name,
                                              scene=self._scene_np,
                                              lens=lens)
        camera_np.reparentTo(self._scene_np)

        # mask is set to make undesireable objects invisible to this camera
        camera_np.node().setCameraMask(camera_np.node().getCameraMask() & mask)

        return OffscreenCamera(camera_np, buffer, tex)
Esempio n. 27
0
def test_floating_point_buffer(rgba_bits):
    props = FrameBufferProperties()
    props.set_srgb_color(False)
    props.set_float_color(True)
    props.set_rgba_bits(*rgba_bits)
    buffer = base.win.make_texture_buffer("testBuffer",
                                          256,
                                          256,
                                          to_ram=True,
                                          fbp=props)
    if buffer is not None:
        supported = True
        buffer.set_active(False)
        base.graphicsEngine.removeWindow(buffer)
    else:
        supported = False
    return supported
Esempio n. 28
0
def gsg(graphics_pipe, graphics_engine):
    "Returns a windowless GSG that can be used for offscreen rendering."
    from panda3d.core import GraphicsPipe, FrameBufferProperties, WindowProperties

    fbprops = FrameBufferProperties()
    fbprops.force_hardware = True

    buffer = graphics_engine.make_output(graphics_pipe, 'buffer', 0, fbprops,
                                         WindowProperties.size(32, 32),
                                         GraphicsPipe.BF_refuse_window)
    graphics_engine.open_windows()

    assert buffer is not None
    yield buffer.gsg

    if buffer is not None:
        graphics_engine.remove_window(buffer)
 def getBuff(self,width,height):
     size=(width,height)
     
     if size in self.buffs:
         buff=self.buffs[size]
     else:
         mainWindow=base.win
         fbp=FrameBufferProperties(mainWindow.getFbProperties())
         #print fbp.getColorBits()
         fbp.setColorBits(24*2)
         fbp.setDepthBits(0)
         fbp.setAlphaBits(0)
         buff=mainWindow.makeTextureBuffer('QueueBuff'+str(size),width,height,Texture(),True)
         dr=buff.makeDisplayRegion(0, 1, 0, 1)
         self.buffs[size]=buff
         self.displayRegions[buff]=dr
         print "saved buffer "+str(size)
         
     return buff
Esempio n. 30
0
    def __init__(self,
                 frame_size=None,
                 force_hardware=True,
                 MSAA_samples=0,
                 CSAA_samples=0,
                 sRGB_color=False):
        """Renderer based on Panda3D

        Keyword Arguments:
            frame_size {tuple} -- frame size (default: {256, 256})
            force_hardware {bool} -- force hardware rendering (default: {True})
            MSAA_samples {int} -- MSAA (Multi-Sampling Anti-Aliasing) level (default: {0})
            CSAA_samples {int} -- CSAA (Coverage Sampling Antialiasing) level (default: {0})
            sRGB_color {bool} -- apply sRGB colorspace gamma correction (default: {False})
        """
        BaseRenderer.__init__(self)
        self.return_to_bullet = True
        # renderer
        loadPrcFileData(
            "", f"""
            gl-compile-and-execute 1
            gl-use-bindless-texture 1
            prefer-texture-buffer 1
            """)

        fbp = FrameBufferProperties(FrameBufferProperties.getDefault())
        fbp.set_force_hardware(force_hardware)
        fbp.set_force_software(not force_hardware)
        fbp.set_multisamples(MSAA_samples)
        fbp.set_coverage_samples(CSAA_samples)
        fbp.set_srgb_color(sRGB_color)
        self._renderer = OffscreenRenderer(frame_size, fbp)
        self._loader = Loader.Loader(None)
        # scene
        self.scene = NodePath('render')
        self.scene.setAttrib(RescaleNormalAttrib.makeDefault())
        self.scene.setTwoSided(False)
        self.scene.setAntialias(AntialiasAttrib.MAuto)
        self.scene.setShaderAuto()
        self._light = PbLightNode(self.scene)
        self._camera = PbCameraNode(self.scene)
        self._node_dict = {}