1

Is there an easy way to show 3D entity at all times, even when that entity is hidden behind another entity? For example, I want that lines are always shown event when they are behind mesh surface.

I use Qt3D framework.

Matphy
  • 1,086
  • 13
  • 21
  • 2
    You should mention in the title of your question that you are looking for answers concerning the Qt3D framework. – Florian Blume Aug 23 '18 at 10:58
  • I misread your question and for some reason thought you were asking about how to show the outline of an object even if it is hidden behind other objects. I therefore moved my answer here: https://stackoverflow.com/questions/52568614/how-do-i-draw-the-outline-of-an-object-in-qt3d/52568615 – dragly Sep 29 '18 at 13:31

2 Answers2

3

Assuming that you are talking about the Qt3D framework I want to extend the answer of Rabbid76.

To disable depth-testing in the Qt3D framework, add a QRenderStateSet to the framegraph branch that renders things (the one that as a QViewPort for example) and add a QDepthTest to it. Then, set the depth function of the QDepthTest to always. This way, the depth test is always passed and entities in the back will also be drawn, depending on the drawing order. You can use QSortPolicy to adjust the drawing order to back-to-front.

But this won't work when the camera position changes and your entity that you always want to be drawn is in the front. I'd suggest you add another framegraph branch and use a QLayerFilter to only deactivate depth-testing for this one entity.

If your entity looks weird when deactivating depth-testing (likely for complex objects), you could replace the QDepthTest by a QClearBuffers and simply clear the depth buffer.

Have a look at my answer here, where I showed an example of a custom framegraph with depth test.

Florian Blume
  • 3,237
  • 17
  • 37
  • 2
    *"and all entities will be drawn, no matter what their z-value is"*. That's only partially true. Entities are only visible in the end when they are drawn in the correct order. – BDL Aug 23 '18 at 11:05
1

If the depth test is disabled, then the geometry (like a line) is always drawn on top of the previously drawn geometry. The depth test can be disabled by:

glDisable(GL_DEPTH_TEST)

See glEnable


As an alternative the depth test function, can be set to let a fragment always pass depth test. In Qt this can be done by the class QDepthTest, using the enumerator constant Qt3DRender::QDepthTest::Always.

In this case, you have to take care about the order in which the geometry is drawn. You have to find a way, to render the polygons (opaque geometry) first, by using the depth test function Qt3DRender::QDepthTest::Less. After that you have to render the lines on top, by using the depth test function Qt3DRender::QDepthTest::Always.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174