I ran to two small problems that I haven’t quite figured out after half a day of searching around.
Firstly, is there an elegant way to fill a render target texture with an arbitrary color? Currently, it winds up looking like this:
The problematic child being the right texture in the two small buffer view windows. It doesn’t clear every frame.
[size=75]Secondly, from some reason, the scene (which is first rendered to those two textures shown in the buffer views) winds up looking kind of gray. I’m unsure why – the color of the texture card is set to 1, 1, 1, 1 and transparency to 1.[/size] – Err, nevermind. The shader was writing to alpha channel.
And as a bonus, is using GraphicsOutput.RTPAuxRgba0 the right way to do multiple rendering targets? That’s not using the aux buffer extension, is it? I also wonder if it is possible to render to the default FBO with an additional texture with a size that does not match the screen size, i.e. rendering both to screen and to a texture with the same pass? The purpose of the color-mess above is to do mouse picking against the terrain, but I’ll probably wind up having to use two-pass rendering to get depth testing and everything.
Now, some relevant code:
# Creating the buffer used to render terrain to self.terrain_buffer = self.createOffscreenBuffer(2, 2048, 2048, True) # Main texture self.terrain_color_txt = Texture() self.terrain_buffer.addRenderTexture(self.terrain_color_txt, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPColor) # Texture coordinate texture self.terrain_texcoord_txt = Texture() self.terrain_buffer.addRenderTexture(self.terrain_texcoord_txt, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPAuxRgba0) # Terrain scene camera self.terrain_camera = base.makeCamera(self.terrain_buffer, clearColor = Vec4(1.0,1.0,1.0, 1.0), lens = base.camLens) # Terrain scene, reparenting camera and terrain base self.terrain_scene = NodePath("TerrainScene") self.terrain_camera.reparentTo(self.terrain_scene) self.terrain_base.reparentTo(self.terrain_scene) # Card that is rendered to the main screen drawn_scene=self.terrain_buffer.getTextureCard() drawn_scene.setTransparency(1) drawn_scene.setColor(1,1,1,1) drawn_scene.reparentTo(render2d) self.drawn_scene = drawn_scene # This is a copypasta function from some other topic here. 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)
The GLSL fragment shader simply has two output vectors it writes to.