[Interest] Qt3D face culling

Paul Lemire paul.lemire at kdab.com
Wed Nov 2 12:43:10 CET 2016


On Thursday, February 25, 2016 10:38:11 AM Øyvind Bakken wrote:
> Hi,
> 
> we are developing a desktop application with 3D graphics using Qt3D. We
> have run into some issues when using the Qt3DRender.CullFace settings in
> the Qt3DRender.StateSet module.
> 
> Basically we have an open surface which was correctly rendering the front,
> but not the back face. We then added the Qt3DRender.CullFace settings like
> this (QML):
> 
> 
> Scene3D { ..... ..... // Top-level entity entity: Qt3DCore.Entity { .....
> ..... // Simple framegraph that just renders the scene from the camera
> components: [ Qt3DRender.FrameGraph { activeFrameGraph: Qt3DRender.Viewport
> { rect: Qt.rect(0, 0, 1, 1) // From Top Left clearColor: "transparent"
> Qt3DRender.CameraSelector { camera: camera Qt3DRender.ClearBuffer { buffers
> 
> : Qt3DRender.ClearBuffer.ColorDepthBuffer Qt3DRender.StateSet {
> 
> Qt3DRender.CullFace { //mode: Qt3DRender.CullFace.FrontAndBack } } } } } }
> ] } //Top-level entity } //Scene3D
> 
> The obvious first strange thing here is that we don't even have to add the
> mode setting of the CullFace to make it work - even though the line is
> commented out, both the front and back face is rendered correctly.

Actually the default is Qt3DRender.NoCulling (which doesn't perform any 
culling) which explains why your are seeing things. FrontAndBack would 
actually cull everything and you wouldn't see anything.

> 
> The other issue is that when rotating the camera, the depth mode seems to
> be broken - we have two objects in the scene, and now one of them is always
> in the front of the other when rotating 360 degrees.

Indeed when you specify a QRenderStateSet you basically reset all the OpenGL 
states to their default value, no depth test, no culling.... So by default 
depth testing is not enabled and you would have to add a DepthTest node to 
enable it again. 

Qt3D internally defines its own default render state which is DepthTest + 
BackFace culling which explains why you get depth testing by default (when not 
specifying a RenderStateSet in the FrameGraph).

The other option is to add the CullFace on the renderStates property of a 
RenderPassFilter or the RenderPass node of your Material (if you are not using 
one of the default ones) in which case CullFace would be added on top of the 
other default states).

I actually believe Qt3D should default to the same as an empty QRenderStateSet 
(and we would modify the default FrameGraph by adding DepthTest/CullFace) so 
that we can get rid of the unintuitive behavior. Not everyone agrees with me 
on this though....


> 
> It seems to us that we are either not using the correct way of changing
> culling settings, or that when adding the Qt3DRender.StateSet part this
> overwrites other settings as well, related to depth etc.
> 
> Any ideas? Thanks in advance:)

-- 
Paul Lemire | paul.lemire at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel: France +33 (0)4 90 84 08 53, http://www.kdab.fr
KDAB - The Qt, C++ and OpenGL Experts




More information about the Interest mailing list