Solved Qt3D: Clear z-buffer before drawing entity
-
Hello,
I have a 3D scene like this:
Entity { Camera { id: camera ... } components: [ RenderSettings { activeFrameGraph: ForwardRenderer { clearColor: Qt.rgba(0.0, 0.0, 0.0, 1.0) camera: camera } }, InputSettings { } ] EntityA { ... } EntityB { ... } }
What I'm trying to achieve is that the engine will render EntityA, then clear the z-buffer, and then render EntityB. So objects in EntityB should always be visible even if they are behind objects from EntityA.
Is it possible to do this in Qt3D? How would I have to change the example code above?Thanks in advance!
-
Thank you for the advice, I got it working now. I am new to the frame graph stuff so please feel free to tell me if I made any obvious mistakes. Here is the code that made it work for me:
Entity { Camera { id: camera ... } components: [ RenderSettings { activeFrameGraph: RenderSurfaceSelector { ClearBuffers { buffers: ClearBuffers.AllBuffers clearColor: Qt.rgba(0.0, 0.0, 0.0, 1.0) } Viewport { normalizedRect: Qt.rect(0, 0, 1, 1) CameraSelector { camera: camera LayerFilter { layers: [layerA] } } } Viewport { normalizedRect: Qt.rect(0, 0, 1, 1) ClearBuffers { buffers: ClearBuffers.DepthBuffer } CameraSelector { camera: camera LayerFilter { layers: [layerB] } } } }, InputSettings { } ] Layer { id: layer1 } Layer { id: layer2 } EntityA { components: [ layerA, ... ] ... } EntityB { components: [ layerB, ... ] ... } }
-
Hi! Yes, it's possible:
- Create one Layer for objects that are always visible (layer1)
- Create a second Layer for all the other objects (layer2)
- Add the layer1 component to all your always-visible-objects
- Add the layer2 component to all your "normal" objects.
You can see how this is done in Layer QML Type.
The next step is creating a custom framegraph with two renderviews, where the first one renders your layer2 objects and the second clears the buffers as you wish and then renders the layer1 objects. You'll use LayerFilters for this.
-
Thank you for the advice, I got it working now. I am new to the frame graph stuff so please feel free to tell me if I made any obvious mistakes. Here is the code that made it work for me:
Entity { Camera { id: camera ... } components: [ RenderSettings { activeFrameGraph: RenderSurfaceSelector { ClearBuffers { buffers: ClearBuffers.AllBuffers clearColor: Qt.rgba(0.0, 0.0, 0.0, 1.0) } Viewport { normalizedRect: Qt.rect(0, 0, 1, 1) CameraSelector { camera: camera LayerFilter { layers: [layerA] } } } Viewport { normalizedRect: Qt.rect(0, 0, 1, 1) ClearBuffers { buffers: ClearBuffers.DepthBuffer } CameraSelector { camera: camera LayerFilter { layers: [layerB] } } } }, InputSettings { } ] Layer { id: layer1 } Layer { id: layer2 } EntityA { components: [ layerA, ... ] ... } EntityB { components: [ layerB, ... ] ... } }