Help with setting up off screen buffer

I am attempting to create an off screen buffer to create a glowing effect. I plan on applying a shader to certain nodes on an offscreen buffer and compositing the camera for the off screen buffer with the main camera.

    winX = base.win.getXSize()
    winY = base.win.getYSize()
    self.dr = base.win.getDisplayRegion(0)

    winprops = WindowProperties.size(base.win.getXSize(), base.win.getYSize())
    fbprops = FrameBufferProperties()
    fbprops.setDepthBits(1)
    self.buffer = base.graphicsEngine.makeOutput(
        base.pipe, "depth buffer", -100,
        fbprops, winprops,
        GraphicsPipe.BFRefuseWindow,
        base.win.getGsg(), base.win)
    
    self.depthTex = Texture()
    self.depthTex.setFormat(Texture.FDepthComponent)
    self.colorTex = Texture()
    self.buffer.addRenderTexture(self.colorTex, 
    GraphicsOutput.RTMCopyRam)

    self.buffer.addRenderTexture(self.depthTex,
        GraphicsOutput.RTMCopyRam, GraphicsOutput.RTPDepth)

    self.bufferCam = base.makeCamera(self.buffer, scene=render)
    self.bufferCam.reparent_to(render)

    self.filters = FilterManager(self.buffer, self.bufferCam)
    self.quad = self.filters.renderSceneInto(colortex=self.colorTex, depthtex=self.depthTex)
    
    self.quad.setShader(Shader.load(Shader.SL_GLSL, "sders/vertex.glsl", "sders/fragment.glsl"))
    self.quad.setShaderInput("tex", self.colorTex)
    self.quad.setShaderInput("dtex", self.depthTex)

how do I make the buffer render every frame? Also how can I view the buffer for debugging purposes? I have enabled show-buffers in the prc data. Any help is greatly appreciated!

In fact, the buffer is already being rendered every frame.

Use a convenient tool for this.
https://docs.panda3d.org/1.10/python/reference/direct.showbase.BufferViewer

Ah, I see you have created your own window, this method will not suit you, you can assign a self.depthTex texture to any mesh, or use:
https://docs.panda3d.org/1.10/python/reference/panda3d.core.CardMaker#panda3d.core.CardMaker

2 Likes

I see, ‘BufferViewer’ seems very helpful.
I’m assuming that calling ‘WindowProperties’ creates a new window?

How can I set up the buffer without creating a new window? I would like to be able to use ‘BufferViewer’

Sorry, I didn’t pay attention to the flag. If you haven’t created your own window after all, then this should work.

https://docs.panda3d.org/1.10/python/programming/rendering-process/creating-windows-and-buffers#creating-windows-and-buffers

from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties, FrameBufferProperties, GraphicsPipe, Texture, GraphicsOutput

class MyApp(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)

        scene = loader.loadModel("models/environment")
        scene.reparentTo(render)

        winprops = WindowProperties.size(base.win.getXSize(), base.win.getYSize())

        fbprops = FrameBufferProperties()
        fbprops.setDepthBits(1)

        self.buffer = base.graphicsEngine.makeOutput(base.pipe, 
                                                     "depth buffer",
                                                     -100, 
                                                     fbprops,
                                                     winprops,
                                                     GraphicsPipe.BFRefuseWindow,
                                                     base.win.getGsg(),
                                                     base.win)

        self.display_region = self.buffer.makeDisplayRegion()
        self.display_region.setActive(True)
        self.display_region.camera = base.cam
        
        self.depthTex = Texture()

        self.buffer.addRenderTexture(self.depthTex, GraphicsOutput.RTMCopyTexture, GraphicsOutput.RTPDepth)

        self.accept("v", base.bufferViewer.toggleEnable)

app = MyApp()
app.run()
#self.accept("v", base.bufferViewer.toggleEnable) # work 
base.bufferViewer.toggleEnable() # not work 

Interestingly, the call itself does not work without binding to the event key. Does anyone remember how it used to be?

1 Like

I don’t remember offhand–but it could simply be that it only works after some aspect of initial startup has been completed.

In particular, I note that the buffer-viewer also seems to work if run via a “doMethodLater” call with a duration of 0–thus running pretty much as soon as may be, but after initial startup. Like so:

    taskMgr.doMethodLater(0, self.mew, "mew")
    
def mew(self, task):
    self.bufferViewer.toggleEnable()

However, under such circumstances, the variable(show-buffers true) in the configuration file is useless. I doubt that this is the intended behavior.

1 Like

glotch