| 1 |
// Copyright (C) 2015 Paul Lemire |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
import Qt3D.Core 2.0 |
| 5 |
import Qt3D.Render 2.0 |
| 6 |
|
| 7 |
Viewport { |
| 8 |
id: root |
| 9 |
property alias camera: cameraSelector.camera |
| 10 |
property alias window: surfaceSelector.surface |
| 11 |
property alias clearColor: clearBuffer.clearColor |
| 12 |
|
| 13 |
readonly property Layer contentLayer: Layer {} |
| 14 |
readonly property Layer visualizationLayer: Layer {} |
| 15 |
readonly property Layer capsLayer: Layer {} |
| 16 |
|
| 17 |
RenderSurfaceSelector { |
| 18 |
id: surfaceSelector |
| 19 |
|
| 20 |
CameraSelector { |
| 21 |
id: cameraSelector |
| 22 |
|
| 23 |
RenderStateSet { |
| 24 |
// Enable 3 clipping planes |
| 25 |
renderStates: [ |
| 26 |
ClipPlane { planeIndex: 0 }, |
| 27 |
ClipPlane { planeIndex: 1 }, |
| 28 |
ClipPlane { planeIndex: 2 }, |
| 29 |
DepthTest { depthFunction: DepthTest.LessOrEqual } |
| 30 |
] |
| 31 |
|
| 32 |
// Branch 1 |
| 33 |
LayerFilter { |
| 34 |
// Render entities with their regular material |
| 35 |
// Fills depth buffer for entities that are clipped |
| 36 |
layers: [root.contentLayer, root.visualizationLayer] |
| 37 |
ClearBuffers { |
| 38 |
id: clearBuffer |
| 39 |
buffers: ClearBuffers.ColorDepthBuffer |
| 40 |
RenderPassFilter { |
| 41 |
matchAny: FilterKey { name: "pass"; value: "material" } |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
// Branch 2 |
| 47 |
ClearBuffers { |
| 48 |
// Enable and fill Stencil to later generate caps |
| 49 |
buffers: ClearBuffers.StencilBuffer |
| 50 |
RenderStateSet { |
| 51 |
// Disable depth culling |
| 52 |
// Incr for back faces |
| 53 |
// Decr for front faces |
| 54 |
// No need to output color values |
| 55 |
renderStates: [ |
| 56 |
StencilTest { |
| 57 |
front { |
| 58 |
stencilFunction: StencilTestArguments.Always |
| 59 |
referenceValue: 0; comparisonMask: 0 |
| 60 |
} |
| 61 |
back { |
| 62 |
stencilFunction: StencilTestArguments.Always |
| 63 |
referenceValue: 0; comparisonMask: 0 |
| 64 |
} |
| 65 |
}, |
| 66 |
StencilOperation { |
| 67 |
front.allTestsPassOperation: StencilOperationArguments.Decrement |
| 68 |
back.allTestsPassOperation: StencilOperationArguments.Increment |
| 69 |
}, |
| 70 |
ColorMask { redMasked: false; greenMasked: false; blueMasked: false; alphaMasked: false } |
| 71 |
] |
| 72 |
|
| 73 |
LayerFilter { |
| 74 |
layers: root.contentLayer |
| 75 |
RenderPassFilter { |
| 76 |
matchAny: FilterKey { name: "pass"; value: "stencilFill"; } |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
// Branch 3 |
| 84 |
RenderStateSet { |
| 85 |
// Draw caps using stencil buffer |
| 86 |
LayerFilter { |
| 87 |
layers: root.capsLayer |
| 88 |
RenderPassFilter { |
| 89 |
matchAny: FilterKey { name: "pass"; value: "capping"; } |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
// Draw back faces - front faces -> caps |
| 94 |
renderStates: [ |
| 95 |
StencilTest { |
| 96 |
front { |
| 97 |
stencilFunction: StencilTestArguments.NotEqual |
| 98 |
referenceValue: 0; comparisonMask: ~0 |
| 99 |
} |
| 100 |
back { |
| 101 |
stencilFunction: StencilTestArguments.NotEqual |
| 102 |
referenceValue: 0; comparisonMask: ~0 |
| 103 |
} |
| 104 |
} |
| 105 |
] |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
|