Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Qt3D: Clear z-buffer before drawing entity
Forum Updated to NodeBB v4.3 + New Features

Qt3D: Clear z-buffer before drawing entity

Scheduled Pinned Locked Moved Solved Game Development
3 Posts 2 Posters 1.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andreas E.
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Andreas E.
      wrote on last edited by
      #3

      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, ... ]
              ...
          }
      }
      
      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #2

        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.

        1 Reply Last reply
        3
        • A Offline
          A Offline
          Andreas E.
          wrote on last edited by
          #3

          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, ... ]
                  ...
              }
          }
          
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved