Tue, 04/12/2022 - 18:50
Forums:
I have followed this example to bridge Opencascade and QOpenGLWidget. A small difference is that I made some changes to the OpenGl_FrameBuffer
and used my own FBO (built around QOpenGLFrameBuffer).
Because the purpose is to interop with native OpenGL stuff, the depth value is essential to mix different scenes (my own and opencascade). However, as shown below, the FBO from a box (built as below) in opencascade does not have depth values, all of them are 1 (white values). But the colors are correct.
TopoDS_Shape aBox = BRepPrimAPI_MakeBox(box.CornerMin(), box.CornerMax()).Shape();
occt_bounds_ = new AIS_Shape(aBox);
occt_context_->Display(occt_bounds_, AIS_Shaded, 0, false);
The point clouds are bounded by the box, so they should be occluded as the figure.
How can I enable the writing of depth values for AIS_InteractiveObject
?
Thanks.
Attachments:
Tue, 04/12/2022 - 23:32
TKOpenGl is a multi-pass renderer that clears Depth buffer multiple times. To incorporate other 3D renderer you should perform custom rendering by subclassing OpenGl_Element or OpenGl_View classes (also refered as "UserDraw" in OCCT documentation).
Wed, 04/13/2022 - 16:10
Seems much more complicated than
V3d_View
. Currently, because my occt scene is relatively lightweight (similar polygon and bounding box primitives as this tool), I have found a workaround by setting all theAIS_InteractiveObject
toGraphic3d_ZLayerId_Topmost
and this z layer has depth recorded in my fbo (the same asAIS_ViewCube
).Maybe when I am more familiar with occt, I will refactor the rendering pipelines.
Fri, 04/15/2022 - 19:29
I have found a relatively perfect walkaround for this issue. I have created two FBOs to record color and depths independently. I draw the scene first normally using all the default settings. In this way, I get a perfect color texture from occt. Then I set the clear depth property of the
TopMost
z layer to false and use raytracing render mode, in this way I get a perfect depth texture from occt. Finally, I use a passthrough shader to combine my own FBO and the two FBOs. The code structure is like the below.