[SOLVED] Renderer.clearBuffers clears only corner of depth target

I’m encountering this problem when rendering shadow maps that the first shadow map to be rendered only has a corner cleared on Renderer.clearBuffers. Here’s a visualization of the problem (white=close, black=far)

When the light moves, the scene “smears” onto the edges of the texture, which I’m guessing means those parts are never cleared.

int w = ...;
int h = ...;
for (int i = 0; i < numShadowMaps; i++) {
    Camera shadowCam = ...
    FrameBuffer fb = ...
    Texture2D shadowMap = ...
    FrameBuffer.RenderBuffer current = fb.getDepthTarget();
    if (current == null || current.getTexture() != shadowMap) {
        fb.setDepthTarget(FrameBuffer.target(shadowMap));
        fb.setUpdateNeeded();
    }
    renderer.setFrameBuffer(fb);
    renderer.clearBuffers(true, true, true);
    rm.setCamera(shadowCam, false);
    context.renderGeometry(occluderQueue, shadowCam, null);
}

It’s only the first shadow map, too. All the other maps are fine, and they’re set up the same way as the first. I’ve tried switching things around as well, but it’s always the first shadow map rendered. Any ideas on what’s going on here?

been exactly there. set the camera before clearing the buffers otherwise the viewport dows not match.

3 Likes

That sounds related to a clip rect bug I fixed. (Also talked about at Blitted To frame buffer only copies part of source)

Does it still happen in the new version beta? Or if you call renderer.clearClipRect() before your call?

2 Likes

I was refering to glViewport and not jme.viewport just in case. It gets set to the correct size when setting the camera.
Nvidia drivers unfortunately clears the rendertargets on creation while amd does not and simply shows you what trash was in that memory region. Easier to track down.
And i cannot state more often, super easy to track down in a opengl debugger.

2 Likes

Yup, moving the setCamera call first fixed it! :+1: Thanks a ton, guys!

4 Likes