Qt3D sort policy (C++)



  • Hi,

    I'm just getting started with Qt3D in C++ so bear with me. I can't figure out how to get my objects to display in proper z order (including as the camera moves). I think I want QSortPolicy::SortType::BackToFront but I can't find or guess the right code to make it work. A simple working C++ example that shows how to do this would be great.

    I'm using Qt 5.11.1 on Windows with VC++ 2017.

    The context is evaluating Qt3D as a possible replacement for OpenSceneGraph in a simulation application. So far it looks very promising but the dearth of C++ tutorials/examples is an obstacle.

    Thanks!



  • What do you mean by proper z order? The sorting becomes relevant when you have transparent objects for example. If your problem is that objects in the back are drawn over objects in the front you should enable depth tests. I think when you use the Qt3DWindow this should be enabled by default. Otherwise attach it to your framegraph using a QRenderStateSet.



  • Thanks for the response. By proper z order I meant that (non-transparent) objects that should be behind others appear in front as I move the camera around. I would also have assumed that depth testing would be enabled automatically but it isn't happening for my code. I'll try adding it via a QRenderStateSet as you suggest.

    If anyone knows why this isn't happening by default or has a "best practice" boilerplate example of setting up a Qt3D scene with 5.11 that would be great.

    Thanks!



  • @HappyFeet So I found one part of the problem. I was doing setAlphaBlendingEnabled on every shape, not just those with transparency. That seems to disable the default depth testing. Using setAlphaBlendingEnabled only on shapes with alpha < 1 is better but to get correct results when transparent objects are in front of opaque objects it seems like I'm still going to need the BackToFront sort policy, but my attempts to apply that aren't working.

    Does that sound right? If so, anyone have an example of setting the sort policy in C++?

    Thanks!



  • Oops, look like my suggestion to use a render state set was not correct, sorry! I thought QSortPolicy was a render state.

    But I found this repo some time ago and it uses the sorting policy in OffscreenLayer.qml. Maybe this helps, because it implements transparency :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.