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
An integer value, a union of several possible bitmask options defined by the GraphicsPipe class. This controls the type of GraphicsOutput we are requesting, for instance whether we want a window or buffer, or other exotic requirements. Set this to GraphicsPipe.BFRequireWindow
if you want to create a GraphicsWindow, or to GraphicsPipe.BFRefuseWindow
if you want to create a GraphicsBuffer. For more options, see the source code.
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