vcti-shader-pick 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vcti_shader_pick-1.0.0/LICENSE +8 -0
- vcti_shader_pick-1.0.0/PKG-INFO +209 -0
- vcti_shader_pick-1.0.0/README.md +180 -0
- vcti_shader_pick-1.0.0/pyproject.toml +98 -0
- vcti_shader_pick-1.0.0/setup.cfg +4 -0
- vcti_shader_pick-1.0.0/src/vcti/shader/pick/__init__.py +91 -0
- vcti_shader_pick-1.0.0/src/vcti/shader/pick/py.typed +0 -0
- vcti_shader_pick-1.0.0/src/vcti/shader/pick/slang/pick.slang +68 -0
- vcti_shader_pick-1.0.0/src/vcti/shader/pick/specs.py +108 -0
- vcti_shader_pick-1.0.0/src/vcti/shader/pick/texel.py +189 -0
- vcti_shader_pick-1.0.0/src/vcti_shader_pick.egg-info/PKG-INFO +209 -0
- vcti_shader_pick-1.0.0/src/vcti_shader_pick.egg-info/SOURCES.txt +21 -0
- vcti_shader_pick-1.0.0/src/vcti_shader_pick.egg-info/dependency_links.txt +1 -0
- vcti_shader_pick-1.0.0/src/vcti_shader_pick.egg-info/requires.txt +16 -0
- vcti_shader_pick-1.0.0/src/vcti_shader_pick.egg-info/top_level.txt +1 -0
- vcti_shader_pick-1.0.0/tests/test_definition.py +39 -0
- vcti_shader_pick-1.0.0/tests/test_docs.py +236 -0
- vcti_shader_pick-1.0.0/tests/test_examples.py +268 -0
- vcti_shader_pick-1.0.0/tests/test_interface.py +305 -0
- vcti_shader_pick-1.0.0/tests/test_pick_math.py +167 -0
- vcti_shader_pick-1.0.0/tests/test_specs.py +98 -0
- vcti_shader_pick-1.0.0/tests/test_texel.py +225 -0
- vcti_shader_pick-1.0.0/tests/test_version.py +17 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright (c) 2018-2026 Visual Collaboration Technologies Inc.
|
|
2
|
+
All Rights Reserved.
|
|
3
|
+
|
|
4
|
+
This software is proprietary and confidential. Unauthorized copying,
|
|
5
|
+
distribution, or use of this software, via any medium, is strictly
|
|
6
|
+
prohibited. Access is granted only to authorized VCollab developers
|
|
7
|
+
and individuals explicitly authorized by Visual Collaboration
|
|
8
|
+
Technologies Inc.
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vcti-shader-pick
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: The pick shader feature: the fragment-stage pass that writes identifiers for the geometry at each pixel.
|
|
5
|
+
Author: Visual Collaboration Technologies Inc.
|
|
6
|
+
License-Expression: LicenseRef-Proprietary
|
|
7
|
+
Project-URL: Repository, https://github.com/vcollab/vcti-python-shader-pick
|
|
8
|
+
Project-URL: Changelog, https://github.com/vcollab/vcti-python-shader-pick/blob/main/CHANGELOG.md
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
13
|
+
Requires-Python: <3.15,>=3.12
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: vcti-shader-base>=2.1.0
|
|
17
|
+
Provides-Extra: gl
|
|
18
|
+
Requires-Dist: vcti-shader-compiler[gl]>=4.0.0; extra == "gl"
|
|
19
|
+
Provides-Extra: test
|
|
20
|
+
Requires-Dist: pytest; extra == "test"
|
|
21
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
22
|
+
Requires-Dist: vcti-shader-compiler>=4.0.0; extra == "test"
|
|
23
|
+
Requires-Dist: numpy; extra == "test"
|
|
24
|
+
Provides-Extra: lint
|
|
25
|
+
Requires-Dist: ruff; extra == "lint"
|
|
26
|
+
Provides-Extra: typecheck
|
|
27
|
+
Requires-Dist: mypy; extra == "typecheck"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# vcti-shader-pick
|
|
31
|
+
|
|
32
|
+
The pick shader feature: the fragment-stage pass that writes identifiers for the geometry at each pixel.
|
|
33
|
+
|
|
34
|
+
## Overview
|
|
35
|
+
|
|
36
|
+
A viewer has to answer "what did the user just click on", and the only thing
|
|
37
|
+
that knows which surface covers which pixel is the rasterizer. So the answer is
|
|
38
|
+
produced the same way the picture is: by drawing. A **pick pass** renders the
|
|
39
|
+
scene to an integer target and writes, at every pixel, identifiers for the
|
|
40
|
+
geometry that landed there — plus how far away it was.
|
|
41
|
+
|
|
42
|
+
Reading one texel back then answers the click. What those identifiers *mean* is
|
|
43
|
+
not this package's business: one names the atom, and the other is opaque,
|
|
44
|
+
resolved by whoever owns the source model. That is what lets the same pass serve
|
|
45
|
+
an element, a face, a triangle, or something not yet invented, without changing
|
|
46
|
+
a line of shader source.
|
|
47
|
+
|
|
48
|
+
`vcti-shader-pick` ships the Slang that packs a texel, a Python mirror of the
|
|
49
|
+
same layout for decoding a readback, and the `ShaderDefinition` saying what the
|
|
50
|
+
feature is. Everything here is a declaration or fixed shader source; nothing
|
|
51
|
+
compiles, runs, or reads back a shader.
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install vcti-shader-pick
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Requires Python 3.12, 3.13, or 3.14, matching `vcti-shader-base`. Nothing native
|
|
60
|
+
is built on that path, and nothing native is built by `[test]` either — only the
|
|
61
|
+
`[gl]` extra pulls a GL binding, and only on 3.14 does that compile from source
|
|
62
|
+
for want of a cp314 wheel.
|
|
63
|
+
|
|
64
|
+
### In `requirements.txt`
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
vcti-shader-pick>=1.0.0
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### In `pyproject.toml` dependencies
|
|
71
|
+
|
|
72
|
+
```toml
|
|
73
|
+
dependencies = [
|
|
74
|
+
"vcti-shader-pick>=1.0.0",
|
|
75
|
+
]
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Quick Start
|
|
79
|
+
|
|
80
|
+
### What a build step binds
|
|
81
|
+
|
|
82
|
+
The feature declares two per-vertex identifiers and one integer target. Both
|
|
83
|
+
identifiers must reach the fragment stage as `flat` varyings — GLSL ES requires
|
|
84
|
+
that of every integer varying, and it is what keeps them exact:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from vcti.shader.pick import fragment_inputs, fragment_outputs, fragment_uniforms
|
|
88
|
+
|
|
89
|
+
inputs = fragment_inputs()
|
|
90
|
+
assert [attribute.name for attribute in inputs] == ["a_atomId", "a_pickIndex"]
|
|
91
|
+
assert inputs[0].semantic == "atom-id"
|
|
92
|
+
|
|
93
|
+
assert fragment_outputs()[0].name == "pickTarget"
|
|
94
|
+
assert fragment_uniforms() == ()
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`a_atomId` is declared identically by another atom-aware feature, so the two
|
|
98
|
+
merge into one attribute when they are composed. `a_pickIndex` is this feature's
|
|
99
|
+
own, and is opaque to everything in the shader.
|
|
100
|
+
|
|
101
|
+
### Reading a click back
|
|
102
|
+
|
|
103
|
+
The target is four unsigned 32-bit channels. Clear it to `PICK_EMPTY` before the
|
|
104
|
+
pass, and draw the pass depth-tested, unblended and single-sampled — each of
|
|
105
|
+
those is the caller's to get right, and each fails silently, which
|
|
106
|
+
[design.md](docs/design.md) explains. Then decode the texel under the cursor:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from vcti.shader.pick import PICK_EMPTY, decode, float_to_bits
|
|
110
|
+
|
|
111
|
+
nothing = decode((PICK_EMPTY, PICK_EMPTY, PICK_EMPTY, PICK_EMPTY))
|
|
112
|
+
assert nothing is None
|
|
113
|
+
|
|
114
|
+
hit = decode((7, 4_210_001, float_to_bits(12.5), 0))
|
|
115
|
+
assert hit is not None
|
|
116
|
+
assert hit.atom_id == 7
|
|
117
|
+
assert hit.pick_index == 4_210_001
|
|
118
|
+
assert hit.depth == 12.5
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The depth is measured along the camera's forward axis — `-z` in view space,
|
|
122
|
+
positive in front of the camera — not from the eye to the point. Give it the
|
|
123
|
+
pixel's ray, and `reconstruct_view_position` returns the point:
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from vcti.shader.pick import reconstruct_view_position
|
|
127
|
+
|
|
128
|
+
# A perspective ray: the origin is the eye, at the view-space origin.
|
|
129
|
+
point = reconstruct_view_position(12.5, (0.0, 0.0, 0.0), (0.3, 0.2, -1.0))
|
|
130
|
+
assert point == (3.75, 2.5, -12.5)
|
|
131
|
+
|
|
132
|
+
# An orthographic ray: parallel, each starting at its own point.
|
|
133
|
+
point = reconstruct_view_position(12.5, (2.0, 1.0, -0.1), (0.0, 0.0, -1.0))
|
|
134
|
+
assert point == (2.0, 1.0, -12.5)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The ray is yours to build — inverting the projection and knowing which way the
|
|
138
|
+
viewport's Y runs are the caller's, because the caller owns the camera. What the
|
|
139
|
+
depth *means* is this package's, which is why the inverse ships here rather than
|
|
140
|
+
being a formula every caller re-derives. `direction` need not be normalized, and
|
|
141
|
+
the origin need not sit on the camera plane: a ray unprojected to the near plane
|
|
142
|
+
works as given.
|
|
143
|
+
|
|
144
|
+
A Euclidean distance from the eye would have cost the same channel and been
|
|
145
|
+
wrong for any ray not starting at a single shared point.
|
|
146
|
+
|
|
147
|
+
Note that `depth` is *reinterpreted* from its bits rather than converted:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from vcti.shader.pick import bits_to_float
|
|
151
|
+
|
|
152
|
+
assert bits_to_float(float_to_bits(12.5)) == 12.5
|
|
153
|
+
assert float_to_bits(1.0) > 1_000_000_000 # the same bits read as an int
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Selecting a pipeline
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from vcti.shader.pick import DEFINITION
|
|
160
|
+
|
|
161
|
+
assert DEFINITION.id == "pick"
|
|
162
|
+
assert DEFINITION.role.value == "fragment"
|
|
163
|
+
assert DEFINITION.capabilities == ("pick",)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## The texel
|
|
167
|
+
|
|
168
|
+
| Channel | Holds |
|
|
169
|
+
|---|---|
|
|
170
|
+
| `R` | `a_atomId` |
|
|
171
|
+
| `G` | `a_pickIndex` |
|
|
172
|
+
| `B` | the view depth, as reinterpreted `float32` bits |
|
|
173
|
+
| `A` | reserved, written as zero |
|
|
174
|
+
|
|
175
|
+
An integer target rather than a float one because identifiers must survive
|
|
176
|
+
exactly: a `float32` carries consecutive integers only to 2²⁴, above which one
|
|
177
|
+
arrives as its neighbour and resolves to different geometry — a failure that
|
|
178
|
+
looks like a mis-click rather than like corruption.
|
|
179
|
+
|
|
180
|
+
## API surface
|
|
181
|
+
|
|
182
|
+
| Name | What it is |
|
|
183
|
+
|---|---|
|
|
184
|
+
| `DEFINITION` | the `ShaderDefinition` a build step imports to compose this feature |
|
|
185
|
+
| `SLANG_DIR` | the installed Slang directory |
|
|
186
|
+
| `fragment_inputs`, `fragment_outputs`, `fragment_uniforms` | what a build step binds |
|
|
187
|
+
| `decode`, `is_empty`, `Pick` | read a texel of a pick readback |
|
|
188
|
+
| `bits_to_float`, `float_to_bits` | the bit reinterpretation, on its own |
|
|
189
|
+
| `reconstruct_view_position` | a ray and a depth to the view-space point |
|
|
190
|
+
| `PICK_EMPTY`, `PICK_RESERVED`, `CHANNELS` | the layout, as data |
|
|
191
|
+
| `TARGET_NAME`, `TARGET_TYPE`, `TARGET_FORMAT` | the output's name, GLSL type, and the attachment it needs |
|
|
192
|
+
|
|
193
|
+
## Dependencies
|
|
194
|
+
|
|
195
|
+
`vcti-shader-base` is the only runtime dependency — declaring a feature is pure
|
|
196
|
+
data. `vcti-shader-compiler>=4.0.0` and `numpy` are test-only, and a separate
|
|
197
|
+
`gl` extra adds the GL binding the shader tests need to execute rather than
|
|
198
|
+
skip.
|
|
199
|
+
|
|
200
|
+
## Documentation
|
|
201
|
+
|
|
202
|
+
| If you want to… | Read |
|
|
203
|
+
|---|---|
|
|
204
|
+
| Get started using the package | Quick Start above |
|
|
205
|
+
| Understand the texel contract and the decisions behind it | [docs/design.md](docs/design.md) |
|
|
206
|
+
| Navigate or modify the source, including the Slang | [docs/source-guide.md](docs/source-guide.md) |
|
|
207
|
+
|
|
208
|
+
The full API reference is generated from the source docstrings and published in
|
|
209
|
+
the unified VCollab docs.
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# vcti-shader-pick
|
|
2
|
+
|
|
3
|
+
The pick shader feature: the fragment-stage pass that writes identifiers for the geometry at each pixel.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
A viewer has to answer "what did the user just click on", and the only thing
|
|
8
|
+
that knows which surface covers which pixel is the rasterizer. So the answer is
|
|
9
|
+
produced the same way the picture is: by drawing. A **pick pass** renders the
|
|
10
|
+
scene to an integer target and writes, at every pixel, identifiers for the
|
|
11
|
+
geometry that landed there — plus how far away it was.
|
|
12
|
+
|
|
13
|
+
Reading one texel back then answers the click. What those identifiers *mean* is
|
|
14
|
+
not this package's business: one names the atom, and the other is opaque,
|
|
15
|
+
resolved by whoever owns the source model. That is what lets the same pass serve
|
|
16
|
+
an element, a face, a triangle, or something not yet invented, without changing
|
|
17
|
+
a line of shader source.
|
|
18
|
+
|
|
19
|
+
`vcti-shader-pick` ships the Slang that packs a texel, a Python mirror of the
|
|
20
|
+
same layout for decoding a readback, and the `ShaderDefinition` saying what the
|
|
21
|
+
feature is. Everything here is a declaration or fixed shader source; nothing
|
|
22
|
+
compiles, runs, or reads back a shader.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install vcti-shader-pick
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Requires Python 3.12, 3.13, or 3.14, matching `vcti-shader-base`. Nothing native
|
|
31
|
+
is built on that path, and nothing native is built by `[test]` either — only the
|
|
32
|
+
`[gl]` extra pulls a GL binding, and only on 3.14 does that compile from source
|
|
33
|
+
for want of a cp314 wheel.
|
|
34
|
+
|
|
35
|
+
### In `requirements.txt`
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
vcti-shader-pick>=1.0.0
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### In `pyproject.toml` dependencies
|
|
42
|
+
|
|
43
|
+
```toml
|
|
44
|
+
dependencies = [
|
|
45
|
+
"vcti-shader-pick>=1.0.0",
|
|
46
|
+
]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
50
|
+
|
|
51
|
+
### What a build step binds
|
|
52
|
+
|
|
53
|
+
The feature declares two per-vertex identifiers and one integer target. Both
|
|
54
|
+
identifiers must reach the fragment stage as `flat` varyings — GLSL ES requires
|
|
55
|
+
that of every integer varying, and it is what keeps them exact:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from vcti.shader.pick import fragment_inputs, fragment_outputs, fragment_uniforms
|
|
59
|
+
|
|
60
|
+
inputs = fragment_inputs()
|
|
61
|
+
assert [attribute.name for attribute in inputs] == ["a_atomId", "a_pickIndex"]
|
|
62
|
+
assert inputs[0].semantic == "atom-id"
|
|
63
|
+
|
|
64
|
+
assert fragment_outputs()[0].name == "pickTarget"
|
|
65
|
+
assert fragment_uniforms() == ()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`a_atomId` is declared identically by another atom-aware feature, so the two
|
|
69
|
+
merge into one attribute when they are composed. `a_pickIndex` is this feature's
|
|
70
|
+
own, and is opaque to everything in the shader.
|
|
71
|
+
|
|
72
|
+
### Reading a click back
|
|
73
|
+
|
|
74
|
+
The target is four unsigned 32-bit channels. Clear it to `PICK_EMPTY` before the
|
|
75
|
+
pass, and draw the pass depth-tested, unblended and single-sampled — each of
|
|
76
|
+
those is the caller's to get right, and each fails silently, which
|
|
77
|
+
[design.md](docs/design.md) explains. Then decode the texel under the cursor:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from vcti.shader.pick import PICK_EMPTY, decode, float_to_bits
|
|
81
|
+
|
|
82
|
+
nothing = decode((PICK_EMPTY, PICK_EMPTY, PICK_EMPTY, PICK_EMPTY))
|
|
83
|
+
assert nothing is None
|
|
84
|
+
|
|
85
|
+
hit = decode((7, 4_210_001, float_to_bits(12.5), 0))
|
|
86
|
+
assert hit is not None
|
|
87
|
+
assert hit.atom_id == 7
|
|
88
|
+
assert hit.pick_index == 4_210_001
|
|
89
|
+
assert hit.depth == 12.5
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The depth is measured along the camera's forward axis — `-z` in view space,
|
|
93
|
+
positive in front of the camera — not from the eye to the point. Give it the
|
|
94
|
+
pixel's ray, and `reconstruct_view_position` returns the point:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from vcti.shader.pick import reconstruct_view_position
|
|
98
|
+
|
|
99
|
+
# A perspective ray: the origin is the eye, at the view-space origin.
|
|
100
|
+
point = reconstruct_view_position(12.5, (0.0, 0.0, 0.0), (0.3, 0.2, -1.0))
|
|
101
|
+
assert point == (3.75, 2.5, -12.5)
|
|
102
|
+
|
|
103
|
+
# An orthographic ray: parallel, each starting at its own point.
|
|
104
|
+
point = reconstruct_view_position(12.5, (2.0, 1.0, -0.1), (0.0, 0.0, -1.0))
|
|
105
|
+
assert point == (2.0, 1.0, -12.5)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The ray is yours to build — inverting the projection and knowing which way the
|
|
109
|
+
viewport's Y runs are the caller's, because the caller owns the camera. What the
|
|
110
|
+
depth *means* is this package's, which is why the inverse ships here rather than
|
|
111
|
+
being a formula every caller re-derives. `direction` need not be normalized, and
|
|
112
|
+
the origin need not sit on the camera plane: a ray unprojected to the near plane
|
|
113
|
+
works as given.
|
|
114
|
+
|
|
115
|
+
A Euclidean distance from the eye would have cost the same channel and been
|
|
116
|
+
wrong for any ray not starting at a single shared point.
|
|
117
|
+
|
|
118
|
+
Note that `depth` is *reinterpreted* from its bits rather than converted:
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from vcti.shader.pick import bits_to_float
|
|
122
|
+
|
|
123
|
+
assert bits_to_float(float_to_bits(12.5)) == 12.5
|
|
124
|
+
assert float_to_bits(1.0) > 1_000_000_000 # the same bits read as an int
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Selecting a pipeline
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from vcti.shader.pick import DEFINITION
|
|
131
|
+
|
|
132
|
+
assert DEFINITION.id == "pick"
|
|
133
|
+
assert DEFINITION.role.value == "fragment"
|
|
134
|
+
assert DEFINITION.capabilities == ("pick",)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## The texel
|
|
138
|
+
|
|
139
|
+
| Channel | Holds |
|
|
140
|
+
|---|---|
|
|
141
|
+
| `R` | `a_atomId` |
|
|
142
|
+
| `G` | `a_pickIndex` |
|
|
143
|
+
| `B` | the view depth, as reinterpreted `float32` bits |
|
|
144
|
+
| `A` | reserved, written as zero |
|
|
145
|
+
|
|
146
|
+
An integer target rather than a float one because identifiers must survive
|
|
147
|
+
exactly: a `float32` carries consecutive integers only to 2²⁴, above which one
|
|
148
|
+
arrives as its neighbour and resolves to different geometry — a failure that
|
|
149
|
+
looks like a mis-click rather than like corruption.
|
|
150
|
+
|
|
151
|
+
## API surface
|
|
152
|
+
|
|
153
|
+
| Name | What it is |
|
|
154
|
+
|---|---|
|
|
155
|
+
| `DEFINITION` | the `ShaderDefinition` a build step imports to compose this feature |
|
|
156
|
+
| `SLANG_DIR` | the installed Slang directory |
|
|
157
|
+
| `fragment_inputs`, `fragment_outputs`, `fragment_uniforms` | what a build step binds |
|
|
158
|
+
| `decode`, `is_empty`, `Pick` | read a texel of a pick readback |
|
|
159
|
+
| `bits_to_float`, `float_to_bits` | the bit reinterpretation, on its own |
|
|
160
|
+
| `reconstruct_view_position` | a ray and a depth to the view-space point |
|
|
161
|
+
| `PICK_EMPTY`, `PICK_RESERVED`, `CHANNELS` | the layout, as data |
|
|
162
|
+
| `TARGET_NAME`, `TARGET_TYPE`, `TARGET_FORMAT` | the output's name, GLSL type, and the attachment it needs |
|
|
163
|
+
|
|
164
|
+
## Dependencies
|
|
165
|
+
|
|
166
|
+
`vcti-shader-base` is the only runtime dependency — declaring a feature is pure
|
|
167
|
+
data. `vcti-shader-compiler>=4.0.0` and `numpy` are test-only, and a separate
|
|
168
|
+
`gl` extra adds the GL binding the shader tests need to execute rather than
|
|
169
|
+
skip.
|
|
170
|
+
|
|
171
|
+
## Documentation
|
|
172
|
+
|
|
173
|
+
| If you want to… | Read |
|
|
174
|
+
|---|---|
|
|
175
|
+
| Get started using the package | Quick Start above |
|
|
176
|
+
| Understand the texel contract and the decisions behind it | [docs/design.md](docs/design.md) |
|
|
177
|
+
| Navigate or modify the source, including the Slang | [docs/source-guide.md](docs/source-guide.md) |
|
|
178
|
+
|
|
179
|
+
The full API reference is generated from the source docstrings and published in
|
|
180
|
+
the unified VCollab docs.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vcti-shader-pick"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "The pick shader feature: the fragment-stage pass that writes identifiers for the geometry at each pixel."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{name = "Visual Collaboration Technologies Inc."}
|
|
12
|
+
]
|
|
13
|
+
license = "LicenseRef-Proprietary"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Programming Language :: Python :: 3.14",
|
|
20
|
+
]
|
|
21
|
+
# Tracks vcti-shader-base, the only runtime dependency. Installing the package
|
|
22
|
+
# is pure data and works anywhere it does, and so does `[test]`: the compiler
|
|
23
|
+
# stopped pulling moderngl in its 3.0, so nothing on that path compiles a GL
|
|
24
|
+
# binding from source. Only `[gl]` does, and on 3.14 that still builds
|
|
25
|
+
# moderngl's glcontext from its sdist for want of a cp314 wheel — which is why
|
|
26
|
+
# ci-shader.yml, the one job that needs it, pins itself to 3.12.
|
|
27
|
+
requires-python = ">=3.12,<3.15"
|
|
28
|
+
dependencies = [
|
|
29
|
+
# 2.1.0 is where OutputSpec grew `format`, which is what lets this feature
|
|
30
|
+
# declare that its target must be `rgba32ui` rather than describe it in
|
|
31
|
+
# prose. A `uvec4` output alone is satisfied by an `rgba8ui` attachment,
|
|
32
|
+
# which truncates every identifier to eight bits without failing, so the
|
|
33
|
+
# floor is what turns that from documentation into a declaration.
|
|
34
|
+
"vcti-shader-base>=2.1.0",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Repository = "https://github.com/vcollab/vcti-python-shader-pick"
|
|
39
|
+
Changelog = "https://github.com/vcollab/vcti-python-shader-pick/blob/main/CHANGELOG.md"
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.packages.find]
|
|
42
|
+
where = ["src"]
|
|
43
|
+
include = ["vcti.shader.pick", "vcti.shader.pick.*"]
|
|
44
|
+
|
|
45
|
+
[tool.setuptools.package-data]
|
|
46
|
+
"vcti.shader.pick" = ["py.typed", "slang/*.slang"]
|
|
47
|
+
|
|
48
|
+
[project.optional-dependencies]
|
|
49
|
+
# The compiler and numpy are needed only to *test* the shader — run the
|
|
50
|
+
# encoding headlessly and diff it against the Python mirror — not to declare
|
|
51
|
+
# the feature.
|
|
52
|
+
#
|
|
53
|
+
# Two things set the floor. 3.0 is where the `gl` extra appeared at all —
|
|
54
|
+
# against anything earlier pip warns the extra does not exist and installs on
|
|
55
|
+
# without the binding, so the probes skip and ci-shader.yml fails reporting a
|
|
56
|
+
# skip rather than the missing pin. 4.0 is where `compile_stages` links the
|
|
57
|
+
# vertex and fragment stages instead of validating each alone, which is what
|
|
58
|
+
# makes a probe compiling mean the pair actually links: the probes here are
|
|
59
|
+
# such a pair, so the floor is what turns this suite's guarantee from
|
|
60
|
+
# incidental into stated.
|
|
61
|
+
#
|
|
62
|
+
# The compiler stays in `test` rather than moving here: tests/test_pick_math.py
|
|
63
|
+
# imports render_readback at module scope, so without it the tests fail to
|
|
64
|
+
# collect instead of skipping. `gl` adds the binding that makes them run.
|
|
65
|
+
gl = ["vcti-shader-compiler[gl]>=4.0.0"]
|
|
66
|
+
test = ["pytest", "pytest-cov", "vcti-shader-compiler>=4.0.0", "numpy"]
|
|
67
|
+
lint = ["ruff"]
|
|
68
|
+
typecheck = ["mypy"]
|
|
69
|
+
|
|
70
|
+
[tool.pytest.ini_options]
|
|
71
|
+
addopts = "--cov=vcti.shader.pick --cov-report=term-missing --cov-fail-under=95"
|
|
72
|
+
|
|
73
|
+
[tool.mypy]
|
|
74
|
+
python_version = "3.12"
|
|
75
|
+
strict = true
|
|
76
|
+
files = ["src"]
|
|
77
|
+
namespace_packages = true
|
|
78
|
+
explicit_package_bases = true
|
|
79
|
+
mypy_path = ["src"]
|
|
80
|
+
|
|
81
|
+
[tool.coverage.run]
|
|
82
|
+
branch = true
|
|
83
|
+
|
|
84
|
+
[tool.coverage.report]
|
|
85
|
+
exclude_also = [
|
|
86
|
+
"raise NotImplementedError",
|
|
87
|
+
"if TYPE_CHECKING:",
|
|
88
|
+
"if __name__ == .__main__.:",
|
|
89
|
+
"@(abc\\.)?abstractmethod",
|
|
90
|
+
"\\.\\.\\.",
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
[tool.ruff]
|
|
94
|
+
target-version = "py312"
|
|
95
|
+
line-length = 99
|
|
96
|
+
|
|
97
|
+
[tool.ruff.lint]
|
|
98
|
+
select = ["E", "F", "W", "I", "UP"]
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Copyright Visual Collaboration Technologies Inc. All Rights Reserved.
|
|
2
|
+
# See LICENSE for details.
|
|
3
|
+
"""vcti.shader.pick — the pick shader feature.
|
|
4
|
+
|
|
5
|
+
The fragment stage that records *what* is at each pixel rather than what colour
|
|
6
|
+
it is. A pass built from it renders to an integer target; reading one texel back
|
|
7
|
+
says which geometry was drawn there and how far away it was, which is how a
|
|
8
|
+
viewer answers "what did the user just click on".
|
|
9
|
+
|
|
10
|
+
The package is three things — the Slang module carrying the encoding
|
|
11
|
+
(``pick.slang``), a Python mirror of the same texel layout, and the
|
|
12
|
+
:class:`~vcti.shader.base.ShaderDefinition` saying what the feature is.
|
|
13
|
+
|
|
14
|
+
All three are declarations, which is why `vcti-shader-base` is the only runtime
|
|
15
|
+
dependency and nothing here executes: importing this package gets you a
|
|
16
|
+
description of the encoding and a decoder for a readback, not a way to run the
|
|
17
|
+
shader or to read one back. Building a shader from it and running that shader
|
|
18
|
+
belong to other packages, and to the tests, which drive the compiler's
|
|
19
|
+
``render_readback`` directly — so `vcti-shader-compiler` is a test dependency
|
|
20
|
+
only.
|
|
21
|
+
|
|
22
|
+
Resolving a ``pick_index`` to an element, a node or a measurement is nobody's
|
|
23
|
+
job here: the identifier is opaque, and what it names belongs to whoever owns
|
|
24
|
+
the source model. See ``docs/design.md``.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from importlib.metadata import version
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
from vcti.shader.base import ShaderDefinition, StageRole
|
|
31
|
+
|
|
32
|
+
from .specs import (
|
|
33
|
+
TARGET_FORMAT,
|
|
34
|
+
TARGET_NAME,
|
|
35
|
+
TARGET_TYPE,
|
|
36
|
+
fragment_inputs,
|
|
37
|
+
fragment_outputs,
|
|
38
|
+
fragment_uniforms,
|
|
39
|
+
)
|
|
40
|
+
from .texel import (
|
|
41
|
+
CHANNELS,
|
|
42
|
+
PICK_EMPTY,
|
|
43
|
+
PICK_RESERVED,
|
|
44
|
+
Pick,
|
|
45
|
+
bits_to_float,
|
|
46
|
+
decode,
|
|
47
|
+
float_to_bits,
|
|
48
|
+
is_empty,
|
|
49
|
+
reconstruct_view_position,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
__version__ = version("vcti-shader-pick")
|
|
53
|
+
|
|
54
|
+
# Resolved from __file__ because only this package can: the .slang file installs
|
|
55
|
+
# inside it, wherever pip put that. Exported because a caller has to pass it to
|
|
56
|
+
# the compiler as an `import` search path — via DEFINITION.slang_dir, or directly
|
|
57
|
+
# as the tests do.
|
|
58
|
+
SLANG_DIR = Path(__file__).parent / "slang"
|
|
59
|
+
|
|
60
|
+
# Built at import, so importing the package is all it takes to have a DEFINITION.
|
|
61
|
+
# Nothing discovers this feature: whatever composes features imports this, and
|
|
62
|
+
# that import is the whole of the registration step.
|
|
63
|
+
DEFINITION = ShaderDefinition(
|
|
64
|
+
id="pick",
|
|
65
|
+
role=StageRole.FRAGMENT,
|
|
66
|
+
capabilities=("pick",),
|
|
67
|
+
slang_modules=("pick.slang",),
|
|
68
|
+
slang_dir=SLANG_DIR,
|
|
69
|
+
description="Writes per-pixel geometry identifiers and view depth to an integer target.",
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
__all__ = [
|
|
73
|
+
"CHANNELS",
|
|
74
|
+
"DEFINITION",
|
|
75
|
+
"PICK_EMPTY",
|
|
76
|
+
"PICK_RESERVED",
|
|
77
|
+
"SLANG_DIR",
|
|
78
|
+
"TARGET_FORMAT",
|
|
79
|
+
"TARGET_NAME",
|
|
80
|
+
"TARGET_TYPE",
|
|
81
|
+
"Pick",
|
|
82
|
+
"__version__",
|
|
83
|
+
"bits_to_float",
|
|
84
|
+
"decode",
|
|
85
|
+
"float_to_bits",
|
|
86
|
+
"fragment_inputs",
|
|
87
|
+
"fragment_outputs",
|
|
88
|
+
"fragment_uniforms",
|
|
89
|
+
"is_empty",
|
|
90
|
+
"reconstruct_view_position",
|
|
91
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.
|
|
2
|
+
// See LICENSE for details.
|
|
3
|
+
//
|
|
4
|
+
// The pick encoding: the identifiers and the depth a fragment writes, packed
|
|
5
|
+
// into one integer texel.
|
|
6
|
+
//
|
|
7
|
+
// Everything arrives as an argument and nothing here reads a uniform, a varying
|
|
8
|
+
// or a texture, so the caller decides where the values come from -- varyings in
|
|
9
|
+
// a built shader, a texture in a probe -- and this module is the same in both.
|
|
10
|
+
// That shared use is what the validation rests on: the probe runs the very code
|
|
11
|
+
// an emitted shader would.
|
|
12
|
+
//
|
|
13
|
+
// The channel order and the sentinel are mirrored by texel.py, which is what a
|
|
14
|
+
// caller decodes a readback with; tests/test_texel.py reads this file and pins
|
|
15
|
+
// the two together. Without that a swapped channel still produces four plausible
|
|
16
|
+
// integers, and the readback resolves to the wrong geometry rather than failing.
|
|
17
|
+
|
|
18
|
+
module pick;
|
|
19
|
+
|
|
20
|
+
// The value a texel carries when no geometry was drawn at that pixel.
|
|
21
|
+
//
|
|
22
|
+
// Absence has to be signalled by the clear rather than by a spare channel,
|
|
23
|
+
// because the four channels are all spoken for. The caller clears the target to
|
|
24
|
+
// this before the pass; a pixel nothing covered keeps it. Identifiers must
|
|
25
|
+
// therefore never take this value -- they are assigned by whatever builds the
|
|
26
|
+
// vertex data, which never approaches the top of the range.
|
|
27
|
+
static const uint PICK_EMPTY = 0xFFFFFFFFu;
|
|
28
|
+
|
|
29
|
+
// Written into the reserved channel. Zero rather than PICK_EMPTY, so that a
|
|
30
|
+
// texel a fragment wrote is distinguishable from the clear in every channel,
|
|
31
|
+
// and so a field added here later starts from a known value.
|
|
32
|
+
static const uint PICK_RESERVED = 0u;
|
|
33
|
+
|
|
34
|
+
// The texel identifying the geometry at this fragment.
|
|
35
|
+
//
|
|
36
|
+
// `viewPosition` is the fragment's position in view space, and the depth written
|
|
37
|
+
// is `-viewPosition.z`: the distance along the camera's forward axis, positive
|
|
38
|
+
// in front of it. A caller recovers the point by solving its own view-space ray
|
|
39
|
+
// for the scale that lands at `z == -depth`; texel.py ships that inverse as
|
|
40
|
+
// reconstruct_view_position, so no caller has to re-derive it.
|
|
41
|
+
//
|
|
42
|
+
// Depth along the axis rather than the Euclidean length from the eye, because
|
|
43
|
+
// the length is only a distance where the rays share an origin. Under an
|
|
44
|
+
// orthographic projection they do not -- every pixel's ray starts at its own
|
|
45
|
+
// point on the near plane -- so `length(viewPosition)` measures from a point no
|
|
46
|
+
// ray passes through, and the reconstruction above is wrong by however far the
|
|
47
|
+
// pixel is from the centre. The axial depth is the same one channel and is
|
|
48
|
+
// correct under both projections, including an orthographic ray, whose direction
|
|
49
|
+
// is `(0, 0, -1)` and whose origin is its own point rather than a shared eye.
|
|
50
|
+
//
|
|
51
|
+
// It is negated here rather than by the caller because the sign convention is
|
|
52
|
+
// part of the encoding: view space looks down -z, so a fragment in front of the
|
|
53
|
+
// camera has a negative z and a positive depth. Computing it here also keeps the
|
|
54
|
+
// definition in one place, where a probe checks the one that ships.
|
|
55
|
+
//
|
|
56
|
+
// The identifiers are reinterpreted, not converted: an integer target carries
|
|
57
|
+
// them exactly, where a float one would round anything above 2^24 into a
|
|
58
|
+
// neighbouring value and resolve to the wrong geometry. The depth is bit-cast
|
|
59
|
+
// for the same reason in reverse -- it is a float riding in an integer channel,
|
|
60
|
+
// and asuint/asfloat round-trips every value exactly.
|
|
61
|
+
public uint4 pickTexel(int atomId, int pickIndex, float3 viewPosition)
|
|
62
|
+
{
|
|
63
|
+
return uint4(
|
|
64
|
+
uint(atomId),
|
|
65
|
+
uint(pickIndex),
|
|
66
|
+
asuint(-viewPosition.z),
|
|
67
|
+
PICK_RESERVED);
|
|
68
|
+
}
|