Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt3D. How to solve Z-Fighting problem?
QtWS25 Last Chance

Qt3D. How to solve Z-Fighting problem?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt3dqt3d 2.0
9 Posts 5 Posters 4.5k Views
  • 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.
  • T Offline
    T Offline
    THE_MASTER
    wrote on last edited by THE_MASTER
    #1

    I use Qt3D 2.0. In my scene i rendering volume lines and solid meshes.
    In this case, the lines - is edges of rectangles, but they may be not only on the edges, they may be located anywhere, such as on side surface of the rectangle...
    alt text
    Lines and solid rectangles shadings in one Entity like this:

    Enitiy
    {
    Triangles
        {
            id: triangles
           //...
        }
    
        Lines
        {
            id: pathLines
           //...
        }
    }
    

    How can i solve Z-fighting problem ?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      There are 2 primary methods to avoid z-fighting:

      • Z-offsetting - add a small (possibly variable depending on depth) offset to your intersecting geometry. In this case move the lines tiny bit closer to the camera or the rest of the geometry away. See the shadow map example for usage of a PolygonOffset property.
      • Just don't have intersecting geometry. I know this sounds like a no go but it's a perfectly valid solution. There are other ways to draw outlines without using additional geometry for it. Look for "toon shader" or "barycentric coordinates wireframe shader" for ready made solutions. A couple of nice features of a shader solution is that you don't actually draw outside the shapes, you avoid the jaggy corners and you have antialiased lines without multisampling.
      1 Reply Last reply
      1
      • T Offline
        T Offline
        THE_MASTER
        wrote on last edited by THE_MASTER
        #3

        Chris-Kawa , in general, is all this I already know, I just do not understand how to do it in Qt3D. Look at this code (from shows map example)

        techniques: [
                Technique {
                    graphicsApiFilter {
                        api: GraphicsApiFilter.OpenGL
                        profile: GraphicsApiFilter.CoreProfile
                        majorVersion: 3
                        minorVersion: 2
                    }
        
                    renderPasses: [
                        RenderPass {
                            filterKeys: [ FilterKey { name: "pass"; value: "shadowmap" } ]
        
                            shaderProgram: ShaderProgram {
                                vertexShaderCode:   loadSource("qrc:/shaders/shadowmap.vert")
                                fragmentShaderCode: loadSource("qrc:/shaders/shadowmap.frag")
                            }
        
                            renderStates: [
                                PolygonOffset { scaleFactor: 4; depthSteps: 4 },
                                DepthTest { depthFunction: DepthTest.Less }
                            ]
                        },
        
                        RenderPass {
                            filterKeys: [ FilterKey { name : "pass"; value : "forward" } ]
        
                            shaderProgram: ShaderProgram {
                                vertexShaderCode:   loadSource("qrc:/shaders/ads.vert")
                                fragmentShaderCode: loadSource("qrc:/shaders/ads.frag")
                            }
        
                            // no special render state set => use the default set of states
                        }
                    ]
                },
                Technique {
                    graphicsApiFilter {
                        api: GraphicsApiFilter.OpenGLES
                        majorVersion: 3
                        minorVersion: 0
                    }
        
                    renderPasses: [
                        RenderPass {
                            filterKeys: [ FilterKey { name: "pass"; value: "shadowmap" } ]
        
                            shaderProgram: ShaderProgram {
                                vertexShaderCode:   loadSource("qrc:/shaders/es3/shadowmap.vert")
                                fragmentShaderCode: loadSource("qrc:/shaders/es3/shadowmap.frag")
                            }
        
                            renderStates: [
                                PolygonOffset { scaleFactor: 4; depthSteps: 4 },
                                DepthTest { depthFunction: DepthTest.Less }
                            ]
                        },
        
                        RenderPass {
                            filterKeys: [ FilterKey { name : "pass"; value : "forward" } ]
        
                            shaderProgram: ShaderProgram {
                                vertexShaderCode:   loadSource("qrc:/shaders/es3/ads.vert")
                                fragmentShaderCode: loadSource("qrc:/shaders/es3/ads.frag")
                            }
                        }
                    ]
                }
            ]
        

        can you explain to me what exactly is meant here:

        1. techniques ? (i can put any number of Technique-s? )
        2. renderPasses ?
        3. renderStates?
          and how much of these elements may be in one Effect ?
        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by Chris Kawa
          #4

          Well I have never written a Qt3D app and the declarative nature of QML totally throws me off, so take my words with a grain of salt but that's what my understanding is:

          In that app there's a root entity with a frame graph component. That component describes what and how is drawn in a single frame. In this case it says there's one fullscreen viewport. This viewport is drawn in two passes defined with RenderPassFilter. Each pass draws entities with a set of filters established. In this case there's one filter applied called "pass". First RenderPassFilter draws everything with "pass" set to "shadowmap", the second one with pass set to "forward".
          Each renderable entity has a Material. Material is a set of properties for the Effect it is drawn with. An Effect is a set of Techniques it can be drawn with and their common properties. My understanding is that there can be any number of Techniques in an effect.
          To put it into perspective I'd use the following example:

          Entity - Ground plane mesh, uses
             Material - Rocks, parametrized with color, texture, rocks height etc. drawn by
                Effect - Rocks effect, using
                   Technique - flat textured with simple per vertex lighting, for low end hardware, or
                   Technique - bump-mapped with per pixel lighting, medium level, or
                   Technique - relief mapped with self-shadowing, high detail level

          The technique used to draw given effect is selected based on some filters (in the shadowmap example what OpenGL version/profile is used). What happens if more than one Technique matches filters for given pass? No idea. My guess is the first one is taken but there might be more to it.

          Rendering a full scene might require more than one pass. In the shadowmap example there are two - one for drawing shadows into a shadowmap texture and another to draw the scene using that shadowmap.
          Each pass draws entities using Technique that matches the filter and uses the RenderPass description in that technique that matches the RenderPassFilter filter. A RenderPass is a set of shaderProgram used for that pass and renderStates. renderStates describes the parameters used for that draw pass. OpenGL is a giant state machine with a ton of switches set to some position e.g. is depth testing on or off, is antialiasing turned on or off, what's the value of polygon offset, state of various bindings etc.

          As for how many elements can be where, my guesses based on the above understanding are:
          There can be any number of entities.
          An entity can have one material assigned.
          One material is drawn with one effect.
          One effect can be achieved using any number of techniques.
          A Technique can require any number of render passes.
          One render pass in a technique is done using one set of shaders and one description of the render state.

          Just to repeat - I never wrote any Qt3D app so I might be wrong in some places.

          T 1 Reply Last reply
          1
          • Chris KawaC Chris Kawa

            Well I have never written a Qt3D app and the declarative nature of QML totally throws me off, so take my words with a grain of salt but that's what my understanding is:

            In that app there's a root entity with a frame graph component. That component describes what and how is drawn in a single frame. In this case it says there's one fullscreen viewport. This viewport is drawn in two passes defined with RenderPassFilter. Each pass draws entities with a set of filters established. In this case there's one filter applied called "pass". First RenderPassFilter draws everything with "pass" set to "shadowmap", the second one with pass set to "forward".
            Each renderable entity has a Material. Material is a set of properties for the Effect it is drawn with. An Effect is a set of Techniques it can be drawn with and their common properties. My understanding is that there can be any number of Techniques in an effect.
            To put it into perspective I'd use the following example:

            Entity - Ground plane mesh, uses
               Material - Rocks, parametrized with color, texture, rocks height etc. drawn by
                  Effect - Rocks effect, using
                     Technique - flat textured with simple per vertex lighting, for low end hardware, or
                     Technique - bump-mapped with per pixel lighting, medium level, or
                     Technique - relief mapped with self-shadowing, high detail level

            The technique used to draw given effect is selected based on some filters (in the shadowmap example what OpenGL version/profile is used). What happens if more than one Technique matches filters for given pass? No idea. My guess is the first one is taken but there might be more to it.

            Rendering a full scene might require more than one pass. In the shadowmap example there are two - one for drawing shadows into a shadowmap texture and another to draw the scene using that shadowmap.
            Each pass draws entities using Technique that matches the filter and uses the RenderPass description in that technique that matches the RenderPassFilter filter. A RenderPass is a set of shaderProgram used for that pass and renderStates. renderStates describes the parameters used for that draw pass. OpenGL is a giant state machine with a ton of switches set to some position e.g. is depth testing on or off, is antialiasing turned on or off, what's the value of polygon offset, state of various bindings etc.

            As for how many elements can be where, my guesses based on the above understanding are:
            There can be any number of entities.
            An entity can have one material assigned.
            One material is drawn with one effect.
            One effect can be achieved using any number of techniques.
            A Technique can require any number of render passes.
            One render pass in a technique is done using one set of shaders and one description of the render state.

            Just to repeat - I never wrote any Qt3D app so I might be wrong in some places.

            T Offline
            T Offline
            THE_MASTER
            wrote on last edited by Eddy
            #5

            @Chris-Kawa
            Thank you very much for reply!
            Now i understood, that it Qt3D is unfinished , to which, moreover, there is little documentation. I will make my own 3D engine from scratch :-)

            ? K 2 Replies Last reply
            0
            • T THE_MASTER

              @Chris-Kawa
              Thank you very much for reply!
              Now i understood, that it Qt3D is unfinished , to which, moreover, there is little documentation. I will make my own 3D engine from scratch :-)

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              @THE_MASTER said in Qt3D. How to solve Z-Fighting problem?:

              I will make my own 3D engine from scratch :-)

              Maybe you want to talk to @jahshaka, he started his own thing, too.

              1 Reply Last reply
              0
              • T THE_MASTER

                @Chris-Kawa
                Thank you very much for reply!
                Now i understood, that it Qt3D is unfinished , to which, moreover, there is little documentation. I will make my own 3D engine from scratch :-)

                K Offline
                K Offline
                kenchan
                wrote on last edited by
                #7

                @THE_MASTER
                if you feel that way about it maybe you could contribute to the project?? :-)
                or even contribute your own super duper 3D engine when it is done. Then everyone would benefit from your experience.
                I for one would certainly appreciate that.

                Good luck

                T 1 Reply Last reply
                0
                • K kenchan

                  @THE_MASTER
                  if you feel that way about it maybe you could contribute to the project?? :-)
                  or even contribute your own super duper 3D engine when it is done. Then everyone would benefit from your experience.
                  I for one would certainly appreciate that.

                  Good luck

                  T Offline
                  T Offline
                  THE_MASTER
                  wrote on last edited by THE_MASTER
                  #8

                  @kenchan
                  KDAB guys develop Qt3D behind closed doors, and they do not need help. I wrote many e-mails to them, but never got response. Judging by their website (https://www.kdab.com/), they earn money on consultations on their own technology :-)
                  What audacity... Made unfinished component for which there is practically no documentation, from now taking money from people for explain how it works

                  1 Reply Last reply
                  -1
                  • m.sueM Offline
                    m.sueM Offline
                    m.sue
                    wrote on last edited by
                    #9

                    Hi,
                    You can write to the Qt Interest mailing list, see http://lists.qt-project.org/mailman/listinfo. There Sean Harmer himself may answer the one or other question about Qt3D if you don't talk badly about his baby right in your first mail.
                    -Michael.

                    1 Reply Last reply
                    2

                    • Login

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