Corrupt rendering after translucent object goes off screen

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
qfwfq
Gnoblar
Posts: 11
Joined: Mon Aug 25, 2014 4:47 pm
Contact:

Corrupt rendering after translucent object goes off screen

Post by qfwfq »

Hi,

My project uses RTT to render an orthographic camera into a texture and then later displays the this on screen composited with some UI elements. It has been working perfectly until today, when I stumbled onto a confusing problem. I'm using Ogre 1.9, the OpenGL renderer, and I'm on Windows with a GeForce GTX 560M/PCIe/SSE2 card.

I've tried to narrow it down as much as possible, and the issue seems to occur when I first display, and then remove from the visible scene, an object with a material which has the following set:

Code: Select all

scene_blend alpha_blend
depth_write off
When either or both of these are missing from the material script, then the problem is not reproducible.

What happens is:

1. I have a scene with a grass-textured rectangle and a box sitting on this. (The box and the grass are not part of the problem, as far as I've been able to tell, but just there to help with the illustration.)
Image

2. Next, I show a simple, rectangular ManualObject with a partially translucent texture map with a smiley face hovering over this scene. So far this looks fine:

Image

The code for the ManualObject looks as follows:

Code: Select all

    m_aim->begin();
    m_aim->position(-1, -1, 2);
    m_aim->textureCoord(0, 0);

    m_aim->position(1, -1, 2);
    m_aim->textureCoord(1, 0);

    m_aim->position(1, 1, 2);
    m_aim->textureCoord(1, 1);

    m_aim->position(-1, 1, 2);
    m_aim->textureCoord(0, 1);

    m_aim->index(0);
    m_aim->index(1);
    m_aim->index(3);

    m_aim->index(1);
    m_aim->index(2);
    m_aim->index(3);
    m_aim->end();
3. The problem occurs when I remove the translucent object from the scene again, either by setVisible(false), by destroying it, or simply by moving it to a location where it is no longer visible.

At this point, if I rotate my camera, the viewport is rendered like this:

Image

The artifacts are not static: As I rotate the camera, some will disappear or shrink, and others will pop up or grow. A given rotation will always have the same artifacts.

I don't have to rotate the camera to see artifacts either. I have a function in the application which allows you to have an object follow the mouse cursor around in the scene. If I do this after hiding the translucent smiley face, then the hovering object is only visible as it overlaps the box in the scene. In this small area it will look fine. It is also visible through the cracks when they appear during rotation. If I rotate the box which is already in the scene, then it will be rendered rotated, but the shape from its original rotation will still be visible, possibly burnt into the depth buffer?

I've tried to illustrate this, although it's easier to see when doing the rotation live. Here's the silhouette of the original rotation is like a hole in the depth buffer allowing the box to be rendered at a different rotation, but there also seems to be a black line along one of the corners of the box at its original rotation.

Image

If I add the translucent smiley face back (or move it back to a visible location), the problem will sort it self out.

An even more interesting detail is that if I move the object to a location where it is no longer visible (so that the problem occurs), and I then subsequently move the camera after the object, the problem will disappear the moment when the object re-enters the screen. And even if I move the camera away again so that the object is no longer visible, this does not trigger the bug again.

It's quite possible that I'm doing something wrong here, but I haven't been able to figure out what, so I hope someone will recognize these artifacts and can help me find out either how to debug the problem or how to work around it. If the issue occurs when the material is unloaded, for instance, is it somehow possible to make sure the material stays in memory?

Thank you =)
Post Reply