Filling an aux render target texture w/ scene a bit dim

Hey,

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. :laughing:

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.

I tried switching to Bullet’s HeightFieldShape for collision detection with mouse ray. However, I can’t get it to match exactly to the custom made terrain generator (I’ve some super magical scale values for the bullet shape, like 0.318, and it’s always a bit off anyway for width and depth, even tho my terrain is just a -10…+10 plane) and the frame rate it offers is abysmal. With a 1024x1024 heightmap, using Bullet drops the FPS from max 60 to 20. And that’s for a single ray query per frame. That can’t possibly be right, as at most there shouldn’t be more than 2048 elements of the image tested against.

I don’t know about Bullet’s HeightFieldShape, but I can answer your original questions:

AuxRgba0 is the right way to use an additional render target. (There may be a more high-level interface soon, but this is the only way for now.)

There is no way in OpenGL to bind a different texture to the default FBO, but if there were, it would be done using base.win.addRenderTexture just as you would bind a texture to any output.

To fill an aux render target with a colour, use output.setClearActive(DrawableRegion.RTPAuxRgba0, True) and setClearValue(DrawableRegion.RTPAuxRgba0, color).

Although it is possible in OpenGL to bind a texture with a mismatching size to an FBO, this does not mean that the rendered image is automatically scaled. OpenGL will instead render using the size of the smallest texture, and the result will be padded in the other attachments. (Older implementations may actually forbid it altogether). I’m not sure how Panda handles it.

I figured that would be the case with my understanding of how the whole pipeline works. In the future, I hope it’s not a technical impossibility to have a screen-sized texture with the default FBO. But that’s their problem. :stuck_out_tongue:

Great, thanks! I was trying to use setClearActive, but my parameters were off.