What is the drawing sequence of the entities in the scene graph in Qt3D? - qt3d

Recently, I tried to realize a semi transparent surface in Qt3D. I put this semi transparent surface in the scene graph in Qt3D together with many other entities that should be draw. However, I found that the drawing order of the surface is not fixed, which seriously affect the blending effect.
How can I know the drawing sequence of the entities in the scene graph in Qt3D? Also, how can I make sure that my semi transparent surface was drawn last?
Thank you.

What you are looking for is the class QSortPolicy. You can set the sorting policy there to back to front, to draw the transparent surface last. Although, according to the documentation, the drawing order depends on when the entities appear in the scene graph, when no sorting policy is present.
Other than that, I found a frame/scene graph in Qt3D that showcases a transparent object here: https://github.com/alpqr/q3dpostproc. It's written in QML but you should be able to transfer it to C++ without much work.

Related

Transparency with complex shapes in three.js

I'm trying to render a fairly complex lamp using Three.js: https://sayduck.com/3d/xhcn
The product is split up in multiple meshes similar to this one:
The main issue is that I also need to use transparent PNG textures (in order to achieve the complex shape while keeping polygon counts low) like this:
As you can see from the live demo, this gives really weird results, especially when rotating the camera around the lamp - I believe due to z-ordering of the meshes.
I've been reading answers to similar questions on SO, like https://stackoverflow.com/a/15995475/5974754 or https://stackoverflow.com/a/37651610/5974754 to get an understanding of the underlying mechanism of how transparency is handled in Three.js and WebGL.
I think that in theory, what I need to do is, each frame, explicitly define a renderOrder for each mesh with a transparent texture (because the order based on distance to camera changes when moving around), so that Three.js knows which pixel is currently closest to the camera.
However, even ignoring for the moment that explicitly setting the order each frame seems far from trivial, I am not sure I understand how to set this order theoretically.
My meshes have fairly complex shapes and are quite intertwined, which means that from a given camera angle, some part of mesh A can be closer to the camera than some part of mesh B, while somewhere else, part of mesh B are closer.
In this situation, it seems impossible to define a closer mesh, and thus a proper renderOrder.
Have I understood correctly, and this is basically reaching the limits of what WebGL can handle?
Otherwise, if this is doable, is the approach with two render scenes (one for opaque meshes first, then one for transparent ones ordered back to front) the right one? How should I go about defining the back to front renderOrder the way that Three.js expects?
Thanks a lot for your help!

THREE.Shape to mimic context.clip()

Using THREE.Shape, I can create holes, but rather than holes, I wish to define a clip mask.
I ONLY want to render the shape within a mask, similar to html's canvas/context .clip()
Is there a way to do this using holes or other method?
EDIT:
So, more background, I was using canvas to render segments, and imported them into three as planes.
The mouth was 1 canvas, and I was able to clip mask the teeth and tongue onto the black part.
See the whole movie at http://zsenji.com (rendered using the old canvas method)
Anyway, now I'm updating everything to use threejs and no more canvases rendered as planes.
I'm going to try three csg , which can hopefully intersect two geometries. https://stemkoski.github.io/Three.js/CSG.html
Then all I would have to do would be extrude the black of the mouth, and intersect it with the teeth/tongue. I will update
It worked.
I used very simple intersect, similar to https://github.com/chandlerprall/ThreeCSG/blob/master/examples.html
It's a little slow and there are still some other problems relating to overlapping paths, but for this issue, this was the fix.
All the different fills you see are three shapes

Alpha Blending and face sorting using OpenGL and GLSL

I'm writing a little 3D engine. I've just added the alpha blending functionality in my program and I wonder one thing: do I have to sort all the primitives compared with the camera?)
Let's take a simple example : I have a scene composed by 1 skybox and 1 tree with alpha blended leafs!
Here's a screenshot of a such scene:
Until here all seems to be correct concerning the alpha blending of the leafs relative to each others.
But if we get closer...
... we can see there is a little trouble on the top right of the image (the area around the leaf forms a quad).
I think this bug comes from the fact these two quads (primitives) should have been rendered later than the ones in back.
What do you think about my supposition ?
PS: I want to precise all the geometry concerning the leafs is rendered in just one draw call.
But if I'm right it would means when I need to render an alpha blended mesh like this tree I need update my VBO each time my camera is moving by sorting all the primitives (triangles or quads) from the camera's point of view. So the primitives in back should be rendered in first...
What do you think of my idea?

Draw model with edges in OpenGL

I have model soucast1.3DS
If I open this model in CAD Autodesk Inventor it looks
model in Autodesk Inventor
if I use simple application using OpenGL it looks
model in OpenGL app
GL.Color3(Color.Aqua);
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
DrawMatrix(); // draw model
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
GL.Enable(EnableCap.PolygonOffsetLine);
GL.PolygonOffset(-1.0f, -1.0f);
GL.Color3(Color.Black);
DrawMatrix(); // draw model
so, my question is:
How can I get same result in my application (OpenGL) as you can see from Inventor?
(Only edges of areas are black)
There are many approaches. You could use tricky shaders combination, stencil buffer or object scaling:
Draw slightly scaled-up model with black color, dropping front faces (e.g. GL_CULL_FACE=GL_CW). Then draw normal model with correct scale and colors, dropping back faces (GL_CCW).
Not a perfect solution, usable for cartoon-like shading in games; may be too unprecise for CAD. If it isn't fit for you - google opengl edge outline.
To clarify things: 3D modeling software always have information about edges in addition to faces, so they can just draw edge lines after model is drawn, and you getting an outline. If you don't have edges (or, like in games - don't even want to have edges because of memory consumption and other issues) - you have to perform some form of edge detection or hack.
I solved it. Change model to STL (contains triangles and normals), found areas (compare of normals) and write algorithm to find border.
And result is:
Opengl

Drawing Outline with OpenGL ES

Every technique that I've found or tried to render outline in OpenGL uses some function that is not avaliable on OpenGL ES...
Actually what I could do is set depthMask to false, draw the object as a 3 pixels wide line wireframe, reenable the depthMask and then drawing my object. It doesnt work for me because it outline only the external parts of my object, not the internals.
The following image shows two outlines, the left one is a correct outline, the right one is what I got.
So, can someone direct me to a technique that doesn't is avaliable on OpenGL ES?
Haven't done one of these for a while, but I think you're almost there! What I would recommend is this:
Keep depthMask enabled, but flip your backface culling to only render the "inside" of the object.
Draw the mesh with that shader that pushes all the verts out along their normals slightly and as a solid color (your outline color, probably black). Make sure that you're drawing solid triangles and not just GL_LINES.
Flip the backface culling back to normal again and re-render the mesh like usual.
The result is that the outlines will only be visible around the points on your mesh where the triangles start to turn away from the camera. This gives you some nice, simple outlines around things like noses, chins, lips, and other internal details.

Resources