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