Skip to content

Commit 4d59e2d

Browse files
committed
feat(ImageCPRMapper): add ImageCPRMapper in WebGPU
1 parent a1c8933 commit 4d59e2d

File tree

7 files changed

+913
-2
lines changed

7 files changed

+913
-2
lines changed

Sources/Rendering/Core/ImageCPRMapper/example/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import vtkPlaneManipulator from '@kitware/vtk.js/Widgets/Manipulators/PlaneManip
2424
import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
2525
import vtkRenderer from '@kitware/vtk.js/Rendering/Core/Renderer';
2626
import vtkResliceCursorWidget from '@kitware/vtk.js/Widgets/Widgets3D/ResliceCursorWidget';
27+
import vtkURLExtract from '@kitware/vtk.js/Common/Core/URLExtract';
2728
import vtkWidgetManager from '@kitware/vtk.js/Widgets/Core/WidgetManager';
2829
import widgetBehavior from '@kitware/vtk.js/Widgets/Widgets3D/ResliceCursorWidget/cprBehavior';
2930

@@ -34,16 +35,21 @@ import spineJSON from './spine_centerline.json';
3435
const volumePath = `${__BASE_PATH__}/data/volume/LIDC2.vti`;
3536
const centerlineJsons = { Aorta: aortaJSON, Spine: spineJSON };
3637
const centerlineKeys = Object.keys(centerlineJsons);
38+
const userParams = vtkURLExtract.extractURLParameters();
39+
const viewAPI = userParams.viewAPI || 'WebGL';
3740

3841
// ----------------------------------------------------------------------------
3942
// Standard rendering code setup
4043
// ----------------------------------------------------------------------------
4144

42-
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance();
45+
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({
46+
defaultViewAPI: viewAPI,
47+
});
4348
const stretchRenderer = fullScreenRenderer.getRenderer();
4449
const renderWindow = fullScreenRenderer.getRenderWindow();
4550
const gui = new GUI();
4651
const params = {
52+
viewAPI,
4753
Angle: 0,
4854
Animate: false,
4955
Centerline: centerlineKeys[0],
@@ -59,6 +65,15 @@ const interactor = renderWindow.getInteractor();
5965
interactor.setInteractorStyle(vtkInteractorStyleImage.newInstance());
6066
interactor.setDesiredUpdateRate(15.0);
6167

68+
gui
69+
.add(params, 'viewAPI', ['WebGL', 'WebGPU'])
70+
.name('Renderer')
71+
.onChange((api) => {
72+
const query = new URLSearchParams(window.location.search);
73+
query.set('viewAPI', api);
74+
window.location.search = query.toString();
75+
});
76+
6277
// Reslice Cursor Widget
6378
const stretchPlane = 'Y';
6479
const crossPlane = 'Z';

Sources/Rendering/WebGPU/ForwardPass/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ fn main(
2525
{
2626
var output: fragmentOutput;
2727
28-
var computedColor: vec4<f32> = clamp(textureSampleLevel(opaquePassColorTexture, finalPassSampler, input.tcoordVS, 0.0),vec4<f32>(0.0),vec4<f32>(1.0));
28+
var texCoord: vec2<i32> =
29+
vec2<i32>(i32(input.fragPos.x), i32(input.fragPos.y));
30+
var computedColor: vec4<f32> = clamp(
31+
textureLoad(opaquePassColorTexture, texCoord, 0),
32+
vec4<f32>(0.0),
33+
vec4<f32>(1.0)
34+
);
2935
3036
//VTK::RenderEncoder::Impl
3137
return output;
@@ -181,6 +187,16 @@ function vtkForwardPass(publicAPI, model) {
181187
]);
182188
model._fullScreenQuad.setAdditionalBindables([model._fsqSampler]);
183189
model._fullScreenQuad.setFragmentShaderTemplate(finalBlitFragTemplate);
190+
model._fullScreenQuad
191+
.getShaderReplacements()
192+
.set('replaceShaderTCoord', (hash, pipeline) => {
193+
const vDesc = pipeline.getShaderDescription('vertex');
194+
if (!vDesc.hasOutput('tcoordVS')) {
195+
vDesc.addOutput('vec2<f32>', 'tcoordVS');
196+
}
197+
const fDesc = pipeline.getShaderDescription('fragment');
198+
fDesc.addBuiltinInput('vec4<f32>', '@builtin(position) fragPos');
199+
});
184200
model._finalBlitOutputTextureView = vtkWebGPUTextureView.newInstance();
185201
model._finalBlitEncoder.setColorTextureView(
186202
0,

Sources/Rendering/WebGPU/Glyph3DMapper/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ function vtkWebGPUGlyph3DCellArrayMapper(publicAPI, model) {
2020
publicAPI.setNumberOfInstances(model.glyphInstances);
2121
};
2222

23+
publicAPI.computePipelineHash = () => {
24+
superClass.computePipelineHash();
25+
if (model.renderable.getColorArray()) {
26+
model.pipelineHash += 'gc';
27+
}
28+
};
29+
2330
publicAPI.replaceShaderPosition = (hash, pipeline, vertexInput) => {
2431
const vDesc = pipeline.getShaderDescription('vertex');
2532
vDesc.addBuiltinInput('u32', '@builtin(instance_index) instanceIndex');

0 commit comments

Comments
 (0)