Picture goes out of center when FilterManager with simple shaders is applied

I’ve created a very basic scene, it’s rendered as expected:

class Render(ShowBase):
    def __init__(self, **kwargs):
        ShowBase.__init__(self, **kwargs)

	cube = self.loader.loadModel('misc/rgbCube')
	cube.reparent_to(self.render)

	self.camera.set_pos(5, 5, 5)
	self.camera.look_at(0, 0, 0)

but when I add no-op vertex and fragment shaders as seen in Render to Texture and Image Postprocessing

	
        manager = FilterManager(self.win, self.cam)
	texture = Texture()
	quad = manager.renderSceneInto(colortex=texture)
        quad.setShader(Shader.load(Shader.SL_GLSL,
                                   vertex="vertex.glsl",
                                   fragment="fragment.glsl"))
        quad.setShaderInput('texture', texture)
#version 130

// Uniform inputs
uniform mat4 p3d_ModelViewProjectionMatrix;

// Vertex inputs
in vec4 p3d_Vertex;
in vec2 p3d_MultiTexCoord0;

// Output to fragment shader
out vec2 texcoord;

void main() {
  gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;
  texcoord = p3d_MultiTexCoord0;
}
#version 130

uniform sampler2D p3d_Texture0;

// Input from vertex shader
in vec2 texcoord;

void main() {
  gl_FragColor = texture(p3d_Texture0, texcoord);
}

the cube appears shifted to the lower-left corner

I suspect that what’s happening is what’s described in this excerpt from the manual:

There’s one tricky aspect of all this. Usually, the window is usually not a power of two. The texture will end up being bigger than the window: for instance, if the window is 800x600, then the texture will be 1024x1024. The scene will be rendered into the lower-left 800x600 pixels of the texture. The shader needs to compensate for this. If you forget this, you will see an empty band above and to the right of the texture.

(From this page: https://www.panda3d.org/manual/?title=Generalized_Image_Filters)

If you look at the shader given on the same page just after that excerpt, it uses a uniform variable called “texpad_tex” to account for this issue, if I’m not much mistaken.

You can see more information on the “texpad_x” shader-input here, I believe: https://www.panda3d.org/manual/?title=List_of_Possible_Cg_Shader_Inputs

1 Like

Oh, what a shame! I usually read everything thoroughly, but this time I was so eager to test my idea that didn’t bother to read down to the end of paragph. Thank you!

Not a problem! I’m glad to have helped. :slight_smile:

You can also enable non power of two texture support by setting

textures-power-2 none

In your prc data.

1 Like

Wow! That is really helpful. Do you know the performance impact of that option?

It’s an OpenGL feature so, on most cards, implemented in hardware, so I would say negligible or no impact at all.

Cards on which this might have a negative performance impact are likely to be very, very, very, very old, old enough that they are unlikely to support GLSL 1.30. I wouldn’t worry about it.

You might still pay for the memory cost of the texture as though it had been allocated at a larger power-of-two size on some cards, but that means that the cost will not be worse than if you had left the setting to its default value.