Qt3D. How to solve Z-Fighting problem?
-
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...
Lines and solid rectangles shadings in one Entity like this:Enitiy { Triangles { id: triangles //... } Lines { id: pathLines //... } }
How can i solve Z-fighting problem ?
-
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.
- 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
-
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:
- techniques ? (i can put any number of Technique-s? )
- renderPasses ?
- renderStates?
and how much of these elements may be in one Effect ?
-
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 levelThe 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.
-
@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 :-) -
@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.
-
@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
-
@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 -
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.