I’m completely lost here. All examples I’ve found seem to work for cg,
but even what I’ve set up seems not to work at all.
As usual do I not understand how Panda works.
I want to add a second texture my first shader can render to. If I am not mistaken,
a simple gl_FragColor[1] would address the additional output. Though when I try this,
it only outputs everything in green.
I’ve taken the createOffscreenBuffer from the web, but I don’t think it’s actually usefull.
I feel like things are overly complicated.
Anyhow.
def createOffscreenBuffer(self, sort, xsize, ysize, auxrgba=False, engine=None):
winprops = WindowProperties.size(xsize,ysize)
props = FrameBufferProperties()
props.setRgbColor(1)
props.setAlphaBits(1)
props.setDepthBits(1)
if auxrgba:
props.setAuxRgba(1)
if engine:
return engine.makeBuffer(base.win.getGsg(), "offscreen buff", sort, xsize, ysize)
return base.graphicsEngine.makeOutput(base.pipe, "offscreenBuffer",sort, props, winprops,
GraphicsPipe.BFRefuseWindow, base.win.getGsg(), base.win)
FirstPassBuffer = CardMaker("FirstPass")
FirstPass = NodePath(FirstPassBuffer.generate())
FirstPass.reparentTo(render)
FirstPass.setShader(Shader.load(Shader.SL_GLSL, vertex="v.glsl", fragment="f.glsl"))
FirstPass.attachNewNode(squareGN)
# the relevant part.
FirstPassPickingBuffer = createOffscreenBuffer(2, 1600,1000, True)
FirstPassPickingTexture = Texture()
FirstPassPickingBuffer.addRenderTexture(FirstPassPickingTexture, GraphicsOutput.RTMBindOrCopy,
GraphicsOutput.RTPColor)
from direct.filter.FilterManager import FilterManager
SecondPass = FilterManager(base.win, base.cam)
FirstPassOutput = Texture()
FirstPassOutput.setAnisotropicDegree(16)
FirstPassOutput.setMagfilter(Texture.FTLinear)
FirstPassOutput.setMinfilter(Texture.FTLinearMipmapLinear)
SecondPassOutput = SecondPass.renderSceneInto(colortex=FirstPassOutput)
SecondPassOutput.setShader(Shader.load(Shader.SL_GLSL, vertex="v2.glsl", fragment="f2.glsl"))
SecondPassOutput.setShaderInput("bla", FirstPassOutput)
SecondPassOutput.reparentTo(render2d)
base.setFrameRateMeter(True)
What this piece of code does is render something and then put it into a texture,
using the filtermanager, so I can run a second set of shaders over the output. That works flawlessly,
although I’m still confused about why it’s “SecondPass.renderSceneInto” instead of
“FirstPass.renderSceneInto” which would actually make sense. But whatever.
What’s important is “the relevant part”. I’ve gathered that this is the part that makes the texture
which then Panda magically adds, somehow, no idea how, as usual, because it’s all hidden.
So … how does it work?
What am I doing wrong?
How do I write to the texture?
Thanks!