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)
示例#2
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
示例#3
0
    def _initRgbCapture(self):

        for camera in self.cameras:

            camNode = Camera('RGB 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, 0)

            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-Rendering', 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.FRgb8)
            tex.setComponentType(Texture.TUnsignedByte)
            buf.addRenderTexture(tex, GraphicsOutput.RTMCopyRam,
                                 GraphicsOutput.RTPColor)
            # XXX: should use tex.setMatchFramebufferFormat(True)?

            agent = camera.getParent()
            self.rgbBuffers[agent.getName()] = buf
            self.rgbTextures[agent.getName()] = tex
示例#4
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
示例#5
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()
示例#6
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)
示例#7
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)
示例#8
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)
示例#9
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
示例#10
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 createBuffer(self, name, xsize, ysize, colortex, cmode, auxtex):

        winprops = WindowProperties.size(xsize, ysize)
        props = FrameBufferProperties()
        props.setColorBits(48)
        props.setRgbColor(0)

        if auxtex:
            props.setAuxHrgba(1)

        buffer = base.graphicsEngine.makeOutput(
            base.win.getPipe(), name, 1,
            props, winprops, GraphicsPipe.BFRefuseWindow,
            base.win.getGsg(), base.win)

        if (buffer == None):
            return buffer

        buffer.addRenderTexture(colortex, cmode, GraphicsOutput.RTPColor)

        if auxtex:
            buffer.addRenderTexture(auxtex, cmode, GraphicsOutput.RTPAuxHrgba0)

        buffer.setSort(-1)
        buffer.disableClears()
        buffer.getDisplayRegion(0).disableClears()
        return buffer
示例#12
0
文件: shader.py 项目: PlumpMath/yyagl
    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)
def makeOffscreenBuffer(name, sort) -> GraphicsOutput:
    fb_prop = FrameBufferProperties()
    fb_prop.setRgbColor(True)
    fb_prop.setRgbaBits(8, 8, 8, 8)
    fb_prop.setDepthBits(16)
    fb_prop.setFloatColor(True)

    # 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

    output = base.graphicsEngine.make_output(base.pipe, name, sort,
                                             fb_prop, win_prop, flags,
                                             base.win.getGsg(), base.win)

    # Should fix lag but doesn't work.
    # output.one_shot = True
    return output
    def makeFBO(self, name):
        """Creates an offscreen buffer with the specified name"""
        
        winprops = WindowProperties()
        props = FrameBufferProperties()
        props.setRgbColor(1)
        tex = Texture('Tex')
        gsg = base.win.getGsg()
        ge = base.graphicsEngine
        buffer = ge.makeOutput(base.pipe, 
                               name, 
                               -2, 
                               props, 
                               winprops,
                               GraphicsPipe.BFRefuseWindow | 
                               GraphicsPipe.BFFbPropsOptional, 
                               gsg, 
                               base.win)

        buffer.addRenderTexture(tex, GraphicsOutput.RTMCopyRam)
        return buffer
示例#15
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)
示例#16
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
示例#17
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)
示例#18
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)
示例#19
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)
示例#20
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()
示例#21
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)
示例#22
0
def window(graphics_pipe, graphics_engine):
    from panda3d.core import GraphicsPipe, FrameBufferProperties, WindowProperties

    fbprops = FrameBufferProperties.get_default()
    winprops = WindowProperties.get_default()

    win = graphics_engine.make_output(graphics_pipe, 'window', 0, fbprops,
                                      winprops, GraphicsPipe.BF_require_window)
    graphics_engine.open_windows()

    assert win is not None
    yield win

    if win is not None:
        graphics_engine.remove_window(win)
示例#23
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
 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
示例#25
0
def window(graphics_pipe, graphics_engine):
    from panda3d.core import GraphicsPipe, FrameBufferProperties, WindowProperties

    fbprops = FrameBufferProperties.get_default()
    winprops = WindowProperties.get_default()

    win = graphics_engine.make_output(
        graphics_pipe,
        'window',
        0,
        fbprops,
        winprops,
        GraphicsPipe.BF_require_window
    )
    graphics_engine.open_windows()

    assert win is not None
    yield win

    if win is not None:
        graphics_engine.remove_window(win)
 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
示例#27
0
    def __init__(self, screen_size=84):
        ShowBase.__init__(self)
        self.render.setShaderAuto()

        # Offscreen Buffer
        winprops = WindowProperties.size(screen_size, screen_size)
        fbprops = FrameBufferProperties()
        self.pipe = GraphicsPipeSelection.get_global_ptr().make_module_pipe(
            'pandagl')
        self.imageBuffer = self.graphicsEngine.makeOutput(
            self.pipe, "image buffer", 1, fbprops, winprops,
            GraphicsPipe.BFRefuseWindow)

        # Camera
        self.camera = Camera('cam')
        self.cam = NodePath(self.camera)
        self.cam.reparentTo(self.render)
        self.cam.setPos(0, 0, 7)
        self.cam.lookAt(0, 0, 0)

        #Display Region
        self.dr = self.imageBuffer.makeDisplayRegion()
        self.dr.setCamera(self.cam)

        # Spotlight with shadows
        self.light = Spotlight('light')
        self.lightNP = self.render.attachNewNode(self.light)
        self.lightNP.setPos(0, 10, 10)
        self.lightNP.lookAt(0, 0, 0)
        self.lightNP.node().setShadowCaster(True, 1024, 1024)
        self.render.setLight(self.lightNP)

        # Block
        node = PandaNode('Block')
        block_np = self.render.attachNewNode(node)
        model = loader.loadModel('box.egg')
        model.reparentTo(block_np)

        self.start_time = time.time()
    def createBuffer(self,
                     name,
                     xsize,
                     ysize,
                     texgroup,
                     depthbits=1,
                     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)
        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 (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
示例#29
0
    def create(self):
        """ Attempts to create this buffer """

        colorIsFloat = self._colorBits >= 16
        auxIsFloat = self._auxBits >= 16

        self.debug("Bitcount: color=" +str(self._colorBits) + "; aux="+str(self._auxBits) + "; depth=" + str(self._depthBits))


        # set wrap modes for color + auxtextures,
        # also set correct formats:
        # panda doesnt use sized formats automatically, this
        # gives problems when using imageLoad / imageStore
        prepare = [
            RenderTargetType.Color,
            RenderTargetType.Aux0,
            RenderTargetType.Aux1,
            RenderTargetType.Aux2,
            RenderTargetType.Aux3,
        ]

        for target in prepare:
            if not self.hasTarget(target):
                continue
            handle = self.getTarget(target)
            handle.setWrapU(Texture.WMClamp)
            handle.setWrapV(Texture.WMClamp)
            handle.setWrapW(Texture.WMClamp)
            handle.setMinfilter(Texture.FTLinear)
            handle.setMagfilter(Texture.FTLinear)
            handle.setAnisotropicDegree(0)

            if target == RenderTargetType.Color:
                if colorIsFloat:
                    handle.setComponentType(Texture.TFloat)

                if self._colorBits == 16:
                    handle.setFormat(Texture.FRgba16)
                elif self._colorBits == 32:
                    handle.setFormat(Texture.FRgba32)
            else:
                if auxIsFloat:
                    handle.setComponentType(Texture.TFloat)
                if self._auxBits == 16:
                    handle.setFormat(Texture.FRgba16)
                elif self._auxBits == 32:
                    handle.setFormat(Texture.FRgba32)

            if self._layers > 1:
                # handle.setup2dTextureArray(self._layers)
                handle.setup3dTexture(self._layers)

        # set layers for depth texture
        if self._layers > 1 and self.hasTarget(RenderTargetType.Depth):
            # self.getTarget(RenderTargetType.Depth).setup2dTextureArray(
                # self._layers)
            self.getTarget(RenderTargetType.Depth).setup3dTexture(
                self._layers)

        # Create buffer descriptors
        windowProps = WindowProperties.size(self._width, self._height)
        bufferProps = FrameBufferProperties()


        # Set color and alpha bits
        if self.hasTarget(RenderTargetType.Color):
            bufferProps.setColorBits(self._colorBits * 3)
            bufferProps.setAlphaBits(self._colorBits)

            if colorIsFloat:
                bufferProps.setFloatColor(True)

        # Set aux bits
        if self.hasTarget(RenderTargetType.Aux0) and auxIsFloat:

            # FRAMEBUFFER INCOMPLETE when using this to render to a 3d texture
            # bufferProps.setAuxFloat(True)

            pass

        # Set depth bits and depth texture format
        if self.hasTarget(RenderTargetType.Depth):
            depthTarget = self.getTarget(RenderTargetType.Depth)

            bufferProps.setDepthBits(self._depthBits)
            bufferProps.setFloatDepth(True)

        # We need no stencil (not supported yet)
        bufferProps.setStencilBits(0)

        numAuxtex = 0

        # Python really needs switch()
        if self.hasTarget(RenderTargetType.Aux3):
            numAuxtex = 4
        elif self.hasTarget(RenderTargetType.Aux2):
            numAuxtex = 3
        elif self.hasTarget(RenderTargetType.Aux1):
            numAuxtex = 2
        elif self.hasTarget(RenderTargetType.Aux0):
            numAuxtex = 1

        # Add aux textures (either 8 or 16 bit)
        if auxIsFloat:
            bufferProps.setAuxHrgba(numAuxtex)
        else:
            bufferProps.setAuxRgba(numAuxtex)

        bufferProps.setMultisamples(self._multisamples)

        # Create internal graphics output
        self._internalBuffer = self._engine.makeOutput(
            self._win.getPipe(), self._name, 1,
            bufferProps, windowProps,
            GraphicsPipe.BFRefuseWindow | GraphicsPipe.BFResizeable,
            self._win.getGsg(), self._win)

        if self._internalBuffer is None:
            self.error("Failed to create buffer :(")
            return False

        # Add render targets
        if self.hasTarget(RenderTargetType.Depth):
            self._internalBuffer.addRenderTexture(
                self.getTarget(RenderTargetType.Depth), self._bindMode,
                GraphicsOutput.RTPDepth)

        if self.hasTarget(RenderTargetType.Color):
            self._internalBuffer.addRenderTexture(
                self.getTarget(RenderTargetType.Color), self._bindMode,
                GraphicsOutput.RTPColor)

        modes = [
            (RenderTargetType.Aux0, GraphicsOutput.RTPAuxHrgba0,
             GraphicsOutput.RTPAuxRgba0),
            (RenderTargetType.Aux1, GraphicsOutput.RTPAuxHrgba1,
             GraphicsOutput.RTPAuxRgba1),
            (RenderTargetType.Aux2, GraphicsOutput.RTPAuxHrgba2,
             GraphicsOutput.RTPAuxRgba2),
            (RenderTargetType.Aux3, GraphicsOutput.RTPAuxHrgba3,
             GraphicsOutput.RTPAuxRgba3),
        ]

        for target, floatMode, normalMode in modes:
            if self.hasTarget(target):
                self._internalBuffer.addRenderTexture(
                    self.getTarget(target), self._bindMode,
                    floatMode if auxIsFloat else normalMode)

        # Increment global sort counter
        RenderBuffer.numBuffersAllocated += 1
        self._sort = -200 + RenderBuffer.numBuffersAllocated*10

        self.debug("our sort value is", self._sort)

        self._internalBuffer.setSort(self._sort)

        self._internalBuffer.disableClears()
        self._internalBuffer.getDisplayRegion(0).disableClears()

        self._internalBuffer.setClearStencilActive(False)

        if self.hasTarget(RenderTargetType.Depth):
            depthTarget = self.getTarget(RenderTargetType.Depth)

            if self._depthBits == 24:
                # depthTarget.setComponentType(Texture.TFloat)
                depthTarget.setFormat(Texture.FDepthComponent24)
            elif self._depthBits == 32:
                # depthTarget.setComponentType(Texture.TFloat)
                depthTarget.setFormat(Texture.FDepthComponent32)

        return True
示例#30
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)
示例#31
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
    def createBuffer(self, name, xsize, ysize, texgroup, depthbits=1):
        """ 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)
        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
示例#33
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)
    def _create(self):
        """ Attempts to create this buffer """

        # if len(self._targets.keys()) < 1:
            # print "WARNING:", self._debug_name, "has no attachments!"

        colorIsFloat = self._colorBits >= 16
        auxIsFloat = self._auxBits >= 16

        self.debug("Bitcount: color=" + str(self._colorBits) +
                   "; aux=" + str(self._auxBits) + "; depth=" + str(self._depthBits))

        # set wrap modes for color + auxtextures,
        # also set correct formats:
        # panda doesnt use sized formats automatically, this
        # gives problems when using imageLoad / imageStore
        prepare = [
            RenderTargetType.Color,
            RenderTargetType.Aux0,
            RenderTargetType.Aux1,
            RenderTargetType.Aux2,
            RenderTargetType.Aux3,
        ]

        for target in prepare:
            if not self.hasTarget(target):
                continue
            handle = self.getTarget(target)
            handle.setWrapU(Texture.WMClamp)
            handle.setWrapV(Texture.WMClamp)
            handle.setWrapW(Texture.WMClamp)
            handle.setMinfilter(Texture.FTLinear)
            handle.setMagfilter(Texture.FTLinear)
            handle.setAnisotropicDegree(0)

            handle.setXSize(self._width)
            handle.setYSize(self._height)

            if target == RenderTargetType.Color:
                if colorIsFloat:
                    handle.setComponentType(Texture.TFloat)

                if self._colorBits == 8:
                    if self._haveColorAlpha:
                        handle.setFormat(Texture.FRgba8)
                    else:
                        handle.setFormat(Texture.FRgb8)

                elif self._colorBits == 16:
                    if self._haveColorAlpha:
                        handle.setFormat(Texture.FRgba16)
                    else:
                        handle.setFormat(Texture.FRgb16)

                elif self._colorBits == 32:
                    if self._haveColorAlpha:
                        handle.setFormat(Texture.FRgba32)
                    else:
                        handle.setFormat(Texture.FRgb32)
            else:
                if auxIsFloat:
                    handle.setComponentType(Texture.TFloat)

                if self._auxBits == 8:
                    handle.setFormat(Texture.FRgba8)
                elif self._auxBits == 16:
                    handle.setFormat(Texture.FRgba16)
                elif self._auxBits == 32:
                    handle.setFormat(Texture.FRgba32)

            if self._layers > 1:
                if self._useTextureArrays:
                    handle.setup2dTextureArray(self._layers)
                else:
                    handle.setup3dTexture(self._layers)

        # set layers for depth texture
        if self._layers > 1 and self.hasTarget(RenderTargetType.Depth):
            if self._useTextureArrays:
                self.getTarget(RenderTargetType.Depth).setup2dTextureArray(
                    self._layers)
            else:
                self.getTarget(RenderTargetType.Depth).setup3dTexture(
                    self._layers)


        # Create buffer descriptors
        windowProps = WindowProperties.size(self._width, self._height)
        bufferProps = FrameBufferProperties()

        # Set color and alpha bits
        if self.hasTarget(RenderTargetType.Color):
            bufferProps.setRgbaBits(self._colorBits, self._colorBits, self._colorBits, self._colorBits if self._haveColorAlpha else 0)
            if colorIsFloat:
                bufferProps.setFloatColor(True)


        # Set aux bits
        if self.hasTarget(RenderTargetType.Aux0) and auxIsFloat:
            # FRAMEBUFFER INCOMPLETE when using this to render to a 3d texture
            # bufferProps.setAuxFloat(True)
            pass

        # Set depth bits and depth texture format
        if self.hasTarget(RenderTargetType.Depth):
            depthTarget = self.getTarget(RenderTargetType.Depth)

            bufferProps.setDepthBits(self._depthBits)
            bufferProps.setFloatDepth(True)

            if self._depthBits != 32:
                self.error("You cannot request a non-32bit float depth buffer! Requesting a non-float depth buffer instead")
                bufferProps.setFloatDepth(False)

            if self._depthBits == 16:
                # depthTarget.setComponentType(Texture.TFloat)
                depthTarget.setFormat(Texture.FDepthComponent16)
            if self._depthBits == 24:
                # depthTarget.setComponentType(Texture.TFloat)
                depthTarget.setFormat(Texture.FDepthComponent24)
            elif self._depthBits == 32:
                # depthTarget.setComponentType(Texture.TFloat)
                depthTarget.setFormat(Texture.FDepthComponent32)

            depthTarget.setXSize(self._width)
            depthTarget.setYSize(self._height)

        # We need no stencil (not supported yet)
        bufferProps.setStencilBits(0)

        numAuxtex = 0

        # Python really needs switch()
        # FIXME: Why is it 2 when only 1 AUX texture is attached?!
        if self.hasTarget(RenderTargetType.Aux3):
            numAuxtex = 3
        elif self.hasTarget(RenderTargetType.Aux2):
            numAuxtex = 3
        elif self.hasTarget(RenderTargetType.Aux1):
            numAuxtex = 2
        elif self.hasTarget(RenderTargetType.Aux0):
            numAuxtex = 1

        self.debug("Num Auxtex=", numAuxtex)

        # Add aux textures (either 8 or 16 bit)
        if auxIsFloat:
            bufferProps.setAuxHrgba(numAuxtex)
        else:
            bufferProps.setAuxRgba(numAuxtex)

        bufferProps.setMultisamples(self._multisamples)

        # Register the target for the memory monitoring
        MemoryMonitor.addRenderTarget(self._name, self)

        # Create internal graphics output
        self._internalBuffer = self._engine.makeOutput(
            self._sourceWindow.getPipe(), self._name, 1,
            bufferProps, windowProps,
            GraphicsPipe.BFRefuseWindow,
            self._sourceWindow.getGsg(), self._sourceWindow)

        if self._internalBuffer is None:
            self.error("Failed to create buffer :(")
            return False

        # Add render targets
        if self.hasTarget(RenderTargetType.Depth):
            self._internalBuffer.addRenderTexture(
                self.getTarget(RenderTargetType.Depth), self._bindMode,
                GraphicsOutput.RTPDepth)

        if self.hasTarget(RenderTargetType.Color):
            self._internalBuffer.addRenderTexture(
                self.getTarget(RenderTargetType.Color), self._bindMode,
                GraphicsOutput.RTPColor)

        modes = [
            (RenderTargetType.Aux0, GraphicsOutput.RTPAuxHrgba0,
             GraphicsOutput.RTPAuxRgba0),
            (RenderTargetType.Aux1, GraphicsOutput.RTPAuxHrgba1,
             GraphicsOutput.RTPAuxRgba1),
            (RenderTargetType.Aux2, GraphicsOutput.RTPAuxHrgba2,
             GraphicsOutput.RTPAuxRgba2),
            (RenderTargetType.Aux3, GraphicsOutput.RTPAuxHrgba3,
             GraphicsOutput.RTPAuxRgba3),
        ]


        for target, floatMode, normalMode in modes:
            if self.hasTarget(target):
                self._internalBuffer.addRenderTexture(
                    self.getTarget(target), self._bindMode,
                    floatMode if auxIsFloat else normalMode)

        # Increment global sort counter
        RenderTarget.numBuffersAllocated += 1
        self._sort = -300 + RenderTarget.numBuffersAllocated * 10

        self.debug("our sort value is", self._sort)
        self._internalBuffer.setSort(self._sort)
        self._internalBuffer.disableClears()
        self._internalBuffer.getDisplayRegion(0).disableClears()

        for i in xrange(16):
            self._internalBuffer.setClearActive(i, False)
            self._internalBuffer.getDisplayRegion(0).setClearActive(i, False)

        self._internalBuffer.setClearStencilActive(False)

        if self.hasTarget(RenderTargetType.Depth):
            depthTarget = self.getTarget(RenderTargetType.Depth)

            if self._depthBits == 16:
                # depthTarget.setComponentType(Texture.TFloat)
                depthTarget.setFormat(Texture.FDepthComponent16)
            elif self._depthBits == 24:
                # depthTarget.setComponentType(Texture.TFloat)
                depthTarget.setFormat(Texture.FDepthComponent24)
            elif self._depthBits == 32:
                # depthTarget.setComponentType(Texture.TFloat)
                depthTarget.setFormat(Texture.FDepthComponent32)

        return True
示例#35
0
    def _create(self):
        """ Attempts to create this buffer """

        # if len(self._targets.keys()) < 1:
        # print "WARNING:", self._debug_name, "has no attachments!"

        colorIsFloat = self._colorBits >= 16
        auxIsFloat = self._auxBits >= 16

        self.debug("Bitcount: color=" + str(self._colorBits) + "; aux=" +
                   str(self._auxBits) + "; depth=" + str(self._depthBits))

        # set wrap modes for color + auxtextures,
        # also set correct formats:
        # panda doesnt use sized formats automatically, this
        # gives problems when using imageLoad / imageStore
        prepare = [
            RenderTargetType.Color,
            RenderTargetType.Aux0,
            RenderTargetType.Aux1,
            RenderTargetType.Aux2,
            RenderTargetType.Aux3,
        ]

        for target in prepare:
            if not self.hasTarget(target):
                continue
            handle = self.getTarget(target)
            handle.setWrapU(Texture.WMClamp)
            handle.setWrapV(Texture.WMClamp)
            handle.setWrapW(Texture.WMClamp)
            handle.setMinfilter(Texture.FTLinear)
            handle.setMagfilter(Texture.FTLinear)
            handle.setAnisotropicDegree(0)

            handle.setXSize(self._width)
            handle.setYSize(self._height)

            if target == RenderTargetType.Color:
                if colorIsFloat:
                    handle.setComponentType(Texture.TFloat)

                if self._colorBits == 8:
                    if self._haveColorAlpha:
                        handle.setFormat(Texture.FRgba8)
                    else:
                        handle.setFormat(Texture.FRgb8)

                elif self._colorBits == 16:
                    if self._haveColorAlpha:
                        handle.setFormat(Texture.FRgba16)
                    else:
                        handle.setFormat(Texture.FRgb16)

                elif self._colorBits == 32:
                    if self._haveColorAlpha:
                        handle.setFormat(Texture.FRgba32)
                    else:
                        handle.setFormat(Texture.FRgb32)
            else:
                if auxIsFloat:
                    handle.setComponentType(Texture.TFloat)

                if self._auxBits == 8:
                    handle.setFormat(Texture.FRgba8)
                elif self._auxBits == 16:
                    handle.setFormat(Texture.FRgba16)
                elif self._auxBits == 32:
                    handle.setFormat(Texture.FRgba32)

            if self._layers > 1:
                if self._useTextureArrays:
                    handle.setup2dTextureArray(self._layers)
                else:
                    handle.setup3dTexture(self._layers)

        # set layers for depth texture
        if self._layers > 1 and self.hasTarget(RenderTargetType.Depth):
            if self._useTextureArrays:
                self.getTarget(RenderTargetType.Depth).setup2dTextureArray(
                    self._layers)
            else:
                self.getTarget(RenderTargetType.Depth).setup3dTexture(
                    self._layers)

        # Create buffer descriptors
        windowProps = WindowProperties.size(self._width, self._height)
        bufferProps = FrameBufferProperties()

        # Set color and alpha bits
        if self.hasTarget(RenderTargetType.Color):
            bufferProps.setRgbaBits(
                self._colorBits, self._colorBits, self._colorBits,
                self._colorBits if self._haveColorAlpha else 0)
            if colorIsFloat:
                bufferProps.setFloatColor(True)

        # Set aux bits
        if self.hasTarget(RenderTargetType.Aux0) and auxIsFloat:
            # FRAMEBUFFER INCOMPLETE when using this to render to a 3d texture
            # bufferProps.setAuxFloat(True)
            pass

        # Set depth bits and depth texture format
        if self.hasTarget(RenderTargetType.Depth):
            depthTarget = self.getTarget(RenderTargetType.Depth)

            bufferProps.setDepthBits(self._depthBits)
            bufferProps.setFloatDepth(True)

            if self._depthBits != 32:
                self.error(
                    "You cannot request a non-32bit float depth buffer! Requesting a non-float depth buffer instead"
                )
                bufferProps.setFloatDepth(False)

            if self._depthBits == 16:
                # depthTarget.setComponentType(Texture.TFloat)
                depthTarget.setFormat(Texture.FDepthComponent16)
            if self._depthBits == 24:
                # depthTarget.setComponentType(Texture.TFloat)
                depthTarget.setFormat(Texture.FDepthComponent24)
            elif self._depthBits == 32:
                # depthTarget.setComponentType(Texture.TFloat)
                depthTarget.setFormat(Texture.FDepthComponent32)

            depthTarget.setXSize(self._width)
            depthTarget.setYSize(self._height)

        # We need no stencil (not supported yet)
        bufferProps.setStencilBits(0)

        numAuxtex = 0

        # Python really needs switch()
        # FIXME: Why is it 2 when only 1 AUX texture is attached?!
        if self.hasTarget(RenderTargetType.Aux3):
            numAuxtex = 3
        elif self.hasTarget(RenderTargetType.Aux2):
            numAuxtex = 3
        elif self.hasTarget(RenderTargetType.Aux1):
            numAuxtex = 2
        elif self.hasTarget(RenderTargetType.Aux0):
            numAuxtex = 1

        self.debug("Num Auxtex=", numAuxtex)

        # Add aux textures (either 8 or 16 bit)
        if auxIsFloat:
            bufferProps.setAuxHrgba(numAuxtex)
        else:
            bufferProps.setAuxRgba(numAuxtex)

        bufferProps.setMultisamples(self._multisamples)

        # Register the target for the memory monitoring
        MemoryMonitor.addRenderTarget(self._name, self)

        # Create internal graphics output
        self._internalBuffer = self._engine.makeOutput(
            self._sourceWindow.getPipe(), self._name, 1, bufferProps,
            windowProps, GraphicsPipe.BFRefuseWindow,
            self._sourceWindow.getGsg(), self._sourceWindow)

        if self._internalBuffer is None:
            self.error("Failed to create buffer :(")
            return False

        # Add render targets
        if self.hasTarget(RenderTargetType.Depth):
            self._internalBuffer.addRenderTexture(
                self.getTarget(RenderTargetType.Depth), self._bindMode,
                GraphicsOutput.RTPDepth)

        if self.hasTarget(RenderTargetType.Color):
            self._internalBuffer.addRenderTexture(
                self.getTarget(RenderTargetType.Color), self._bindMode,
                GraphicsOutput.RTPColor)

        modes = [
            (RenderTargetType.Aux0, GraphicsOutput.RTPAuxHrgba0,
             GraphicsOutput.RTPAuxRgba0),
            (RenderTargetType.Aux1, GraphicsOutput.RTPAuxHrgba1,
             GraphicsOutput.RTPAuxRgba1),
            (RenderTargetType.Aux2, GraphicsOutput.RTPAuxHrgba2,
             GraphicsOutput.RTPAuxRgba2),
            (RenderTargetType.Aux3, GraphicsOutput.RTPAuxHrgba3,
             GraphicsOutput.RTPAuxRgba3),
        ]

        for target, floatMode, normalMode in modes:
            if self.hasTarget(target):
                self._internalBuffer.addRenderTexture(
                    self.getTarget(target), self._bindMode,
                    floatMode if auxIsFloat else normalMode)

        # Increment global sort counter
        RenderTarget.numBuffersAllocated += 1
        self._sort = -300 + RenderTarget.numBuffersAllocated * 10

        self.debug("our sort value is", self._sort)
        self._internalBuffer.setSort(self._sort)
        self._internalBuffer.disableClears()
        self._internalBuffer.getDisplayRegion(0).disableClears()

        for i in xrange(16):
            self._internalBuffer.setClearActive(i, False)
            self._internalBuffer.getDisplayRegion(0).setClearActive(i, False)

        self._internalBuffer.setClearStencilActive(False)

        if self.hasTarget(RenderTargetType.Depth):
            depthTarget = self.getTarget(RenderTargetType.Depth)

            if self._depthBits == 16:
                # depthTarget.setComponentType(Texture.TFloat)
                depthTarget.setFormat(Texture.FDepthComponent16)
            elif self._depthBits == 24:
                # depthTarget.setComponentType(Texture.TFloat)
                depthTarget.setFormat(Texture.FDepthComponent24)
            elif self._depthBits == 32:
                # depthTarget.setComponentType(Texture.TFloat)
                depthTarget.setFormat(Texture.FDepthComponent32)

        return True
示例#36
0
    def __init__(self, screen_size=84, DEBUGGING=False):
        ShowBase.__init__(self)
        self.render_stuff = True
        self.actions = 3

        self.render.setShaderAuto()
        self.cam.setPos(0, 0, 7)
        self.cam.lookAt(0, 0, 0)

        wp = WindowProperties()
        window_size = screen_size
        wp.setSize(window_size, window_size)
        self.win.requestProperties(wp)

        # Create Ambient Light
        self.ambientLight = AmbientLight('ambientLight')
        self.ambientLight.setColor((0.2, 0.2, 0.2, 1))
        self.ambientLightNP = self.render.attachNewNode(self.ambientLight)
        self.render.setLight(self.ambientLightNP)

        # Spotlight
        self.light = Spotlight('light')
        self.light.setColor((0.9, 0.9, 0.9, 1))
        self.lightNP = self.render.attachNewNode(self.light)
        self.lightNP.setPos(0, 10, 10)
        self.lightNP.lookAt(0, 0, 0)
        self.lightNP.node().getLens().setFov(40)
        self.lightNP.node().getLens().setNearFar(10, 100)
        self.lightNP.node().setShadowCaster(True, 1024, 1024)
        self.render.setLight(self.lightNP)

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))

        if DEBUGGING is True:
            debugNode = BulletDebugNode('Debug')
            debugNode.showWireframe(True)
            debugNode.showConstraints(True)
            debugNode.showBoundingBoxes(False)
            debugNode.showNormals(False)
            debugNP = render.attachNewNode(debugNode)
            debugNP.show()
            self.world.setDebugNode(debugNP.node())

        # Reward zone
        self.rzone_shape = BulletBoxShape(Vec3(.8, 1, 0.5))
        self.rzone_ghost = BulletGhostNode('Reward Zone')
        self.rzone_ghost.addShape(self.rzone_shape)
        self.rzone_ghostNP = self.render.attachNewNode(self.rzone_ghost)
        self.rzone_ghostNP.setPos(2.2, 0.0, 0.86)
        self.rzone_ghostNP.setCollideMask(BitMask32(0x0f))
        self.world.attachGhost(self.rzone_ghost)

        # 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)
示例#37
0
文件: conv_env.py 项目: Shirnia/l_sim
    def __init__(self, screen_size=84, DEBUGGING=False, human_playable=False):
        ShowBase.__init__(self)
        self.forward_button = KeyboardButton.ascii_key(b'w')
        self.backward_button = KeyboardButton.ascii_key(b's')

        self.fps = 20
        self.human_playable = human_playable
        self.actions = 3
        self.last_frame_start_time = time.time()
        self.action_buffer = [1, 1, 1]
        self.last_teleport_time = 0.0
        self.time_to_teleport = False

        if self.human_playable is False:
            winprops = WindowProperties.size(screen_size, screen_size)
            fbprops = FrameBufferProperties()
            fbprops.set_rgba_bits(8, 8, 8, 0)
            fbprops.set_depth_bits(24)
            self.pipe = GraphicsPipeSelection.get_global_ptr().make_module_pipe('pandagl')
            self.imageBuffer = self.graphicsEngine.makeOutput(
                self.pipe,
                "image buffer",
                1,
                fbprops,
                winprops,
                GraphicsPipe.BFRefuseWindow)


            self.camera = Camera('cam')
            self.cam = NodePath(self.camera)
            self.cam.reparentTo(self.render)

            self.dr = self.imageBuffer.makeDisplayRegion()
            self.dr.setCamera(self.cam)

        self.render.setShaderAuto()
        self.cam.setPos(0.5, 0, 6)
        self.cam.lookAt(0.5, 0, 0)

        # Create Ambient Light
        self.ambientLight = AmbientLight('ambientLight')
        self.ambientLight.setColor((0.2, 0.2, 0.2, 1))
        self.ambientLightNP = self.render.attachNewNode(self.ambientLight)
        self.render.setLight(self.ambientLightNP)

        # Spotlight
        self.light = Spotlight('light')
        self.light.setColor((0.9, 0.9, 0.9, 1))
        self.lightNP = self.render.attachNewNode(self.light)
        self.lightNP.setPos(0, 10, 10)
        self.lightNP.lookAt(0, 0, 0)
        self.lightNP.node().getLens().setFov(40)
        self.lightNP.node().getLens().setNearFar(10, 100)
        self.lightNP.node().setShadowCaster(True, 1024, 1024)
        self.render.setLight(self.lightNP)

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))

        if DEBUGGING is True:
            debugNode = BulletDebugNode('Debug')
            debugNode.showWireframe(True)
            debugNode.showConstraints(True)
            debugNode.showBoundingBoxes(False)
            debugNode.showNormals(False)
            debugNP = render.attachNewNode(debugNode)
            debugNP.show()
            self.world.setDebugNode(debugNP.node())

        self.finger_speed_mps = 0.0
        self.penalty_applied = False
        self.teleport_cooled_down = True
        self.fps = 20
        self.framecount = 0
        self.reset()
示例#38
0
    def __init__(self):
        # Set up the window, camera, etc.
        ShowBase.__init__(self)

        base.render.setAttrib(LightRampAttrib.makeHdr0())

        # Configure depth pre-pass
        prepass_pass = lionrender.DepthScenePass()

        # Configure scene pass
        scene_fb_props = FrameBufferProperties()
        scene_fb_props.set_rgb_color(True)
        scene_fb_props.set_rgba_bits(8, 8, 8, 0)
        scene_fb_props.set_depth_bits(32)
        scene_pass = lionrender.ScenePass(
            frame_buffer_properties=scene_fb_props,
            clear_color=LColor(0.53, 0.80, 0.92, 1),
            share_depth_with=prepass_pass)
        scene_pass.node_path.set_depth_write(False)

        # Configure post processing
        filter_pass = lionrender.FilterPass(fragment_path='shaders/fsq.frag')
        filter_pass.node_path.set_shader_input('inputTexture',
                                               scene_pass.output)

        # Enable FXAA
        fxaa_pass = lionrender.FxaaFilterPass()
        fxaa_pass.node_path.set_shader_input('inputTexture',
                                             filter_pass.output)

        # Output result
        fxaa_pass.output_to(render2d)

        # This is used to store which keys are currently pressed.
        self.keyMap = {
            "left": 0,
            "right": 0,
            "forward": 0,
            "backward": 0,
            "cam-left": 0,
            "cam-right": 0,
        }

        # Post the instructions
        self.title = addTitle(
            "Panda3D Tutorial: Roaming Ralph (Walking on Uneven Terrain)")
        self.inst1 = addInstructions(0.06, "[ESC]: Quit")
        self.inst2 = addInstructions(0.12, "[Left Arrow]: Rotate Ralph Left")
        self.inst3 = addInstructions(0.18, "[Right Arrow]: Rotate Ralph Right")
        self.inst4 = addInstructions(0.24, "[Up Arrow]: Run Ralph Forward")
        self.inst5 = addInstructions(0.30, "[Down Arrow]: Walk Ralph Backward")
        self.inst6 = addInstructions(0.36, "[A]: Rotate Camera Left")
        self.inst7 = addInstructions(0.42, "[S]: Rotate Camera Right")

        # Set up the environment
        #
        # This environment model contains collision meshes.  If you look
        # in the egg file, you will see the following:
        #
        #    <Collide> { Polyset keep descend }
        #
        # This tag causes the following mesh to be converted to a collision
        # mesh -- a mesh which is optimized for collision, not rendering.
        # It also keeps the original mesh, so there are now two copies ---
        # one optimized for rendering, one for collisions.

        self.environ = loader.loadModel("models/world")
        self.environ.reparentTo(render)

        # We do not have a skybox, so we will just use a sky blue background color
        self.setBackgroundColor(0.53, 0.80, 0.92, 1)

        # Create the main character, Ralph

        ralphStartPos = self.environ.find("**/start_point").getPos()
        self.ralph = Actor("models/ralph", {
            "run": "models/ralph-run",
            "walk": "models/ralph-walk"
        })
        self.ralph.reparentTo(render)
        self.ralph.setScale(.2)
        self.ralph.setPos(ralphStartPos + (0, 0, 1.5))

        # Create a floater object, which floats 2 units above ralph.  We
        # use this as a target for the camera to look at.

        self.floater = NodePath(PandaNode("floater"))
        self.floater.reparentTo(self.ralph)
        self.floater.setZ(2.0)

        # Accept the control keys for movement and rotation

        self.accept("escape", sys.exit)
        self.accept("arrow_left", self.setKey, ["left", True])
        self.accept("arrow_right", self.setKey, ["right", True])
        self.accept("arrow_up", self.setKey, ["forward", True])
        self.accept("arrow_down", self.setKey, ["backward", True])
        self.accept("a", self.setKey, ["cam-left", True])
        self.accept("s", self.setKey, ["cam-right", True])
        self.accept("arrow_left-up", self.setKey, ["left", False])
        self.accept("arrow_right-up", self.setKey, ["right", False])
        self.accept("arrow_up-up", self.setKey, ["forward", False])
        self.accept("arrow_down-up", self.setKey, ["backward", False])
        self.accept("a-up", self.setKey, ["cam-left", False])
        self.accept("s-up", self.setKey, ["cam-right", False])
        self.accept("v", self.toggleCards)

        taskMgr.add(self.move, "moveTask")

        # Set up the camera
        self.disableMouse()
        self.camera.setPos(self.ralph.getX(), self.ralph.getY() + 10, 2)

        self.cTrav = CollisionTraverser()

        # Use a CollisionHandlerPusher to handle collisions between Ralph and
        # the environment. Ralph is added as a "from" object which will be
        # "pushed" out of the environment if he walks into obstacles.
        #
        # Ralph is composed of two spheres, one around the torso and one
        # around the head.  They are slightly oversized since we want Ralph to
        # keep some distance from obstacles.
        self.ralphCol = CollisionNode('ralph')
        self.ralphCol.addSolid(CollisionSphere(center=(0, 0, 2), radius=1.5))
        self.ralphCol.addSolid(
            CollisionSphere(center=(0, -0.25, 4), radius=1.5))
        self.ralphCol.setFromCollideMask(CollideMask.bit(0))
        self.ralphCol.setIntoCollideMask(CollideMask.allOff())
        self.ralphColNp = self.ralph.attachNewNode(self.ralphCol)
        self.ralphPusher = CollisionHandlerPusher()
        self.ralphPusher.horizontal = True

        # Note that we need to add ralph both to the pusher and to the
        # traverser; the pusher needs to know which node to push back when a
        # collision occurs!
        self.ralphPusher.addCollider(self.ralphColNp, self.ralph)
        self.cTrav.addCollider(self.ralphColNp, self.ralphPusher)

        # We will detect the height of the terrain by creating a collision
        # ray and casting it downward toward the terrain.  One ray will
        # start above ralph's head, and the other will start above the camera.
        # A ray may hit the terrain, or it may hit a rock or a tree.  If it
        # hits the terrain, we can detect the height.
        self.ralphGroundRay = CollisionRay()
        self.ralphGroundRay.setOrigin(0, 0, 9)
        self.ralphGroundRay.setDirection(0, 0, -1)
        self.ralphGroundCol = CollisionNode('ralphRay')
        self.ralphGroundCol.addSolid(self.ralphGroundRay)
        self.ralphGroundCol.setFromCollideMask(CollideMask.bit(0))
        self.ralphGroundCol.setIntoCollideMask(CollideMask.allOff())
        self.ralphGroundColNp = self.ralph.attachNewNode(self.ralphGroundCol)
        self.ralphGroundHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.ralphGroundColNp, self.ralphGroundHandler)

        self.camGroundRay = CollisionRay()
        self.camGroundRay.setOrigin(0, 0, 9)
        self.camGroundRay.setDirection(0, 0, -1)
        self.camGroundCol = CollisionNode('camRay')
        self.camGroundCol.addSolid(self.camGroundRay)
        self.camGroundCol.setFromCollideMask(CollideMask.bit(0))
        self.camGroundCol.setIntoCollideMask(CollideMask.allOff())
        self.camGroundColNp = self.camera.attachNewNode(self.camGroundCol)
        self.camGroundHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.camGroundColNp, self.camGroundHandler)

        # Uncomment this line to see the collision rays
        #self.ralphColNp.show()
        #self.camGroundColNp.show()

        # Uncomment this line to show a visual representation of the
        # collisions occuring
        #self.cTrav.showCollisions(render)

        # Create some lighting
        ambientLight = AmbientLight("ambientLight")
        ambientLight.setColor((.3, .3, .3, 1))
        directionalLight = DirectionalLight("directionalLight")
        directionalLight.setDirection((-5, -5, -5))
        directionalLight.setColor((1, 1, 1, 1))
        directionalLight.setSpecularColor((1, 1, 1, 1))
        render.setLight(render.attachNewNode(ambientLight))
        render.setLight(render.attachNewNode(directionalLight))

        # Clean up texture attributes
        for texture in self.render.find_all_textures():
            texture.set_format(Texture.F_srgb)
示例#39
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._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)
        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:
            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
示例#40
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
示例#41
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
示例#42
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 = {}