[Interest] Qt3D Stencil example?

Sean Harmer sean.harmer at kdab.com
Sat Sep 23 13:22:19 CEST 2017


Hi,

On 20/09/2017 18:43, Gil H wrote:
> Hi everyone, between StencilMask, StencilTest, and StencilOperation QML
> items and their sparse documentation, I have been unable to achieve
> something fairly straightforward with a custom framegraph.

The render states work in exactly the same way as raw OpenGL states just 
in an object oriented fashion. A nice page with a stencil example is:

https://open.gl/depthstencils

> Specifically, I am trying to render one object (say, a torus) to the
> stencil buffer, and then use that to mask out the rendering of the rest
> of the scene in the second pass.  Can anyone provide an example frame
> graph that does this?

I've created the small attached example that demonstrates this for you. 
It renders a torus shaped entity as a mask, followed by a simple cube as 
the actual scene content. Left clicking on the cube toggles whether the 
stencil buffers masks in or masks out the scene layer content. I've 
briefly documented the MaskedForwardRenderer.qml frame graph for you.

To control which entities are rendered in each phase of the frame, we 
use a Layer and LayerFilter combination - don't forget to assign the 
scene layer to your lights too.

To improve the stencil writing pass, you could use a trivial shader 
program that does the bare minimum of work rather than the phong 
material I've used here for convenience.

Hope this helps,

Sean
-- 
Dr Sean Harmer | sean.harmer at kdab.com | Managing Director UK
KDAB (UK) Ltd, a KDAB Group company
Tel. +44 (0)1625 809908; Sweden (HQ) +46-563-540090
Mobile: +44 (0)7545 140604
KDAB - Qt Experts
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stencil-mask.zip
Type: application/x-zip-compressed
Size: 7232 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170923/db278f9a/attachment.bin>


More information about the Interest mailing list