@vcollab/shader-webgl2 0.0.0-stage → 1.0.0
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.
- package/CHANGELOG.md +51 -0
- package/LICENSE +8 -0
- package/README.md +154 -2
- package/dist/index.cjs +511 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +503 -0
- package/dist/index.js.map +1 -0
- package/dist/pick.d.ts +96 -0
- package/dist/pipeline.d.ts +130 -0
- package/dist/version.d.ts +2 -0
- package/package.json +60 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@vcollab/shader-webgl2` are documented here.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
|
|
6
|
+
this package adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] — 2026-12-03
|
|
9
|
+
|
|
10
|
+
First release. Extracted from the playground's renderer, which had already
|
|
11
|
+
written the binding layer generically; this package is that code with the
|
|
12
|
+
playground's policy removed.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- `GLPipeline`: one envelope bound to a WebGL2 context — compiles and links the
|
|
17
|
+
stage pair, binds the emitted uniform block, matches attributes and resources
|
|
18
|
+
by semantic, uploads the block and draws. It decides no values.
|
|
19
|
+
- The uniform buffer is sized at the larger of the envelope's `blockSize` and
|
|
20
|
+
the driver's `UNIFORM_BLOCK_DATA_SIZE`; a driver block too small for the
|
|
21
|
+
reflected layout is refused.
|
|
22
|
+
- `setGeometry` checks each source against the contract: `int`/`ivecN`
|
|
23
|
+
inputs take `Int32Array` data, `float`/`vecN` inputs `Float32Array`,
|
|
24
|
+
`components` is at least the declared width, and
|
|
25
|
+
`AttributeSource.integer` agrees with the declared type. Calling it again
|
|
26
|
+
frees the previous geometry's buffers.
|
|
27
|
+
- An attribute the caller did not supply reads a zero constant, set at every
|
|
28
|
+
draw because it is context state rather than vertex-array state.
|
|
29
|
+
- `draw` throws `GLPipelineError` naming every semantic in
|
|
30
|
+
`requiredSemantics` that has no texture.
|
|
31
|
+
- Every GL object made before a failed step is freed before the error is
|
|
32
|
+
rethrown.
|
|
33
|
+
- `PickPass`: the pick pipeline drawn into an offscreen `rgba32ui` target with
|
|
34
|
+
a depth buffer, one pixel read back and decoded. Hit-testing is a second draw
|
|
35
|
+
rather than a second attachment on the color pipeline — see
|
|
36
|
+
[docs/design.md](docs/design.md) §4 for why.
|
|
37
|
+
- `pick` sets the state the pass depends on (scissor test off, every color
|
|
38
|
+
and depth write on, depth testing on with `LESS`, blending off), resets
|
|
39
|
+
the readback to `PICK_EMPTY` before reading, and afterwards restores that
|
|
40
|
+
state, the viewport and the caller's draw and read framebuffers, even if
|
|
41
|
+
the draw throws. Face culling is left as the caller set it.
|
|
42
|
+
- `fromCanvasPoint` converts a CSS-pixel offset to the integer device pixel
|
|
43
|
+
GL reads: `x = floor(offsetX * scaleX)`,
|
|
44
|
+
`y = height - 1 - floor(offsetY * scaleY)`.
|
|
45
|
+
- `resize` rebuilds only when the floored size changes, checks every object
|
|
46
|
+
and the framebuffer's completeness, and puts back the caller's bindings.
|
|
47
|
+
- `linkProgram`, `UNIFORM_BLOCK_NAME` and `UNIFORM_BLOCK_BINDING` for a caller
|
|
48
|
+
managing its own program.
|
|
49
|
+
- Documented: context loss is not handled (rebuild every object after
|
|
50
|
+
`webglcontextrestored`), and an integer table (`usampler2D`) needs `NEAREST`
|
|
51
|
+
filtering and no mipmaps.
|
package/LICENSE
ADDED
|
@@ -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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,155 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vcollab/shader-webgl2
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Binds a VCollab shader pipeline envelope to a WebGL2 context: programs,
|
|
4
|
+
attributes, uniform blocks, resources, and the pick pass.
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
The shaders are built offline and shipped as an artifact set.
|
|
9
|
+
[`@vcollab/shader-library`](../shader-library/README.md) reads that set and
|
|
10
|
+
tells a renderer what to bind and where; this is the renderer half for WebGL2.
|
|
11
|
+
|
|
12
|
+
Everything it does is driven by the envelope and nothing by knowledge of a
|
|
13
|
+
particular shader: the contract says which attributes to supply, the layout
|
|
14
|
+
says where each uniform sits, and the bindings say which sampler uniform and
|
|
15
|
+
texture unit each resource takes. A pipeline this package has never heard of
|
|
16
|
+
binds correctly as long as the set describes it.
|
|
17
|
+
|
|
18
|
+
**It decides no values.** Which uniforms to write, what to put in them, and
|
|
19
|
+
what a table or image holds are the caller's. That split is what keeps a
|
|
20
|
+
viewer's policy out of the binding layer, and the binding layer out of every
|
|
21
|
+
viewer.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm add @vcollab/shader-webgl2 @vcollab/shader-library
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { openBundledSet } from "@vcollab/shader-library/bundled";
|
|
33
|
+
import { GLPipeline } from "@vcollab/shader-webgl2";
|
|
34
|
+
|
|
35
|
+
const set = await openBundledSet();
|
|
36
|
+
const pipeline = new GLPipeline(gl, await set.envelope("deform3.symtensor"));
|
|
37
|
+
|
|
38
|
+
// Attributes are matched by the contract's semantic, never by declared name.
|
|
39
|
+
// A float/vecN input takes a Float32Array, an int/ivecN input an Int32Array.
|
|
40
|
+
pipeline.setGeometry({
|
|
41
|
+
attributes: new Map([
|
|
42
|
+
["coordinates", { data: positions, components: 3, integer: false }], // Float32Array
|
|
43
|
+
["mask-id", { data: atomIds, components: 1, integer: true }], // Int32Array
|
|
44
|
+
]),
|
|
45
|
+
indices, // Uint32Array
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Resources by semantic too — the declared name does not reach the program.
|
|
49
|
+
// Every semantic the pipeline binds needs a texture, or draw() throws.
|
|
50
|
+
const textures = new Map<string, WebGLTexture>([
|
|
51
|
+
["mask", maskTable],
|
|
52
|
+
["transform", transformTable],
|
|
53
|
+
["material", materialTable],
|
|
54
|
+
]);
|
|
55
|
+
for (const semantic of pipeline.requiredSemantics) {
|
|
56
|
+
const texture = textures.get(semantic);
|
|
57
|
+
if (texture === undefined) throw new Error(`no texture for ${semantic}`);
|
|
58
|
+
pipeline.setTexture(semantic, texture);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function frame(camera) {
|
|
62
|
+
pipeline.uniforms.set("u_mvpMatrix", camera.mvp); // column-major in
|
|
63
|
+
pipeline.uniforms.set("u_colorSource", 2);
|
|
64
|
+
pipeline.draw();
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
An attribute you do not supply is left as a disabled array with a constant,
|
|
69
|
+
which is how a viewer expresses "this draw has no such data" — the same
|
|
70
|
+
"off state is data" the always-present features rely on.
|
|
71
|
+
|
|
72
|
+
### What it refuses
|
|
73
|
+
|
|
74
|
+
Input it cannot use is refused with a `GLPipelineError` rather than skipped,
|
|
75
|
+
because a skipped binding draws a plausible wrong picture:
|
|
76
|
+
|
|
77
|
+
- `setGeometry` refuses a source whose data type or `integer` flag does not
|
|
78
|
+
match the declared type, or whose `components` is narrower than the declared
|
|
79
|
+
width. Calling it again replaces the previous geometry and frees its buffers.
|
|
80
|
+
- `draw` refuses to run while any semantic in `requiredSemantics` has no
|
|
81
|
+
texture, and names every one missing.
|
|
82
|
+
- The constructor refuses a driver whose size for the uniform block differs
|
|
83
|
+
from the size the build reflected.
|
|
84
|
+
|
|
85
|
+
### What stays with the caller
|
|
86
|
+
|
|
87
|
+
- **Context loss is not handled.** After `webglcontextrestored`, every
|
|
88
|
+
`GLPipeline` and `PickPass` from the lost context is dead: build new ones and
|
|
89
|
+
set their geometry and textures again.
|
|
90
|
+
- **Integer tables** (`usampler2D`) must use `NEAREST` filtering and no
|
|
91
|
+
mipmaps; anything else makes the texture incomplete and every fetch reads
|
|
92
|
+
zero.
|
|
93
|
+
- **`draw` leaves GL state changed**: the current program, the active texture
|
|
94
|
+
unit and the textures bound on the pipeline's units.
|
|
95
|
+
|
|
96
|
+
## Picking
|
|
97
|
+
|
|
98
|
+
The pick shape writes identifiers *instead of* a color, so hit-testing is a
|
|
99
|
+
second draw of the same geometry rather than a feature added to the color
|
|
100
|
+
pipeline. That is much the cheaper arrangement: the extra draw happens when
|
|
101
|
+
someone clicks, where making the color pipeline write a second attachment
|
|
102
|
+
would cost bandwidth on every frame, force every consumer off the default
|
|
103
|
+
framebuffer, and give up multisampling — an integer attachment cannot be
|
|
104
|
+
multisampled, and every attachment of a framebuffer shares its sample count.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import { pickPipelineFor } from "@vcollab/shader-library";
|
|
108
|
+
import { GLPipeline, PickPass } from "@vcollab/shader-webgl2";
|
|
109
|
+
|
|
110
|
+
// The pick pipeline whose vertex stage matches the color one, so deformed
|
|
111
|
+
// geometry is picked where it is drawn.
|
|
112
|
+
const entry = pickPipelineFor(set.registry, set.entry("deform3.symtensor"));
|
|
113
|
+
const pass = new PickPass(gl, new GLPipeline(gl, await set.envelope(entry.id)));
|
|
114
|
+
pass.pipeline.setGeometry(geometry);
|
|
115
|
+
// deform3.pick binds "mask" and "transform"; set whatever it lists.
|
|
116
|
+
for (const semantic of pass.pipeline.requiredSemantics) {
|
|
117
|
+
const texture = textures.get(semantic);
|
|
118
|
+
if (texture === undefined) throw new Error(`no texture for ${semantic}`);
|
|
119
|
+
pass.pipeline.setTexture(semantic, texture);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
canvas.addEventListener("pointerdown", (event) => {
|
|
123
|
+
pass.resize(canvas.width, canvas.height);
|
|
124
|
+
const { x, y } = PickPass.fromCanvasPoint(canvas, event.offsetX, event.offsetY);
|
|
125
|
+
// Write the uniforms from the same state the color pass used, or the pick
|
|
126
|
+
// names something the viewer cannot see.
|
|
127
|
+
const hit = pass.pick(x, y, (uniforms) => writeUniforms(uniforms, currentState));
|
|
128
|
+
if (hit !== null) select(hit.primitiveId, hit.depth);
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`pick` returns `null` where nothing was drawn. The target is cleared to
|
|
133
|
+
`PICK_EMPTY` and the texel decoded by `@vcollab/shader-library` — the depth
|
|
134
|
+
channel holds the *bits* of a float, so it cannot be read as a number.
|
|
135
|
+
|
|
136
|
+
`fromCanvasPoint` returns the integer device pixel under the point, counted
|
|
137
|
+
from the bottom row: the top CSS row is row `canvas.height - 1`.
|
|
138
|
+
|
|
139
|
+
The pass draws into its own framebuffer. For the draw it turns the scissor
|
|
140
|
+
test and blending off, depth testing on with `LESS`, and every color and depth
|
|
141
|
+
write on; afterwards it puts back each of those, the viewport and the caller's
|
|
142
|
+
draw and read framebuffers, even if the draw throws. Face culling is left as
|
|
143
|
+
the caller set it, so the pick honours winding exactly as the color pass does.
|
|
144
|
+
|
|
145
|
+
## Dependencies
|
|
146
|
+
|
|
147
|
+
`@vcollab/shader-library` is a normal dependency. There are no peers, and the
|
|
148
|
+
package touches nothing but the `WebGL2RenderingContext` it is handed.
|
|
149
|
+
|
|
150
|
+
## Documentation
|
|
151
|
+
|
|
152
|
+
| If you want to… | Read |
|
|
153
|
+
|---|---|
|
|
154
|
+
| Understand the design and what this package does not do | [docs/design.md](docs/design.md) |
|
|
155
|
+
| Look up an export | [docs/api.md](docs/api.md) |
|