import macro from 'vtk.js/Sources/macros'; import vtkWebGPURenderEncoder from 'vtk.js/Sources/Rendering/WebGPU/RenderEncoder'; import vtkWebGPUTexture from 'vtk.js/Sources/Rendering/WebGPU/Texture'; import vtkWebGPUShaderCache from 'vtk.js/Sources/Rendering/WebGPU/ShaderCache'; import vtkRenderPass from 'vtk.js/Sources/Rendering/SceneGraph/RenderPass';
function vtkWebGPUHardwareSelectionPass(publicAPI, model) { model.classHierarchy.push('vtkWebGPUHardwareSelectionPass');
publicAPI.traverse = (viewNode, renNode) => { if (model.deleted) { return; }
model._currentParent = null;
publicAPI.setCurrentOperation('buildPass'); viewNode.traverse(publicAPI);
const device = viewNode.getDevice();
if (!model.selectionRenderEncoder) { publicAPI.createRenderEncoder();
model.colorTexture = vtkWebGPUTexture.newInstance({ label: 'hardwareSelectorColor', }); model.colorTexture.create(device, { width: viewNode.getCanvas().width, height: viewNode.getCanvas().height, format: 'rgba32uint', usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC, }); const v1 = model.colorTexture.createView('hardwareSelectColorTexture'); model.selectionRenderEncoder.setColorTextureView(0, v1);
model.depthTexture = vtkWebGPUTexture.newInstance({ label: 'hardwareSelectorDepth', }); model.depthTexture.create(device, { width: viewNode.getCanvas().width, height: viewNode.getCanvas().height, format: 'depth32float', usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC, }); const v2 = model.depthTexture.createView('hardwareSelectDepthTexture'); model.selectionRenderEncoder.setDepthTextureView(v2); } else { model.colorTexture.resize( viewNode.getCanvas().width, viewNode.getCanvas().height ); model.depthTexture.resizeToMatch(model.colorTexture); }
model.selectionRenderEncoder.attachTextureViews(); renNode.setRenderEncoder(model.selectionRenderEncoder);
publicAPI.setCurrentOperation('cameraPass'); renNode.traverse(publicAPI); publicAPI.setCurrentOperation('opaquePass'); renNode.traverse(publicAPI); };
publicAPI.createRenderEncoder = () => { model.selectionRenderEncoder = vtkWebGPURenderEncoder.newInstance({ label: 'HardwareSelectionPass', }); model.selectionRenderEncoder.setPipelineHash('sel'); model.selectionRenderEncoder.setReplaceShaderCodeFunction((pipeline) => { const fDesc = pipeline.getShaderDescription('fragment'); fDesc.addOutput('vec4<u32>', 'outColor'); let code = fDesc.getCode(); code = vtkWebGPUShaderCache.substitute( code, '//VTK::RenderEncoder::Impl', ['output.outColor = vec4<u32>(mapperUBO.PropID, compositeID, 0u, 0u);'] ).result; fDesc.setCode(code); }); const renDesc = model.selectionRenderEncoder.getDescription(); renDesc.colorAttachments[0].clearValue = [0.0, 0.0, 0.0, 0.0];
model.selectionRenderEncoder.setPipelineSettings({ primitive: { cullMode: 'none' }, depthStencil: { depthWriteEnabled: true, depthCompare: 'greater', format: 'depth32float', }, fragment: { targets: [ { format: 'rgba32uint', blend: undefined, }, ], }, }); }; }
const DEFAULT_VALUES = { selectionRenderEncoder: null, colorTexture: null, depthTexture: null, };
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
vtkRenderPass.extend(publicAPI, model, initialValues);
macro.get(publicAPI, model, ['colorTexture', 'depthTexture']);
vtkWebGPUHardwareSelectionPass(publicAPI, model); }
export const newInstance = macro.newInstance( extend, 'vtkWebGPUHardwareSelectionPass' );
export default { newInstance, extend };
|