Hi Roberto,

The opacity of any geometry node is decided by the opacity that comes out of 
the fragment shader of its material. Depending on how the alpha logic exists in 
your custom GL renderer, there are two ways to do this. 

Option 1: If most of the FBO is partially transparent, or if there are bits and 
pieces that are overlaid on top of the rest of the UI, like controls on a HUD, 
then you want to render into an FBO with an alpha buffer, clear it with fully 
transparent, draw your custom GL stuff and then alpha blend the entire FBO on 
top of the QML scene. You do alpha blending of the fbo content by setting the 
QSGMaterial::Blending flag and returning a premultiplied alpha color from the 
fragment shader. The QSGTextureMaterial has a fragment shader that does the 
right thing.

Option 2: If you have an opaque FBO with certain sections, say a given 
rectangle, fully transparent, you can draw the FBO as fully opaque, but create 
a geometry that excludes the fully transparent region. This has the benefit you 
will be drawing more opaque stuff which is generally faster for the GPU to 
handle, compared to blended stuff.

It is of course possible to do a mixture of 1 and 2, by creating two separate 
materials, both referring to the FBO. For the fully opaque sections of the FBO, 
you use an opaque material to draw it which is fast. For the semi-transparent 
sections of the FBO you use a different geometry node with a material that 
enables blending. The fully transparent regions are fully excluded from either 
geometry, so those cost nothing. (something like the MaskedImage I have here: 
https://github.com/qtproject/playground-scenegraph/tree/master/shapes)

Btw, if you used QQuickFramebufferObject instead of rolling your own custom 
Item/node/material, you would get option 1 by default :)

cheers,
Gunnar

> On 06 Jun 2016, at 18:05, Roberto Garrido <robertogarridomar...@gmail.com> 
> wrote:
> 
> Hi all!
> We have a custom QQuickItem which in turn creates a custom QSGGeometryNode. 
> We reimplement the QSGGeometryNode's preprocess() method in order to draw our 
> scene to a FrameBufferObject with a texture attached. This OpenGL texture ID 
> is shared with the QSGGeometryNode's material. This way, we can render our 
> custom OpenGL scene into a QML item. So far, so good.
> 
> However, we want to use alpha blending on some parts of our scene, in order 
> to let the user see the QML items behind our custom item. Something similar 
> to what Item::opacity value is doing, but only for a specific area of our 
> Item. It's like having a hole inside our Item that allows the user to see 
> what's behind. The information about the specific region that should be 
> transparent is handled inside our custom OpenGL renderer.
> 
> I've been trying to find out what Qt is doing in order to change the opacity 
> of a QML item, with no luck.
> 
> Any idea on how can we achieve this effect, with our Item/Node configuration?
> Thanks in advance,
> Robert.
> 
> -- 
> Website: http://robertogarrido.com
> Twitter: http://twitter.com/che1404
> LinkedIn: http://es.linkedin.com/in/robertogarrido/en
> _______________________________________________
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to