@kitware/vtk.js 24.5.2 → 24.5.5
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/Common/DataModel/DataSetAttributes/FieldData.d.ts +3 -1
- package/Rendering/Core/RenderWindowInteractor.d.ts +123 -109
- package/Rendering/Core/ScalarBarActor.js +2 -2
- package/Rendering/OpenGL/OrderIndependentTranslucentPass.js +5 -1
- package/Rendering/OpenGL/RenderWindow.d.ts +1 -1
- package/Rendering/OpenGL/VolumeMapper.js +1 -1
- package/Rendering/SceneGraph/ViewNode.js +28 -2
- package/Rendering/WebGPU/BufferManager.js +83 -14
- package/Rendering/WebGPU/CellArrayMapper.js +591 -0
- package/Rendering/WebGPU/Device.js +97 -57
- package/Rendering/WebGPU/FullScreenQuad.js +4 -6
- package/Rendering/WebGPU/Glyph3DMapper.js +62 -27
- package/Rendering/WebGPU/ImageMapper.js +23 -64
- package/Rendering/WebGPU/OrderIndependentTranslucentPass.js +4 -6
- package/Rendering/WebGPU/Pipeline.js +12 -0
- package/Rendering/WebGPU/PolyDataMapper.js +49 -623
- package/Rendering/WebGPU/RenderEncoder.js +34 -0
- package/Rendering/WebGPU/Renderer.js +4 -62
- package/Rendering/WebGPU/ShaderDescription.js +6 -6
- package/Rendering/WebGPU/{MapperHelper.js → SimpleMapper.js} +64 -38
- package/Rendering/WebGPU/SphereMapper.js +66 -64
- package/Rendering/WebGPU/StickMapper.js +73 -72
- package/Rendering/WebGPU/StorageBuffer.js +2 -3
- package/Rendering/WebGPU/Texture.js +0 -2
- package/Rendering/WebGPU/TextureManager.js +37 -7
- package/Rendering/WebGPU/UniformBuffer.js +1 -2
- package/Rendering/WebGPU/Volume.js +1 -14
- package/Rendering/WebGPU/VolumePass.js +16 -22
- package/Rendering/WebGPU/VolumePassFSQ.js +19 -29
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@ function vtkWebGPURenderEncoder(publicAPI, model) {
|
|
|
10
10
|
model.classHierarchy.push('vtkWebGPURenderEncoder');
|
|
11
11
|
|
|
12
12
|
publicAPI.begin = function (encoder) {
|
|
13
|
+
model.drawCallbacks = [];
|
|
13
14
|
model.handle = encoder.beginRenderPass(model.description);
|
|
14
15
|
|
|
15
16
|
if (model.label) {
|
|
@@ -18,14 +19,30 @@ function vtkWebGPURenderEncoder(publicAPI, model) {
|
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
publicAPI.end = function () {
|
|
22
|
+
// loop over registered pipelines and their callbacks
|
|
23
|
+
for (var i = 0; i < model.drawCallbacks.length; i++) {
|
|
24
|
+
var pStruct = model.drawCallbacks[i];
|
|
25
|
+
var pl = pStruct.pipeline;
|
|
26
|
+
publicAPI.setPipeline(pl);
|
|
27
|
+
|
|
28
|
+
for (var cb = 0; cb < pStruct.callbacks.length; cb++) {
|
|
29
|
+
pStruct.callbacks[cb](publicAPI);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
21
33
|
if (model.label) {
|
|
22
34
|
model.handle.popDebugGroup();
|
|
23
35
|
}
|
|
24
36
|
|
|
25
37
|
model.handle.end();
|
|
38
|
+
model.boundPipeline = null;
|
|
26
39
|
};
|
|
27
40
|
|
|
28
41
|
publicAPI.setPipeline = function (pl) {
|
|
42
|
+
if (model.boundPipeline === pl) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
29
46
|
model.handle.setPipeline(pl.getHandle());
|
|
30
47
|
var pd = pl.getPipelineDescription(); // check attachment state
|
|
31
48
|
|
|
@@ -57,6 +74,7 @@ function vtkWebGPURenderEncoder(publicAPI, model) {
|
|
|
57
74
|
}
|
|
58
75
|
|
|
59
76
|
model.boundPipeline = pl;
|
|
77
|
+
pl.draw(publicAPI);
|
|
60
78
|
};
|
|
61
79
|
|
|
62
80
|
publicAPI.replaceShaderCode = function (pipeline) {
|
|
@@ -100,6 +118,22 @@ function vtkWebGPURenderEncoder(publicAPI, model) {
|
|
|
100
118
|
if (model.depthTextureView) {
|
|
101
119
|
model.description.depthStencilAttachment.view = model.depthTextureView.getHandle();
|
|
102
120
|
}
|
|
121
|
+
}; // register pipeline callbacks from a mapper
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
publicAPI.registerDrawCallback = function (pipeline, cb) {
|
|
125
|
+
// if there is a matching pipeline just add the cb
|
|
126
|
+
for (var i = 0; i < model.drawCallbacks.length; i++) {
|
|
127
|
+
if (model.drawCallbacks[i].pipeline === pipeline) {
|
|
128
|
+
model.drawCallbacks[i].callbacks.push(cb);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
model.drawCallbacks.push({
|
|
134
|
+
pipeline: pipeline,
|
|
135
|
+
callbacks: [cb]
|
|
136
|
+
});
|
|
103
137
|
}; // simple forwarders
|
|
104
138
|
|
|
105
139
|
|
|
@@ -93,22 +93,6 @@ function vtkWebGPURenderer(publicAPI, model) {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
return count;
|
|
96
|
-
}; // register pipeline callbacks from a mapper
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
publicAPI.registerPipelineCallback = function (pipeline, cb) {
|
|
100
|
-
// if there is a matching pipeline just add the cb
|
|
101
|
-
for (var i = 0; i < model.pipelineCallbacks.length; i++) {
|
|
102
|
-
if (model.pipelineCallbacks[i].pipeline === pipeline) {
|
|
103
|
-
model.pipelineCallbacks[i].callbacks.push(cb);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
model.pipelineCallbacks.push({
|
|
109
|
-
pipeline: pipeline,
|
|
110
|
-
callbacks: [cb]
|
|
111
|
-
});
|
|
112
96
|
};
|
|
113
97
|
|
|
114
98
|
publicAPI.updateUBO = function () {
|
|
@@ -148,25 +132,11 @@ function vtkWebGPURenderer(publicAPI, model) {
|
|
|
148
132
|
|
|
149
133
|
publicAPI.opaquePass = function (prepass) {
|
|
150
134
|
if (prepass) {
|
|
151
|
-
// clear last pipelines
|
|
152
|
-
model.pipelineCallbacks = [];
|
|
153
135
|
model.renderEncoder.begin(model._parent.getCommandEncoder());
|
|
154
136
|
publicAPI.updateUBO();
|
|
155
137
|
} else {
|
|
156
138
|
publicAPI.scissorAndViewport(model.renderEncoder);
|
|
157
|
-
publicAPI.clear();
|
|
158
|
-
|
|
159
|
-
for (var i = 0; i < model.pipelineCallbacks.length; i++) {
|
|
160
|
-
var pStruct = model.pipelineCallbacks[i];
|
|
161
|
-
var pl = pStruct.pipeline;
|
|
162
|
-
model.renderEncoder.setPipeline(pl);
|
|
163
|
-
publicAPI.bindUBO(model.renderEncoder);
|
|
164
|
-
|
|
165
|
-
for (var cb = 0; cb < pStruct.callbacks.length; cb++) {
|
|
166
|
-
pStruct.callbacks[cb](model.renderEncoder);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
139
|
+
publicAPI.clear();
|
|
170
140
|
model.renderEncoder.end();
|
|
171
141
|
}
|
|
172
142
|
};
|
|
@@ -193,51 +163,23 @@ function vtkWebGPURenderer(publicAPI, model) {
|
|
|
193
163
|
var background = model.renderable.getBackgroundByReference();
|
|
194
164
|
model.clearFSQ.getUBO().setArray('BackgroundColor', background);
|
|
195
165
|
model.clearFSQ.getUBO().sendIfNeeded(device);
|
|
196
|
-
model.clearFSQ.
|
|
166
|
+
model.clearFSQ.prepareAndDraw(model.renderEncoder);
|
|
197
167
|
};
|
|
198
168
|
|
|
199
169
|
publicAPI.translucentPass = function (prepass) {
|
|
200
170
|
if (prepass) {
|
|
201
|
-
// clear last pipelines
|
|
202
|
-
model.pipelineCallbacks = [];
|
|
203
171
|
model.renderEncoder.begin(model._parent.getCommandEncoder());
|
|
204
172
|
} else {
|
|
205
|
-
publicAPI.scissorAndViewport(model.renderEncoder);
|
|
206
|
-
|
|
207
|
-
for (var i = 0; i < model.pipelineCallbacks.length; i++) {
|
|
208
|
-
var pStruct = model.pipelineCallbacks[i];
|
|
209
|
-
var pl = pStruct.pipeline;
|
|
210
|
-
model.renderEncoder.setPipeline(pl);
|
|
211
|
-
publicAPI.bindUBO(model.renderEncoder);
|
|
212
|
-
|
|
213
|
-
for (var cb = 0; cb < pStruct.callbacks.length; cb++) {
|
|
214
|
-
pStruct.callbacks[cb](model.renderEncoder);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
173
|
+
publicAPI.scissorAndViewport(model.renderEncoder);
|
|
218
174
|
model.renderEncoder.end();
|
|
219
175
|
}
|
|
220
176
|
};
|
|
221
177
|
|
|
222
178
|
publicAPI.volumeDepthRangePass = function (prepass) {
|
|
223
179
|
if (prepass) {
|
|
224
|
-
// clear last pipelines
|
|
225
|
-
model.pipelineCallbacks = [];
|
|
226
180
|
model.renderEncoder.begin(model._parent.getCommandEncoder());
|
|
227
181
|
} else {
|
|
228
|
-
publicAPI.scissorAndViewport(model.renderEncoder);
|
|
229
|
-
|
|
230
|
-
for (var i = 0; i < model.pipelineCallbacks.length; i++) {
|
|
231
|
-
var pStruct = model.pipelineCallbacks[i];
|
|
232
|
-
var pl = pStruct.pipeline;
|
|
233
|
-
model.renderEncoder.setPipeline(pl);
|
|
234
|
-
publicAPI.bindUBO(model.renderEncoder);
|
|
235
|
-
|
|
236
|
-
for (var cb = 0; cb < pStruct.callbacks.length; cb++) {
|
|
237
|
-
pStruct.callbacks[cb](model.renderEncoder);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
182
|
+
publicAPI.scissorAndViewport(model.renderEncoder);
|
|
241
183
|
model.renderEncoder.end();
|
|
242
184
|
}
|
|
243
185
|
};
|
|
@@ -51,15 +51,15 @@ function vtkWebGPUShaderDescription(publicAPI, model) {
|
|
|
51
51
|
|
|
52
52
|
for (var i = 0; i < inputNames.length; i++) {
|
|
53
53
|
if (inputInterpolations[i] !== undefined) {
|
|
54
|
-
inputStruct.push(" @location(".concat(i, ") @interpolate(").concat(inputInterpolations[i], ") ").concat(inputNames[i], " : ").concat(inputTypes[i], "
|
|
54
|
+
inputStruct.push(" @location(".concat(i, ") @interpolate(").concat(inputInterpolations[i], ") ").concat(inputNames[i], " : ").concat(inputTypes[i], ","));
|
|
55
55
|
} else {
|
|
56
|
-
inputStruct.push(" @location(".concat(i, ") ").concat(inputNames[i], " : ").concat(inputTypes[i], "
|
|
56
|
+
inputStruct.push(" @location(".concat(i, ") ").concat(inputNames[i], " : ").concat(inputTypes[i], ","));
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
for (var _i = 0; _i < model.builtinInputNames.length; _i++) {
|
|
62
|
-
inputStruct.push(" ".concat(model.builtinInputNames[_i], " : ").concat(model.builtinInputTypes[_i], "
|
|
62
|
+
inputStruct.push(" ".concat(model.builtinInputNames[_i], " : ").concat(model.builtinInputTypes[_i], ","));
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
if (inputStruct.length > 1) {
|
|
@@ -79,14 +79,14 @@ function vtkWebGPUShaderDescription(publicAPI, model) {
|
|
|
79
79
|
|
|
80
80
|
for (var _i2 = 0; _i2 < model.outputNames.length; _i2++) {
|
|
81
81
|
if (model.outputInterpolations[_i2] !== undefined) {
|
|
82
|
-
outputStruct.push(" @location(".concat(_i2, ") @interpolate(").concat(model.outputInterpolations[_i2], ") ").concat(model.outputNames[_i2], " : ").concat(model.outputTypes[_i2], "
|
|
82
|
+
outputStruct.push(" @location(".concat(_i2, ") @interpolate(").concat(model.outputInterpolations[_i2], ") ").concat(model.outputNames[_i2], " : ").concat(model.outputTypes[_i2], ","));
|
|
83
83
|
} else {
|
|
84
|
-
outputStruct.push(" @location(".concat(_i2, ") ").concat(model.outputNames[_i2], " : ").concat(model.outputTypes[_i2], "
|
|
84
|
+
outputStruct.push(" @location(".concat(_i2, ") ").concat(model.outputNames[_i2], " : ").concat(model.outputTypes[_i2], ","));
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
for (var _i3 = 0; _i3 < model.builtinOutputNames.length; _i3++) {
|
|
89
|
-
outputStruct.push(" ".concat(model.builtinOutputNames[_i3], " : ").concat(model.builtinOutputTypes[_i3], "
|
|
89
|
+
outputStruct.push(" ".concat(model.builtinOutputNames[_i3], " : ").concat(model.builtinOutputTypes[_i3], ","));
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
outputStruct.push('};');
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
2
2
|
import macro from '../../macros.js';
|
|
3
|
+
import vtkViewNode from '../SceneGraph/ViewNode.js';
|
|
3
4
|
import vtkWebGPUBindGroup from './BindGroup.js';
|
|
4
5
|
import vtkWebGPUPipeline from './Pipeline.js';
|
|
5
6
|
import vtkWebGPUShaderCache from './ShaderCache.js';
|
|
6
7
|
import vtkWebGPUShaderDescription from './ShaderDescription.js';
|
|
7
8
|
import vtkWebGPUVertexInput from './VertexInput.js';
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
//
|
|
10
|
+
var vtkWebGPUSimpleMapperVS = "\n//VTK::Renderer::Dec\n\n//VTK::Color::Dec\n\n//VTK::Normal::Dec\n\n//VTK::TCoord::Dec\n\n//VTK::Select::Dec\n\n//VTK::Mapper::Dec\n\n//VTK::IOStructs::Dec\n\n@stage(vertex)\nfn main(\n//VTK::IOStructs::Input\n)\n//VTK::IOStructs::Output\n{\n var output : vertexOutput;\n\n // var vertex: vec4<f32> = vertexBC;\n\n //VTK::Color::Impl\n\n //VTK::Normal::Impl\n\n //VTK::TCoord::Impl\n\n //VTK::Select::Impl\n\n //VTK::Position::Impl\n\n return output;\n}\n";
|
|
11
|
+
var vtkWebGPUSimpleMapperFS = "\n//VTK::Renderer::Dec\n\n//VTK::Color::Dec\n\n//VTK::Normal::Dec\n\n//VTK::TCoord::Dec\n\n//VTK::Select::Dec\n\n//VTK::RenderEncoder::Dec\n\n//VTK::Mapper::Dec\n\n//VTK::IOStructs::Dec\n\n@stage(fragment)\nfn main(\n//VTK::IOStructs::Input\n)\n//VTK::IOStructs::Output\n{\n var output : fragmentOutput;\n\n //VTK::Color::Impl\n\n //VTK::Normal::Impl\n\n //VTK::Light::Impl\n\n //VTK::TCoord::Impl\n\n //VTK::Select::Impl\n\n // var computedColor:vec4<f32> = vec4<f32>(1.0,0.5,0.5,1.0);\n\n //VTK::RenderEncoder::Impl\n return output;\n}\n"; // ----------------------------------------------------------------------------
|
|
12
|
+
// vtkWebGPUSimpleMapper methods
|
|
12
13
|
// ----------------------------------------------------------------------------
|
|
13
14
|
|
|
14
|
-
function
|
|
15
|
+
function vtkWebGPUSimpleMapper(publicAPI, model) {
|
|
15
16
|
// Set our className
|
|
16
|
-
model.classHierarchy.push('
|
|
17
|
+
model.classHierarchy.push('vtkWebGPUSimpleMapper');
|
|
17
18
|
|
|
18
19
|
publicAPI.generateShaderDescriptions = function (hash, pipeline, vertexInput) {
|
|
19
20
|
// create the shader descriptions
|
|
@@ -126,32 +127,59 @@ function vtkWebGPUMapperHelper(publicAPI, model) {
|
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
model.textureViews.push(view);
|
|
130
|
+
}; // do everything required for this mapper to be rerady to draw
|
|
131
|
+
// but do not bind or do the actual draw commands as the pipeline
|
|
132
|
+
// is not neccessarily bound yet
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
publicAPI.prepareToDraw = function (renderEncoder) {
|
|
136
|
+
model.renderEncoder = renderEncoder; // do anything needed to get our input data up to date
|
|
137
|
+
|
|
138
|
+
publicAPI.updateInput(); // make sure buffers are created and up to date
|
|
139
|
+
|
|
140
|
+
publicAPI.updateBuffers(); // update bindings and bind groups/layouts
|
|
141
|
+
// does not acutally bind them, that is done in draw(...)
|
|
142
|
+
|
|
143
|
+
publicAPI.updateBindings(); // update the pipeline, includes computing the hash, and if needed
|
|
144
|
+
// creating the pipeline, shader code etc
|
|
145
|
+
|
|
146
|
+
publicAPI.updatePipeline();
|
|
129
147
|
};
|
|
130
148
|
|
|
131
|
-
publicAPI.
|
|
132
|
-
var pipeline = renderEncoder.getBoundPipeline(); // bind the mapper bind group
|
|
149
|
+
publicAPI.updateInput = function () {};
|
|
133
150
|
|
|
134
|
-
|
|
151
|
+
publicAPI.updateBuffers = function () {};
|
|
135
152
|
|
|
136
|
-
|
|
137
|
-
|
|
153
|
+
publicAPI.updateBindings = function () {
|
|
154
|
+
// bindings can change without a pipeline change
|
|
155
|
+
// as long as their layout remains the same.
|
|
156
|
+
// That is why this is done even when the pipeline
|
|
157
|
+
// hash doesn't change.
|
|
158
|
+
model.bindGroup.setBindables(publicAPI.getBindables());
|
|
138
159
|
};
|
|
139
160
|
|
|
140
|
-
publicAPI.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
161
|
+
publicAPI.computePipelineHash = function () {};
|
|
162
|
+
|
|
163
|
+
publicAPI.registerDrawCallback = function (encoder) {
|
|
164
|
+
encoder.registerDrawCallback(model.pipeline, publicAPI.draw);
|
|
144
165
|
};
|
|
145
166
|
|
|
146
|
-
publicAPI.
|
|
147
|
-
publicAPI.
|
|
148
|
-
|
|
167
|
+
publicAPI.prepareAndDraw = function (encoder) {
|
|
168
|
+
publicAPI.prepareToDraw(encoder);
|
|
169
|
+
encoder.setPipeline(model.pipeline);
|
|
170
|
+
publicAPI.draw(encoder);
|
|
171
|
+
}; // do the rest of the calls required to draw this mapper
|
|
172
|
+
// at this point the command encouder and pipeline are
|
|
173
|
+
// created and bound
|
|
149
174
|
|
|
150
|
-
if (model.WebGPURenderer) {
|
|
151
|
-
model.WebGPURenderer.bindUBO(renderEncoder);
|
|
152
|
-
}
|
|
153
175
|
|
|
154
|
-
|
|
176
|
+
publicAPI.draw = function (renderEncoder) {
|
|
177
|
+
var pipeline = renderEncoder.getBoundPipeline(); // bind the mapper bind group
|
|
178
|
+
|
|
179
|
+
renderEncoder.activateBindGroup(model.bindGroup); // bind the vertex input
|
|
180
|
+
|
|
181
|
+
pipeline.bindVertexInput(renderEncoder, model.vertexInput);
|
|
182
|
+
renderEncoder.draw(model.numberOfVertices, model.numberOfInstances, 0, 0);
|
|
155
183
|
};
|
|
156
184
|
|
|
157
185
|
publicAPI.getBindables = function () {
|
|
@@ -178,27 +206,25 @@ function vtkWebGPUMapperHelper(publicAPI, model) {
|
|
|
178
206
|
return bindables;
|
|
179
207
|
};
|
|
180
208
|
|
|
181
|
-
publicAPI.
|
|
182
|
-
|
|
183
|
-
model.
|
|
184
|
-
model.pipeline = device.getPipeline(model.pipelineHash);
|
|
185
|
-
model.bindGroup.setBindables(publicAPI.getBindables()); // build VBO for this primitive
|
|
186
|
-
// build the pipeline if needed
|
|
209
|
+
publicAPI.updatePipeline = function () {
|
|
210
|
+
publicAPI.computePipelineHash();
|
|
211
|
+
model.pipeline = model.device.getPipeline(model.pipelineHash); // build the pipeline if needed
|
|
187
212
|
|
|
188
213
|
if (!model.pipeline) {
|
|
189
214
|
model.pipeline = vtkWebGPUPipeline.newInstance();
|
|
190
|
-
model.pipeline.setDevice(device);
|
|
215
|
+
model.pipeline.setDevice(model.device);
|
|
191
216
|
|
|
192
217
|
if (model.WebGPURenderer) {
|
|
193
218
|
model.pipeline.addBindGroupLayout(model.WebGPURenderer.getBindGroup());
|
|
219
|
+
model.pipeline.addDrawCallback(model.WebGPURenderer.bindUBO);
|
|
194
220
|
}
|
|
195
221
|
|
|
196
222
|
model.pipeline.addBindGroupLayout(model.bindGroup);
|
|
197
223
|
publicAPI.generateShaderDescriptions(model.pipelineHash, model.pipeline, model.vertexInput);
|
|
198
224
|
model.pipeline.setTopology(model.topology);
|
|
199
|
-
model.pipeline.setRenderEncoder(renderEncoder);
|
|
225
|
+
model.pipeline.setRenderEncoder(model.renderEncoder);
|
|
200
226
|
model.pipeline.setVertexState(model.vertexInput.getVertexInputInformation());
|
|
201
|
-
device.createPipeline(model.pipelineHash, model.pipeline);
|
|
227
|
+
model.device.createPipeline(model.pipelineHash, model.pipeline);
|
|
202
228
|
}
|
|
203
229
|
};
|
|
204
230
|
} // ----------------------------------------------------------------------------
|
|
@@ -227,28 +253,28 @@ function extend(publicAPI, model) {
|
|
|
227
253
|
var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
228
254
|
Object.assign(model, DEFAULT_VALUES, initialValues); // Inheritance
|
|
229
255
|
|
|
230
|
-
|
|
256
|
+
vtkViewNode.extend(publicAPI, model, initialValues);
|
|
231
257
|
model.textureViews = [];
|
|
232
258
|
model.vertexInput = vtkWebGPUVertexInput.newInstance();
|
|
233
259
|
model.bindGroup = vtkWebGPUBindGroup.newInstance({
|
|
234
260
|
label: 'mapperBG'
|
|
235
261
|
});
|
|
236
262
|
model.additionalBindables = [];
|
|
237
|
-
model.fragmentShaderTemplate = model.fragmentShaderTemplate ||
|
|
238
|
-
model.vertexShaderTemplate = model.vertexShaderTemplate ||
|
|
263
|
+
model.fragmentShaderTemplate = model.fragmentShaderTemplate || vtkWebGPUSimpleMapperFS;
|
|
264
|
+
model.vertexShaderTemplate = model.vertexShaderTemplate || vtkWebGPUSimpleMapperVS;
|
|
239
265
|
model.shaderReplacements = new Map(); // Build VTK API
|
|
240
266
|
|
|
241
|
-
macro.get(publicAPI, model, ['vertexInput']);
|
|
267
|
+
macro.get(publicAPI, model, ['pipeline', 'vertexInput']);
|
|
242
268
|
macro.setGet(publicAPI, model, ['additionalBindables', 'device', 'fragmentShaderTemplate', 'interpolate', 'numberOfInstances', 'numberOfVertices', 'pipelineHash', 'shaderReplacements', 'SSBO', 'textureViews', 'topology', 'UBO', 'vertexShaderTemplate', 'WebGPURenderer']); // Object methods
|
|
243
269
|
|
|
244
|
-
|
|
270
|
+
vtkWebGPUSimpleMapper(publicAPI, model);
|
|
245
271
|
} // ----------------------------------------------------------------------------
|
|
246
272
|
|
|
247
|
-
var newInstance = macro.newInstance(extend, '
|
|
273
|
+
var newInstance = macro.newInstance(extend, 'vtkWebGPUSimpleMapper'); // ----------------------------------------------------------------------------
|
|
248
274
|
|
|
249
|
-
var
|
|
275
|
+
var vtkWebGPUSimpleMapper$1 = {
|
|
250
276
|
newInstance: newInstance,
|
|
251
277
|
extend: extend
|
|
252
278
|
};
|
|
253
279
|
|
|
254
|
-
export {
|
|
280
|
+
export { vtkWebGPUSimpleMapper$1 as default, extend, newInstance };
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { newInstance as newInstance$1, vtkErrorMacro as vtkErrorMacro$1 } from '../../macros.js';
|
|
2
2
|
import { r as radiansFromDegrees } from '../../Common/Core/Math/index.js';
|
|
3
|
-
import
|
|
3
|
+
import vtkWebGPUCellArrayMapper from './CellArrayMapper.js';
|
|
4
4
|
import vtkWebGPUBufferManager from './BufferManager.js';
|
|
5
5
|
import vtkWebGPUShaderCache from './ShaderCache.js';
|
|
6
6
|
import { registerOverride } from './ViewNodeFactory.js';
|
|
7
7
|
|
|
8
|
-
var BufferUsage = vtkWebGPUBufferManager.BufferUsage
|
|
9
|
-
PrimitiveTypes = vtkWebGPUBufferManager.PrimitiveTypes;
|
|
8
|
+
var BufferUsage = vtkWebGPUBufferManager.BufferUsage;
|
|
10
9
|
var vtkErrorMacro = vtkErrorMacro$1;
|
|
11
10
|
var vtkWebGPUSphereMapperVS = "\n//VTK::Renderer::Dec\n\n//VTK::Mapper::Dec\n\n//VTK::Color::Dec\n\n//VTK::IOStructs::Dec\n\n@stage(vertex)\nfn main(\n//VTK::IOStructs::Input\n)\n//VTK::IOStructs::Output\n{\n var output : vertexOutput;\n\n var vertexVC: vec4<f32> = rendererUBO.SCVCMatrix * mapperUBO.BCSCMatrix * vec4<f32>(vertexBC.x, vertexBC.y, vertexBC.z, 1.0);\n\n //VTK::Color::Impl\n\n // compute the projected vertex position\n output.centerVC = vertexVC.xyz;\n output.radiusVC = length(offsetMC)*0.5;\n\n // make the triangle face the camera\n if (rendererUBO.cameraParallel == 0u)\n {\n var dir: vec3<f32> = normalize(-vertexVC.xyz);\n var base2: vec3<f32> = normalize(cross(dir,vec3<f32>(1.0,0.0,0.0)));\n var base1: vec3<f32> = cross(base2,dir);\n dir = vertexVC.xyz + offsetMC.x*base1 + offsetMC.y*base2;\n vertexVC = vec4<f32>(dir, 1.0);\n }\n else\n {\n // add in the offset\n var tmp2: vec2<f32> = vertexVC.xy + offsetMC;\n vertexVC = vec4<f32>(tmp2, vertexVC.zw);\n }\n\n output.vertexVC = vertexVC.xyz;\n\n //VTK::Position::Impl\n\n return output;\n}\n"; // ----------------------------------------------------------------------------
|
|
12
11
|
// vtkWebGPUSphereMapper methods
|
|
@@ -15,6 +14,21 @@ var vtkWebGPUSphereMapperVS = "\n//VTK::Renderer::Dec\n\n//VTK::Mapper::Dec\n\n/
|
|
|
15
14
|
function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
16
15
|
// Set our className
|
|
17
16
|
model.classHierarchy.push('vtkWebGPUSphereMapper');
|
|
17
|
+
var cellMapperBuildPass = publicAPI.buildPass;
|
|
18
|
+
|
|
19
|
+
publicAPI.buildPass = function (prepass) {
|
|
20
|
+
if (prepass) {
|
|
21
|
+
if (!model.renderable.getStatic()) {
|
|
22
|
+
model.renderable.update();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var poly = model.renderable.getInputData();
|
|
26
|
+
publicAPI.setCellArray(poly.getVerts());
|
|
27
|
+
publicAPI.setCurrentInput(poly);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
cellMapperBuildPass(prepass);
|
|
31
|
+
};
|
|
18
32
|
|
|
19
33
|
publicAPI.replaceShaderNormal = function (hash, pipeline, vertexInput) {
|
|
20
34
|
var vDesc = pipeline.getShaderDescription('vertex');
|
|
@@ -40,42 +54,35 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
40
54
|
// or vertex input changes/ bind groups/ etc
|
|
41
55
|
|
|
42
56
|
|
|
43
|
-
publicAPI.computePipelineHash = function (
|
|
44
|
-
|
|
57
|
+
publicAPI.computePipelineHash = function () {
|
|
58
|
+
model.pipelineHash = 'spm';
|
|
45
59
|
|
|
46
|
-
if (vertexInput.hasAttribute("colorVI")) {
|
|
47
|
-
pipelineHash += "c";
|
|
60
|
+
if (model.vertexInput.hasAttribute("colorVI")) {
|
|
61
|
+
model.pipelineHash += "c";
|
|
48
62
|
}
|
|
49
63
|
|
|
50
|
-
pipelineHash += model.renderEncoder.getPipelineHash();
|
|
51
|
-
|
|
52
|
-
}; // was originally buildIBOs() but not using IBOs right now
|
|
53
|
-
|
|
64
|
+
model.pipelineHash += model.renderEncoder.getPipelineHash();
|
|
65
|
+
};
|
|
54
66
|
|
|
55
|
-
publicAPI.
|
|
67
|
+
publicAPI.updateBuffers = function () {
|
|
56
68
|
var poly = model.currentInput;
|
|
57
|
-
|
|
58
|
-
model.renderable.mapScalars(poly, 1.0); // handle triangles
|
|
59
|
-
|
|
60
|
-
var i = PrimitiveTypes.Triangles;
|
|
69
|
+
model.renderable.mapScalars(poly, 1.0);
|
|
61
70
|
var points = poly.getPoints();
|
|
62
71
|
var numPoints = points.getNumberOfPoints();
|
|
63
|
-
var pointArray = points.getData();
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (!device.getBufferManager().hasBuffer(buffRequest)) {
|
|
78
|
-
// xyz v1 v2 v3
|
|
72
|
+
var pointArray = points.getData(); // default to one instance and computed number of verts
|
|
73
|
+
|
|
74
|
+
publicAPI.setNumberOfInstances(1);
|
|
75
|
+
publicAPI.setNumberOfVertices(3 * numPoints);
|
|
76
|
+
var vertexInput = model.vertexInput;
|
|
77
|
+
var hash = "spm".concat(points.getMTime(), "float32x3");
|
|
78
|
+
|
|
79
|
+
if (!model.device.getBufferManager().hasBuffer(hash)) {
|
|
80
|
+
var buffRequest = {
|
|
81
|
+
hash: hash,
|
|
82
|
+
usage: BufferUsage.RawVertex,
|
|
83
|
+
format: 'float32x3'
|
|
84
|
+
}; // xyz v1 v2 v3
|
|
85
|
+
|
|
79
86
|
var tmpVBO = new Float32Array(3 * numPoints * 3);
|
|
80
87
|
var pointIdx = 0;
|
|
81
88
|
var vboIdx = 0;
|
|
@@ -94,7 +101,7 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
buffRequest.nativeArray = tmpVBO;
|
|
97
|
-
var buff = device.getBufferManager().getBuffer(buffRequest);
|
|
104
|
+
var buff = model.device.getBufferManager().getBuffer(buffRequest);
|
|
98
105
|
vertexInput.addBuffer(buff, ['vertexBC']);
|
|
99
106
|
} // compute offset VBO
|
|
100
107
|
|
|
@@ -109,15 +116,15 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
109
116
|
var defaultRadius = model.renderable.getRadius();
|
|
110
117
|
|
|
111
118
|
if (scales || defaultRadius !== model._lastRadius) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
hash = "spm".concat(scales ? pointData.getArray(model.renderable.getScaleArray()).getMTime() : defaultRadius, "float32x2");
|
|
120
|
+
|
|
121
|
+
if (!model.device.getBufferManager().hasBuffer(hash)) {
|
|
122
|
+
var _buffRequest = {
|
|
123
|
+
hash: hash,
|
|
124
|
+
usage: BufferUsage.RawVertex,
|
|
125
|
+
format: 'float32x2'
|
|
126
|
+
};
|
|
119
127
|
|
|
120
|
-
if (!device.getBufferManager().hasBuffer(buffRequest)) {
|
|
121
128
|
var _tmpVBO = new Float32Array(3 * numPoints * 2);
|
|
122
129
|
|
|
123
130
|
var cos30 = Math.cos(radiansFromDegrees(30.0));
|
|
@@ -138,17 +145,16 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
138
145
|
_tmpVBO[_vboIdx++] = 2.0 * radius;
|
|
139
146
|
}
|
|
140
147
|
|
|
141
|
-
|
|
148
|
+
_buffRequest.nativeArray = _tmpVBO;
|
|
142
149
|
|
|
143
|
-
var _buff = device.getBufferManager().getBuffer(
|
|
150
|
+
var _buff = model.device.getBufferManager().getBuffer(_buffRequest);
|
|
144
151
|
|
|
145
152
|
vertexInput.addBuffer(_buff, ['offsetMC']);
|
|
146
153
|
}
|
|
147
154
|
|
|
148
155
|
model._lastRadius = defaultRadius;
|
|
149
|
-
}
|
|
156
|
+
} // deal with colors but only if modified
|
|
150
157
|
|
|
151
|
-
model.renderable.mapScalars(poly, 1.0); // deal with colors but only if modified
|
|
152
158
|
|
|
153
159
|
var haveColors = false;
|
|
154
160
|
|
|
@@ -156,15 +162,14 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
156
162
|
var c = model.renderable.getColorMapColors();
|
|
157
163
|
|
|
158
164
|
if (c) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (!device.getBufferManager().hasBuffer(buffRequest)) {
|
|
165
|
+
hash = "spm".concat(c.getMTime(), "unorm8x4");
|
|
166
|
+
|
|
167
|
+
if (!model.device.getBufferManager().hasBuffer(hash)) {
|
|
168
|
+
var _buffRequest2 = {
|
|
169
|
+
hash: hash,
|
|
170
|
+
usage: BufferUsage.RawVertex,
|
|
171
|
+
format: 'unorm8x4'
|
|
172
|
+
};
|
|
168
173
|
var colorComponents = c.getNumberOfComponents();
|
|
169
174
|
|
|
170
175
|
if (colorComponents !== 4) {
|
|
@@ -187,9 +192,9 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
187
192
|
}
|
|
188
193
|
}
|
|
189
194
|
|
|
190
|
-
|
|
195
|
+
_buffRequest2.nativeArray = _tmpVBO2;
|
|
191
196
|
|
|
192
|
-
var _buff2 = device.getBufferManager().getBuffer(
|
|
197
|
+
var _buff2 = model.device.getBufferManager().getBuffer(_buffRequest2);
|
|
193
198
|
|
|
194
199
|
vertexInput.addBuffer(_buff2, ['colorVI']);
|
|
195
200
|
}
|
|
@@ -202,11 +207,8 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
202
207
|
vertexInput.removeBufferIfPresent('colorVI');
|
|
203
208
|
}
|
|
204
209
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
primHelper.setTopology('triangle-list');
|
|
208
|
-
primHelper.build(model.renderEncoder, device);
|
|
209
|
-
primHelper.registerToDraw();
|
|
210
|
+
publicAPI.setTopology('triangle-list');
|
|
211
|
+
publicAPI.updateUBO();
|
|
210
212
|
};
|
|
211
213
|
} // ----------------------------------------------------------------------------
|
|
212
214
|
// Object factory
|
|
@@ -219,11 +221,11 @@ function extend(publicAPI, model) {
|
|
|
219
221
|
var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
220
222
|
Object.assign(model, DEFAULT_VALUES, initialValues); // Inheritance
|
|
221
223
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
+
vtkWebGPUCellArrayMapper.extend(publicAPI, model, initialValues);
|
|
225
|
+
publicAPI.setVertexShaderTemplate(vtkWebGPUSphereMapperVS); // Object methods
|
|
224
226
|
|
|
225
227
|
vtkWebGPUSphereMapper(publicAPI, model);
|
|
226
|
-
var sr = model.
|
|
228
|
+
var sr = model.shaderReplacements;
|
|
227
229
|
sr.set('replaceShaderPosition', publicAPI.replaceShaderPosition);
|
|
228
230
|
sr.set('replaceShaderNormal', publicAPI.replaceShaderNormal);
|
|
229
231
|
} // ----------------------------------------------------------------------------
|