I’ll give it a shot soon, then, I intend!
[edit]
Okay, I believe that I’ve put together a fairly-minimal example:
In short, it ping-pongs between two buffers, both rendering the same off-screen scene to a texture. This texture is then fed into its counterpart’s buffer.
One of the textures thus produced is additionally added to an on-screen card, so that we can see it.
The specific rendering result is generated by a simple shader that just renders colour from a single point on the input-texture, sending it to both “color” and “color1”–presumably baseline colour and the aux-output, respectively.
As to that texture, it is initialised to blue via a call to “setClearColor” followed by a call to “clearImage”.
As a result, the output should be a blue card floating against the grey of the default window-clear.
As to use of the program:
Simply put, run the code below. As-is, you should find that it renders a blue square as intended.
Then go to about line 105, uncomment the first call to “addRenderTexture”, and comment-out the second call to “addRenderTexture” (just below the first). Where the buffer was rendering to aux, it should now be rendering to “color”.
Once again, run the code–on my machine, at least, it now renders black.
from direct.showbase.ShowBase import ShowBase
from panda3d.core import CardMaker, NodePath, Texture, GraphicsOutput, GraphicsPipe, \
FrameBufferProperties, Vec4, PandaNode, OrthographicLens, Vec2, Shader, WindowProperties
vert = """
#version 150
in vec4 p3d_Vertex;
uniform mat4 p3d_ModelViewProjectionMatrix;
void main()
{
gl_Position = p3d_ModelViewProjectionMatrix*p3d_Vertex;
}
"""
frag = """
#version 150
uniform sampler2D mew;
out vec4 color;
out vec4 color1;
void main()
{
color.xyz = texture(mew, vec2(0.5, 0.5)).xyz;
color.w = 1;
color1.xyz = texture(mew, vec2(0.5, 0.5)).xyz;
color1.w = 1;
}
"""
class GameCore(ShowBase):
def __init__(self):
ShowBase.__init__(self)
cardMaker = CardMaker("mew")
cardMaker.setFrame(-0.5, 0.5, -0.5, 0.5)
frameProperties = FrameBufferProperties()
frameProperties.setRgbaBits(8, 8, 8, 8)
frameProperties.setAuxRgba(4)
windowProperties = WindowProperties(self.win.getProperties())
windowProperties.setSize(512, 512)
self.testBuffer1, self.testCamera1, \
self.testTexture1, \
self.testRoot1, \
self.testPaintingCard1 = \
self.makeTestRenderer(frameProperties, windowProperties, cardMaker)
self.testBuffer2, self.testCamera2, \
self.testTexture2, \
self.testRoot2, \
self.testPaintingCard2 = \
self.makeTestRenderer(frameProperties, windowProperties, cardMaker)
self.testPaintingCard1.setShaderInput("mew", self.testTexture2)
self.testPaintingCard2.setShaderInput("mew", self.testTexture1)
self.testBuffer1.setActive(True)
self.testBuffer2.setActive(False)
self.activeBuffer = 1
self.testTexCard = self.render.attachNewNode(cardMaker.generate())
self.testTexCard.setScale(2.5)
self.testTexCard.setPos(2, 10, -1)
self.testTexCard.setTexture(self.testTexture2)
self.disableMouse()
self.taskMgr.add(self.update, "update")
def makeTestRenderer(self, frameProperties, windowProperties, cardMaker):
testRoot = NodePath(PandaNode("vel root"))
testPaintingCard = testRoot.attachNewNode(cardMaker.generate())
testPaintingCard.setY(10)
shader = Shader.make(Shader.SL_GLSL, vert, frag)
testPaintingCard.setShader(shader)
testBuffer = self.graphicsEngine.makeOutput(self.pipe, "Test Buffer", -1,
frameProperties, windowProperties,
GraphicsPipe.BFRefuseWindow, self.win.getGsg(), self.win)
testCamera = self.makeCamera(testBuffer)
testCamera.node().setScene(testRoot)
newLens = OrthographicLens()
newLens.setFilmSize(Vec2(1, 1))
newLens.setNearFar(5, 100)
testCamera.node().setLens(newLens)
testTexture = Texture()
testTexture.setWrapU(Texture.WM_clamp)
testTexture.setWrapV(Texture.WM_clamp)
"""
testBuffer.addRenderTexture(testTexture,
GraphicsOutput.RTMBindOrCopy,
GraphicsOutput.RTP_color)
"""
testBuffer.addRenderTexture(testTexture,
GraphicsOutput.RTMBindOrCopy,
GraphicsOutput.RTP_aux_rgba_0)
#"""
testTexture.setClearColor(Vec4(0, 0, 1, 1))
testTexture.clearImage()
return testBuffer, testCamera, testTexture, testRoot, testPaintingCard
def update(self, task):
if self.activeBuffer == 1:
self.testBuffer1.setActive(False)
self.testBuffer2.setActive(True)
self.activeBuffer = 2
else:
self.testBuffer2.setActive(False)
self.testBuffer1.setActive(True)
self.activeBuffer = 1
return task.cont
game = GameCore()
game.run()