@kitware/vtk.js 25.1.3 → 25.2.2

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.
@@ -18,7 +18,7 @@ var ScalarMode = vtkMapper.ScalarMode;
18
18
  var CoordinateSystem = vtkProp.CoordinateSystem;
19
19
  var DisplayLocation = vtkProperty2D.DisplayLocation;
20
20
  var vtkWebGPUPolyDataVS = "\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@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";
21
- var vtkWebGPUPolyDataFS = "\n//VTK::Renderer::Dec\n\n//VTK::Color::Dec\n\n// optional surface normal declaration\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@fragment\nfn main(\n//VTK::IOStructs::Input\n)\n//VTK::IOStructs::Output\n{\n var output : fragmentOutput;\n\n var ambientColor: vec4<f32> = mapperUBO.AmbientColor;\n var diffuseColor: vec4<f32> = mapperUBO.DiffuseColor;\n var opacity: f32 = mapperUBO.Opacity;\n\n //VTK::Color::Impl\n\n //VTK::Normal::Impl\n\n //VTK::Light::Impl\n\n var computedColor: vec4<f32> = vec4<f32>(ambientColor.rgb * mapperUBO.AmbientIntensity\n + diffuse * mapperUBO.DiffuseIntensity\n + specular * mapperUBO.SpecularIntensity,\n opacity);\n\n //VTK::TCoord::Impl\n\n //VTK::Select::Impl\n\n if (computedColor.a == 0.0) { discard; };\n\n //VTK::Position::Impl\n\n //VTK::RenderEncoder::Impl\n return output;\n}\n";
21
+ var vtkWebGPUPolyDataFS = "\nstruct PBRData {\n diffuse: vec3<f32>,\n specular: vec3<f32>,\n}\n\n// Dot product with the max already in it\nfn mdot(a: vec3<f32>, b: vec3<f32>) -> f32 {\n return max(0.0, dot(a, b));\n}\n\n// Lambertian diffuse model\nfn lambertDiffuse(base: vec3<f32>, N: vec3<f32>, L: vec3<f32>) -> vec3<f32> {\n var pi: f32 = 3.14159265359; \n var NdotL: f32 = mdot(N, L);\n NdotL = pow(NdotL, 1.5);\n return (base/pi)*NdotL;\n}\n\n// Yasuhiro Fujii improvement on the Oren-Nayar model\n// https://mimosa-pudica.net/improved-oren-nayar.html\n// p is surface color, o is roughness\nfn fujiiOrenNayar(p: vec3<f32>, o: f32, N: vec3<f32>, L: vec3<f32>, V: vec3<f32>) -> vec3<f32> {\n var invpi: f32 = 0.31830988618; // 1/pi\n\n var o2 = o*o;\n var NdotL: f32 = mdot(N, L);\n NdotL = pow(NdotL, 1.5); // Less physically accurate, but hides the \"seams\" between lights better\n\n var NdotV: f32 = mdot(N, V);\n var LdotV: f32 = mdot(L, V);\n\n var s: f32 = LdotV - NdotL*NdotV;\n var t: f32 = mix(1, max(NdotL, NdotV), step(0, s)); // Mix with step is the equivalent of an if statement\n var A: vec3<f32> = 0.5*(o2 / (o2 + 0.33)) + 0.17*p*(o2 / (o2 + 0.13));\n A = invpi*(1 - A);\n var B: f32 = 0.45*(o2 / (o2 + 0.09));\n B = invpi*B;\n\n return p*NdotL*(A + B*(s/t));\n}\n\n// Fresnel portion of BRDF (IOR only, simplified)\nfn schlickFresnelIOR(V: vec3<f32>, N: vec3<f32>, ior: f32, k: f32) -> f32 {\n var NdotV: f32 = mdot(V, N);\n // var R0: f32 = pow((ior - 1.0) / (ior + 1.0), 2); // 1.0 is about the ior of air, and it is assumed that light will be traveling through air\n var F0: f32 = (pow((ior - 1.0), 2) + k*k) / (pow((ior + 1.0), 2) + k*k); // This takes into account the roughness, whic the other one does not\n return F0 + (1 - F0) * pow((1-NdotV), 5); \n}\n\n// Fresnel portion of BRDF (Color ior, better)\nfn schlickFresnelRGB(V: vec3<f32>, N: vec3<f32>, F0: vec3<f32>) -> vec3<f32> {\n var NdotV: f32 = mdot(V, N);\n return F0 + (1 - F0) * pow((1-NdotV), 5); \n}\n\n// Normal portion of BRDF\n// https://learnopengl.com/PBR/Theory\n// Trowbridge-Reitz GGX functions: normal, halfway, roughness^2\nfn trGGX(N: vec3<f32>, H: vec3<f32>, a: f32) -> f32 {\n var pi: f32 = 3.14159265359; \n\n var a2: f32 = a*a;\n var NdotH = mdot(N, H);\n var NdotH2 = NdotH*NdotH;\n \n var denom: f32 = NdotH2 * (a2 - 1.0) + 1.0;\n\n return a2 / max((pi*denom*denom), 0.000001);\n}\n\n// A VERY bad approximation of anisotropy. Real anisotropic calculations require tangent and bitangent\nfn anisotrophicTrGGX(N: vec3<f32>, H: vec3<f32>, O: vec3<f32>, s: f32, a: f32) -> f32 {\n var Op: vec3<f32> = (rendererUBO.WCVCNormals * vec4<f32>(normalize(O) * s, 0.)).xyz;\n\n var ggx1: f32 = trGGX(N + Op*s, H, a);\n var ggx2: f32 = trGGX(N - Op*s, H, a);\n return (0.5 * ggx1 + 0.5 * ggx2);\n}\n\n// Geometry portion of BRDF\nfn schlickGGX(N: vec3<f32>, X: vec3<f32>, k: f32) -> f32 {\n var NdotX = mdot(N, X);\n return NdotX / max(0.000001, (NdotX*(1-k) + k));\n}\n\nfn smithSurfaceRoughness(N: vec3<f32>, V: vec3<f32>, L: vec3<f32>, k: f32) -> f32 {\n var ggx1: f32 = max(0.01, schlickGGX(N, V, k)); // Prevents void zones at the cost of some accuracy\n var ggx2: f32 = schlickGGX(N, L, k);\n return ggx1*ggx2;\n}\n\n// BRDF Combination\nfn cookTorrance(D: f32, F: f32, G: f32, N: vec3<f32>, V: vec3<f32>, L: vec3<f32>) -> f32 {\n var num: f32 = D*F*G;\n var denom: f32 = 4*mdot(V, N)*mdot(L, N);\n\n return num / max(denom, 0.000001);\n}\n\n// Different lighting calculations for different light sources\nfn calcDirectionalLight(N: vec3<f32>, V: vec3<f32>, ior: f32, roughness: f32, metallic: f32, direction: vec3<f32>, color: vec3<f32>, base: vec3<f32>) -> PBRData { \n var L: vec3<f32> = normalize(direction); // Light Vector\n var H: vec3<f32> = normalize(L + V); // Halfway Vector\n\n var alpha = roughness*roughness;\n var k: f32 = alpha*alpha / 2;\n\n var D: f32 = trGGX(N, H, alpha); // Distribution\n // var F: f32 = schlickFresnelIOR(V, N, ior, k); // Fresnel\n var G: f32 = smithSurfaceRoughness(N, V, L, k); // Geometry\n\n var brdf: f32 = cookTorrance(D, 1, G, N, V, L); // Fresnel term is replaced with 1 because it is added later\n var incoming: vec3<f32> = color;\n var angle: f32 = mdot(L, N);\n angle = pow(angle, 1.5);\n\n var specular: vec3<f32> = brdf*incoming*angle;\n // Oren-Nayar gives a clay-like effect when fully rough which some people may not want, so it might be better to give a separate\n // control property for the diffuse vs specular roughness\n var diffuse: vec3<f32> = incoming*fujiiOrenNayar(base, roughness, N, L, V); \n // Stores the specular and diffuse separately to allow for finer post processing\n // Could also be done (propably more properly) with a struct\n var out = PBRData(diffuse, specular);\n \n return out; // Returns angle along with color of light so the final color can be multiplied by angle as well (creates black areas)\n}\n\n// TODO: find some way to reduce the number of arguments going in here\nfn calcPointLight(N: vec3<f32>, V: vec3<f32>, fragPos: vec3<f32>, ior: f32, roughness: f32, metallic: f32, position: vec3<f32>, color: vec3<f32>, base: vec3<f32>) -> PBRData {\n var L: vec3<f32> = normalize(position - fragPos); // Light Vector\n var H: vec3<f32> = normalize(L + V); // Halfway Vector\n var dist = distance(position, fragPos);\n\n var alpha = roughness*roughness;\n var k: f32 = alpha*alpha / 2; // could also be pow(alpha + 1.0, 2) / 8\n\n var D: f32 = trGGX(N, H, alpha); // Distribution\n // var F: f32 = schlickFresnelIOR(V, N, ior, k); // Fresnel\n var G: f32 = smithSurfaceRoughness(N, V, L, k); // Geometry\n\n var brdf: f32 = cookTorrance(D, 1, G, N, V, L); \n var incoming: vec3<f32> = color * (1. / (dist*dist));\n var angle: f32 = mdot(L, N);\n angle = pow(angle, 1.5); // Smoothing factor makes it less accurate, but reduces ugly \"seams\" bewteen light sources\n\n var specular: vec3<f32> = brdf*incoming*angle;\n var diffuse: vec3<f32> = incoming*fujiiOrenNayar(base, roughness, N, L, V);\n\n // Stores the specular and diffuse separately to allow for finer post processing\n // Could also be done (propably more properly) with a struct\n var out = PBRData(diffuse, specular);\n \n return out; // Returns angle along with color of light so the final color can be multiplied by angle as well (creates black areas)\n}\n\n// For a reason unknown to me, spheres dont seem to behave propperly with head-on spot lights\nfn calcSpotLight(N: vec3<f32>, V: vec3<f32>, fragPos: vec3<f32>, ior: f32, roughness: f32, metallic: f32, position: vec3<f32>, direction: vec3<f32>, cones: vec2<f32>, color: vec3<f32>, base: vec3<f32>) -> PBRData {\n var L: vec3<f32> = normalize(position - fragPos);\n var H: vec3<f32> = normalize(L + V); // Halfway Vector\n var dist = distance(position, fragPos);\n\n var alpha = roughness*roughness;\n var k: f32 = alpha*alpha / 2; // could also be pow(alpha + 1.0, 2) / 8\n\n var D: f32 = trGGX(N, H, alpha); // Distribution\n // var F: f32 = schlickFresnelIOR(V, N, ior, k); // Fresnel\n var G: f32 = smithSurfaceRoughness(N, V, L, k); // Geometry\n\n var brdf: f32 = cookTorrance(D, 1, G, N, V, L); \n \n // Cones.x is the inner phi and cones.y is the outer phi\n var theta: f32 = mdot(normalize(direction), L);\n var epsilon: f32 = cones.x - cones.y;\n var intensity: f32 = (theta - cones.y) / epsilon;\n intensity = clamp(intensity, 0.0, 1.0);\n intensity /= dist*dist;\n\n var incoming: vec3<f32> = color * intensity;\n\n var angle: f32 = mdot(L, N);\n angle = pow(angle, 1.5); // Smoothing factor makes it less accurate, but reduces ugly \"seams\" bewteen light sources\n\n var specular: vec3<f32> = brdf*incoming*angle;\n var diffuse: vec3<f32> = incoming*fujiiOrenNayar(base, roughness, N, L, V);\n\n // Stores the specular and diffuse separately to allow for finer post processing\n // Could also be done (propably more properly) with a struct\n var out = PBRData(diffuse, specular);\n \n return out; // Returns angle along with color of light so the final color can be multiplied by angle as well (creates black areas)\n}\n\n// Environment mapping stuff\n// Takes in a vector and converts it to an equivalent coordinate in a rectilinear texture. Should be replaced with cubemaps at some point\nfn vecToRectCoord(dir: vec3<f32>) -> vec2<f32> {\n var tau: f32 = 6.28318530718;\n var out: vec2<f32> = vec2<f32>(0.);\n\n out.x = atan2(dir.z, dir.x) / tau;\n out.x += 0.5;\n\n out.y = (dir.y * .5) + .5;\n\n return out;\n}\n\n//VTK::Renderer::Dec\n\n//VTK::Color::Dec\n\n//VTK::TCoord::Dec\n\n// optional surface normal declaration\n//VTK::Normal::Dec\n\n//VTK::Select::Dec\n\n//VTK::RenderEncoder::Dec\n\n//VTK::Mapper::Dec\n\n//VTK::IOStructs::Dec\n\n@fragment\nfn main(\n//VTK::IOStructs::Input\n)\n//VTK::IOStructs::Output\n{\n var output : fragmentOutput;\n\n // Temporary ambient, diffuse, and opacity\n var ambientColor: vec4<f32> = mapperUBO.AmbientColor;\n var diffuseColor: vec4<f32> = mapperUBO.DiffuseColor;\n var opacity: f32 = mapperUBO.Opacity;\n\n // This should be declared somewhere else\n var _diffuseMap: vec4<f32> = vec4<f32>(1);\n var _roughnessMap: vec4<f32> = vec4<f32>(1);\n var _metallicMap: vec4<f32> = vec4<f32>(1);\n var _normalMap: vec4<f32> = vec4<f32>(0, 0, 1, 0); // normal map was setting off the normal vector detection in fragment\n var _ambientOcclusionMap: vec4<f32> = vec4<f32>(0);\n var _emissionMap: vec4<f32> = vec4<f32>(0);\n\n //VTK::Color::Impl\n\n //VTK::TCoord::Impl\n\n //VTK::Normal::Impl\n\n var computedColor: vec4<f32> = vec4<f32>(diffuseColor.rgb, 1.);\n\n //VTK::Light::Impl\n\n //VTK::Select::Impl\n\n if (computedColor.a == 0.0) { discard; };\n\n //VTK::Position::Impl\n\n //VTK::RenderEncoder::Impl\n\n return output;\n}\n";
22
22
 
23
23
  function isEdges(hash) {
24
24
  // edge pipelines have "edge" in them
@@ -72,6 +72,9 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
72
72
  var utime = model.UBO.getSendTime();
73
73
 
74
74
  if (publicAPI.getMTime() > utime || ppty.getMTime() > utime || model.renderable.getMTime() > utime) {
75
+ var _ppty$getEdgeColorByR;
76
+
77
+ // Matricies
75
78
  var keyMats = model.WebGPUActor.getKeyMatrices(model.WebGPURenderer);
76
79
  model.UBO.setArray('BCWCMatrix', keyMats.bcwc);
77
80
  model.UBO.setArray('BCSCMatrix', keyMats.bcsc);
@@ -79,25 +82,42 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
79
82
 
80
83
  if (model.is2D) {
81
84
  model.UBO.setValue('ZValue', model.WebGPUActor.getRenderable().getProperty().getDisplayLocation() === DisplayLocation.FOREGROUND ? 1.0 : 0.0);
82
- var aColor = ppty.getColorByReference();
85
+
86
+ var _aColor = ppty.getColorByReference();
87
+
83
88
  model.UBO.setValue('AmbientIntensity', 1.0);
84
- model.UBO.setArray('AmbientColor', [aColor[0], aColor[1], aColor[2], 1.0]);
89
+ model.UBO.setArray('DiffuseColor', [_aColor[0], _aColor[1], _aColor[2], 1.0]);
85
90
  model.UBO.setValue('DiffuseIntensity', 0.0);
86
91
  model.UBO.setValue('SpecularIntensity', 0.0);
87
92
  } else {
88
- var _aColor = ppty.getAmbientColorByReference();
93
+ // Base Colors
94
+ var _aColor2 = ppty.getAmbientColorByReference();
89
95
 
90
96
  model.UBO.setValue('AmbientIntensity', ppty.getAmbient());
91
- model.UBO.setArray('AmbientColor', [_aColor[0], _aColor[1], _aColor[2], 1.0]);
97
+ model.UBO.setArray('AmbientColor', [_aColor2[0], _aColor2[1], _aColor2[2], 1.0]);
92
98
  model.UBO.setValue('DiffuseIntensity', ppty.getDiffuse());
93
- _aColor = ppty.getDiffuseColorByReference();
94
- model.UBO.setArray('DiffuseColor', [_aColor[0], _aColor[1], _aColor[2], 1.0]);
99
+ _aColor2 = ppty.getDiffuseColorByReference();
100
+ model.UBO.setArray('DiffuseColor', [_aColor2[0], _aColor2[1], _aColor2[2], 1.0]); // Roughness
101
+
102
+ model.UBO.setValue('Roughness', ppty.getRoughness());
103
+ model.UBO.setValue('BaseIOR', ppty.getBaseIOR()); // Metallic
104
+
105
+ model.UBO.setValue('Metallic', ppty.getMetallic()); // Normal
106
+
107
+ model.UBO.setValue('NormalStrength', ppty.getNormalStrength()); // Emission
108
+
109
+ model.UBO.setValue('Emission', ppty.getEmission()); // Specular
110
+
95
111
  model.UBO.setValue('SpecularIntensity', ppty.getSpecular());
96
- model.UBO.setValue('SpecularPower', ppty.getSpecularPower());
97
- _aColor = ppty.getSpecularColorByReference();
98
- model.UBO.setArray('SpecularColor', [_aColor[0], _aColor[1], _aColor[2], 1.0]);
99
- _aColor = ppty.getEdgeColorByReference();
100
- model.UBO.setArray('EdgeColor', [_aColor[0], _aColor[1], _aColor[2], 1.0]);
112
+ _aColor2 = ppty.getSpecularColorByReference();
113
+ model.UBO.setArray('SpecularColor', [_aColor2[0], _aColor2[1], _aColor2[2], 1.0]);
114
+ } // Edge and line rendering
115
+
116
+
117
+ var aColor = (_ppty$getEdgeColorByR = ppty.getEdgeColorByReference) === null || _ppty$getEdgeColorByR === void 0 ? void 0 : _ppty$getEdgeColorByR.call(ppty);
118
+
119
+ if (aColor) {
120
+ model.UBO.setArray('EdgeColor', [aColor[0], aColor[1], aColor[2], 1.0]);
101
121
  }
102
122
 
103
123
  model.UBO.setValue('LineWidth', ppty.getLineWidth());
@@ -130,10 +150,11 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
130
150
  publicAPI.replaceShaderPosition = function (hash, pipeline, vertexInput) {
131
151
  var vDesc = pipeline.getShaderDescription('vertex');
132
152
  vDesc.addBuiltinOutput('vec4<f32>', '@builtin(position) Position');
153
+ if (!vDesc.hasOutput('vertexVC')) vDesc.addOutput('vec4<f32>', 'vertexVC');
133
154
  var code = vDesc.getCode();
134
155
 
135
156
  if (model.useRendererMatrix) {
136
- code = vtkWebGPUShaderCache.substitute(code, '//VTK::Position::Impl', [' var pCoord: vec4<f32> = rendererUBO.SCPCMatrix*mapperUBO.BCSCMatrix*vertexBC;', '//VTK::Position::Impl']).result;
157
+ code = vtkWebGPUShaderCache.substitute(code, '//VTK::Position::Impl', [' var pCoord: vec4<f32> = rendererUBO.SCPCMatrix*mapperUBO.BCSCMatrix*vertexBC;', ' output.vertexVC = rendererUBO.SCVCMatrix * mapperUBO.BCSCMatrix * vec4<f32>(vertexBC.xyz, 1.0);', '//VTK::Position::Impl']).result;
137
158
 
138
159
  if (model.forceZValue) {
139
160
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::Position::Impl', ['pCoord = vec4<f32>(pCoord.xyz/pCoord.w, 1.0);', 'pCoord.z = mapperUBO.ZValue;', '//VTK::Position::Impl']).result;
@@ -161,16 +182,38 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
161
182
 
162
183
  publicAPI.replaceShaderNormal = function (hash, pipeline, vertexInput) {
163
184
  var normalBuffer = vertexInput.getBuffer('normalMC');
185
+ var actor = model.WebGPUActor.getRenderable();
164
186
 
165
187
  if (normalBuffer) {
166
188
  var vDesc = pipeline.getShaderDescription('vertex');
167
- vDesc.addOutput('vec3<f32>', 'normalVC', normalBuffer.getArrayInformation()[0].interpolation);
189
+
190
+ if (!vDesc.hasOutput('normalVC')) {
191
+ vDesc.addOutput('vec3<f32>', 'normalVC', normalBuffer.getArrayInformation()[0].interpolation);
192
+ }
193
+
194
+ if (!vDesc.hasOutput('tangentVC')) {
195
+ vDesc.addOutput('vec3<f32>', 'tangentVC', normalBuffer.getArrayInformation()[0].interpolation);
196
+ }
197
+
198
+ if (!vDesc.hasOutput('bitangentVC')) {
199
+ vDesc.addOutput('vec3<f32>', 'bitangentVC', normalBuffer.getArrayInformation()[0].interpolation);
200
+ }
201
+
168
202
  var code = vDesc.getCode();
169
- code = vtkWebGPUShaderCache.substitute(code, '//VTK::Normal::Impl', [' output.normalVC = normalize((rendererUBO.WCVCNormals * mapperUBO.MCWCNormals * normalMC).xyz);']).result;
203
+ code = vtkWebGPUShaderCache.substitute(code, '//VTK::Normal::Impl', [' output.normalVC = normalize((rendererUBO.WCVCNormals * mapperUBO.MCWCNormals * normalMC).xyz);', // This is just an approximation, but it happens to work extremely well
204
+ // It only works well for normals that are head on and not super angled though
205
+ // Definitely needs to be replaced
206
+ ' var c1: vec3<f32> = cross(output.normalVC, vec3<f32>(0, 0, 1));', ' var c2: vec3<f32> = cross(output.normalVC, vec3<f32>(0, 1, 0));', ' var tangent: vec3<f32> = mix(c1, c2, distance(c1, c2));', ' output.tangentVC = normalize(tangent);', ' output.bitangentVC = normalize(cross(output.normalVC, tangent));']).result;
170
207
  vDesc.setCode(code);
171
208
  var fDesc = pipeline.getShaderDescription('fragment');
172
209
  code = fDesc.getCode();
173
- code = vtkWebGPUShaderCache.substitute(code, '//VTK::Normal::Impl', [' var normal: vec3<f32> = input.normalVC;', ' if (!input.frontFacing) { normal = -normal; }']).result;
210
+
211
+ if (actor.getProperty().getNormalTexture()) {
212
+ code = vtkWebGPUShaderCache.substitute(code, '//VTK::Normal::Impl', [' var normal: vec3<f32> = input.normalVC;', ' if (!input.frontFacing) { normal = -normal; }', ' var tangent: vec3<f32> = input.tangentVC;', ' var bitangent: vec3<f32> = input.bitangentVC;', ' var TCVCMatrix: mat3x3<f32> = mat3x3<f32>(', ' tangent.x, bitangent.x, normal.x,', ' tangent.y, bitangent.y, normal.y,', ' tangent.z, bitangent.z, normal.z,', ' );', ' normal = TCVCMatrix * (_normalMap.xyz * 2 - 1);', ' normal = mix(input.normalVC, normal, mapperUBO.NormalStrength);', ' normal = normalize(normal);']).result;
213
+ } else {
214
+ code = vtkWebGPUShaderCache.substitute(code, '//VTK::Normal::Impl', [' var normal: vec3<f32> = input.normalVC;', ' if (!input.frontFacing) { normal = -normal; }', ' normal = normalize(normal);']).result;
215
+ }
216
+
174
217
  fDesc.setCode(code);
175
218
  }
176
219
  };
@@ -179,14 +222,24 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
179
222
  // fragment shader code. That is the lighting trigger.
180
223
 
181
224
  publicAPI.replaceShaderLight = function (hash, pipeline, vertexInput) {
225
+ if (hash.includes('sel')) return;
226
+ var vDesc = pipeline.getShaderDescription('vertex');
227
+ if (!vDesc.hasOutput('vertexVC')) vDesc.addOutput('vec4<f32>', 'vertexVC');
182
228
  var fDesc = pipeline.getShaderDescription('fragment');
183
- var code = fDesc.getCode();
184
-
185
- if (code.includes('var normal')) {
186
- code = vtkWebGPUShaderCache.substitute(code, '//VTK::Light::Impl', [' var df: f32 = max(0.0, normal.z);', ' var sf: f32 = pow(df, mapperUBO.SpecularPower);', ' var diffuse: vec3<f32> = df * diffuseColor.rgb;', ' var specular: vec3<f32> = sf * mapperUBO.SpecularColor.rgb * mapperUBO.SpecularColor.a;']).result;
187
- fDesc.setCode(code);
229
+ var code = fDesc.getCode(); // Code that runs if the fragment shader includes normals
230
+
231
+ if (code.includes('var normal:') && model.useRendererMatrix && !isEdges(hash) && !model.is2D && !hash.includes('sel')) {
232
+ code = vtkWebGPUShaderCache.substitute(code, '//VTK::Light::Impl', [// Constants
233
+ ' var pi: f32 = 3.14159265359;', // Vectors needed for light calculations
234
+ ' var fragPos: vec3<f32> = vec3<f32>(input.vertexVC.xyz);', ' var V: vec3<f32> = mix(normalize(-fragPos), vec3<f32>(0, 0, 1), f32(rendererUBO.cameraParallel)); // View Vector', // Values needed for light calculations
235
+ ' var baseColor: vec3<f32> = _diffuseMap.rgb * diffuseColor.rgb;', ' var roughness: f32 = max(0.000001, mapperUBO.Roughness * _roughnessMap.r);', // Need to have a different way of sampling greyscale values aside from .r
236
+ ' var metallic: f32 = mapperUBO.Metallic * _metallicMap.r;', ' var alpha: f32 = roughness*roughness;', ' var ior: f32 = mapperUBO.BaseIOR;', ' var k: f32 = alpha*alpha / 2;', // Split diffuse and specular components
237
+ ' var diffuse: vec3<f32> = vec3<f32>(0.);', ' var specular: vec3<f32> = vec3<f32>(0.);', ' var emission: vec3<f32> = _emissionMap.rgb * mapperUBO.Emission;', // Summing diffuse and specular components of directional lights
238
+ ' {', ' var i: i32 = 0;', ' loop {', ' if !(i < rendererUBO.LightCount) { break; }', ' switch (i32(rendererLightSSBO.values[i].LightData.x)) {', ' // Point Light', ' case 0 {', ' var color: vec3<f32> = rendererLightSSBO.values[i].LightColor.rgb * rendererLightSSBO.values[i].LightColor.w;', ' var pos: vec3<f32> = (rendererLightSSBO.values[i].LightPos).xyz;', ' var calculated: PBRData = calcPointLight(normal, V, fragPos, ior, roughness, metallic, pos, color, baseColor);', ' diffuse += max(vec3<f32>(0), calculated.diffuse);', ' specular += max(vec3<f32>(0), calculated.specular);', ' }', ' // Directional light', ' case 1 {', ' var dir: vec3<f32> = (rendererUBO.WCVCNormals * vec4<f32>(normalize(rendererLightSSBO.values[i].LightDir.xyz), 0.)).xyz;', ' dir = normalize(dir);', ' var color: vec3<f32> = rendererLightSSBO.values[i].LightColor.rgb * rendererLightSSBO.values[i].LightColor.w;', ' var calculated: PBRData = calcDirectionalLight(normal, V, ior, roughness, metallic, dir, color, baseColor); // diffuseColor.rgb needs to be fixed with a more dynamic diffuse color', ' diffuse += max(vec3<f32>(0), calculated.diffuse);', ' specular += max(vec3<f32>(0), calculated.specular);', ' }', ' // Spot Light', ' case 2 {', ' var color: vec3<f32> = rendererLightSSBO.values[i].LightColor.rgb * rendererLightSSBO.values[i].LightColor.w;', ' var pos: vec3<f32> = (rendererLightSSBO.values[i].LightPos).xyz;', ' var dir: vec3<f32> = (rendererUBO.WCVCNormals * vec4<f32>(normalize(rendererLightSSBO.values[i].LightDir.xyz), 0.)).xyz;', ' dir = normalize(dir);', ' var cones: vec2<f32> = vec2<f32>(rendererLightSSBO.values[i].LightData.y, rendererLightSSBO.values[i].LightData.z);', ' var calculated: PBRData = calcSpotLight(normal, V, fragPos, ior, roughness, metallic, pos, dir, cones, color, baseColor);', ' diffuse += max(vec3<f32>(0), calculated.diffuse);', ' specular += max(vec3<f32>(0), calculated.specular);', ' }', ' default { continue; }', ' }', ' continuing { i++; }', ' }', ' }', // Final variables for combining specular and diffuse
239
+ ' var fresnel: f32 = schlickFresnelIOR(V, normal, ior, k); // Fresnel', ' fresnel = min(1, fresnel);', ' // This could be controlled with its own variable (that isnt base color) for better artistic control', ' var fresnelMetallic: vec3<f32> = schlickFresnelRGB(V, normal, baseColor); // Fresnel for metal, takes color into account', ' var kS: vec3<f32> = mix(vec3<f32>(fresnel), fresnelMetallic, metallic);', ' kS = min(vec3<f32>(1), kS);', ' var kD: vec3<f32> = (1.0 - kS) * (1.0 - metallic);', ' var PBR: vec3<f32> = mapperUBO.DiffuseIntensity*kD*diffuse + kS*specular;', ' PBR += emission;', ' computedColor = vec4<f32>(PBR, mapperUBO.Opacity);']).result;
240
+ fDesc.setCode(code); // If theres no normals, just set the specular color to be flat
188
241
  } else {
189
- code = vtkWebGPUShaderCache.substitute(code, '//VTK::Light::Impl', [' var diffuse: vec3<f32> = diffuseColor.rgb;', ' var specular: vec3<f32> = mapperUBO.SpecularColor.rgb * mapperUBO.SpecularColor.a;']).result;
242
+ code = vtkWebGPUShaderCache.substitute(code, '//VTK::Light::Impl', [' var diffuse: vec3<f32> = diffuseColor.rgb;', ' var specular: vec3<f32> = mapperUBO.SpecularColor.rgb * mapperUBO.SpecularColor.a;', ' computedColor = vec4<f32>(diffuse, mapperUBO.Opacity);']).result;
190
243
  fDesc.setCode(code);
191
244
  }
192
245
  };
@@ -194,6 +247,7 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
194
247
  model.shaderReplacements.set('replaceShaderLight', publicAPI.replaceShaderLight);
195
248
 
196
249
  publicAPI.replaceShaderColor = function (hash, pipeline, vertexInput) {
250
+ // By default, set the colors to be flat
197
251
  if (isEdges(hash)) {
198
252
  var _fDesc = pipeline.getShaderDescription('fragment');
199
253
 
@@ -204,15 +258,18 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
204
258
  _fDesc.setCode(_code);
205
259
 
206
260
  return;
207
- }
261
+ } // If there's no vertex color buffer return the shader as is
262
+
208
263
 
209
264
  var colorBuffer = vertexInput.getBuffer('colorVI');
210
- if (!colorBuffer) return;
265
+ if (!colorBuffer) return; // Modifies the vertex shader to include the vertex colors and interpolation in the outputs
266
+
211
267
  var vDesc = pipeline.getShaderDescription('vertex');
212
268
  vDesc.addOutput('vec4<f32>', 'color', colorBuffer.getArrayInformation()[0].interpolation);
213
269
  var code = vDesc.getCode();
214
270
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::Color::Impl', [' output.color = colorVI;']).result;
215
- vDesc.setCode(code);
271
+ vDesc.setCode(code); // Sets the fragment shader to accept the color inputs from the vertex shader
272
+
216
273
  var fDesc = pipeline.getShaderDescription('fragment');
217
274
  code = fDesc.getCode();
218
275
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::Color::Impl', ['ambientColor = input.color;', 'diffuseColor = input.color;', 'opacity = mapperUBO.Opacity * input.color.a;']).result;
@@ -222,27 +279,70 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
222
279
  model.shaderReplacements.set('replaceShaderColor', publicAPI.replaceShaderColor);
223
280
 
224
281
  publicAPI.replaceShaderTCoord = function (hash, pipeline, vertexInput) {
282
+ var _actor$getProperty$ge, _actor$getProperty, _actor$getProperty$ge2, _actor$getProperty$ge4, _actor$getProperty3, _actor$getProperty$ge5, _actor$getProperty$ge6, _actor$getProperty4, _actor$getProperty$ge7, _actor$getProperty$ge8, _actor$getProperty5, _actor$getProperty$ge9, _actor$getProperty$ge10, _actor$getProperty6, _actor$getProperty$ge11, _actor$getProperty$ge12, _actor$getProperty7, _actor$getProperty$ge13;
283
+
225
284
  if (!vertexInput.hasAttribute('tcoord')) return;
226
285
  var vDesc = pipeline.getShaderDescription('vertex');
227
286
  var tcoords = vertexInput.getBuffer('tcoord');
228
287
  var numComp = vtkWebGPUTypes.getNumberOfComponentsFromBufferFormat(tcoords.getArrayInformation()[0].format);
229
288
  var code = vDesc.getCode();
230
289
  vDesc.addOutput("vec".concat(numComp, "<f32>"), 'tcoordVS');
231
- code = vtkWebGPUShaderCache.substitute(code, '//VTK::TCoord::Impl', [' output.tcoordVS = tcoord;']).result;
290
+ code = vtkWebGPUShaderCache.substitute(code, '//VTK::TCoord::Impl', [' output.tcoordVS = tcoord;' // Ensure that UV coordinates are always between 0-1
291
+ ]).result;
232
292
  vDesc.setCode(code);
293
+ if (model.is2D) return;
233
294
  var fDesc = pipeline.getShaderDescription('fragment');
234
- code = fDesc.getCode(); // todo handle multiple textures? Blend multiply ?
295
+ code = fDesc.getCode();
296
+ var actor = model.WebGPUActor.getRenderable();
235
297
 
236
- if (model.textures.length) {
237
- var tdims = model.textures[0].getDimensions();
298
+ var checkDims = function checkDims(texture) {
299
+ if (!texture) return false;
300
+ var dims = texture.getDimensionality();
301
+ return dims === numComp;
302
+ };
238
303
 
239
- if (tdims === numComp) {
240
- code = vtkWebGPUShaderCache.substitute(code, '//VTK::TCoord::Impl', ['var tcolor: vec4<f32> = textureSample(Texture0, Texture0Sampler, input.tcoordVS);', 'computedColor = computedColor*tcolor;']).result;
241
- } else {
242
- console.log("mismatched texture coord dimension ".concat(numComp, " with texture map dimension ").concat(tdims));
304
+ var usedTextures = [];
305
+
306
+ if ((_actor$getProperty$ge = (_actor$getProperty = actor.getProperty()).getDiffuseTexture) !== null && _actor$getProperty$ge !== void 0 && (_actor$getProperty$ge2 = _actor$getProperty$ge.call(_actor$getProperty)) !== null && _actor$getProperty$ge2 !== void 0 && _actor$getProperty$ge2.getImageLoaded() || actor.getTextures()[0] || model.colorTexture) {
307
+ var _actor$getProperty$ge3, _actor$getProperty2;
308
+
309
+ if ( // Chained or statements here are questionable
310
+ checkDims((_actor$getProperty$ge3 = (_actor$getProperty2 = actor.getProperty()).getDiffuseTexture) === null || _actor$getProperty$ge3 === void 0 ? void 0 : _actor$getProperty$ge3.call(_actor$getProperty2)) || checkDims(actor.getTextures()[0]) || checkDims(model.colorTexture)) {
311
+ usedTextures.push('_diffuseMap = textureSample(DiffuseTexture, DiffuseTextureSampler, input.tcoordVS);');
312
+ }
313
+ }
314
+
315
+ if ((_actor$getProperty$ge4 = (_actor$getProperty3 = actor.getProperty()).getRoughnessTexture) !== null && _actor$getProperty$ge4 !== void 0 && (_actor$getProperty$ge5 = _actor$getProperty$ge4.call(_actor$getProperty3)) !== null && _actor$getProperty$ge5 !== void 0 && _actor$getProperty$ge5.getImageLoaded()) {
316
+ if (checkDims(actor.getProperty().getRoughnessTexture())) {
317
+ usedTextures.push('_roughnessMap = textureSample(RoughnessTexture, RoughnessTextureSampler, input.tcoordVS);');
318
+ }
319
+ }
320
+
321
+ if ((_actor$getProperty$ge6 = (_actor$getProperty4 = actor.getProperty()).getMetallicTexture) !== null && _actor$getProperty$ge6 !== void 0 && (_actor$getProperty$ge7 = _actor$getProperty$ge6.call(_actor$getProperty4)) !== null && _actor$getProperty$ge7 !== void 0 && _actor$getProperty$ge7.getImageLoaded()) {
322
+ if (checkDims(actor.getProperty().getMetallicTexture())) {
323
+ usedTextures.push('_metallicMap = textureSample(MetallicTexture, MetallicTextureSampler, input.tcoordVS);');
324
+ }
325
+ }
326
+
327
+ if ((_actor$getProperty$ge8 = (_actor$getProperty5 = actor.getProperty()).getNormalTexture) !== null && _actor$getProperty$ge8 !== void 0 && (_actor$getProperty$ge9 = _actor$getProperty$ge8.call(_actor$getProperty5)) !== null && _actor$getProperty$ge9 !== void 0 && _actor$getProperty$ge9.getImageLoaded()) {
328
+ if (checkDims(actor.getProperty().getNormalTexture())) {
329
+ usedTextures.push('_normalMap = textureSample(NormalTexture, NormalTextureSampler, input.tcoordVS);');
243
330
  }
244
331
  }
245
332
 
333
+ if ((_actor$getProperty$ge10 = (_actor$getProperty6 = actor.getProperty()).getAmbientOcclusionTexture) !== null && _actor$getProperty$ge10 !== void 0 && (_actor$getProperty$ge11 = _actor$getProperty$ge10.call(_actor$getProperty6)) !== null && _actor$getProperty$ge11 !== void 0 && _actor$getProperty$ge11.getImageLoaded()) {
334
+ if (checkDims(actor.getProperty().getAmbientOcclusionTexture())) {
335
+ usedTextures.push('_ambientOcclusionMap = textureSample(AmbientOcclusionTexture, AmbientOcclusionTextureSampler, input.tcoordVS);');
336
+ }
337
+ }
338
+
339
+ if ((_actor$getProperty$ge12 = (_actor$getProperty7 = actor.getProperty()).getEmissionTexture) !== null && _actor$getProperty$ge12 !== void 0 && (_actor$getProperty$ge13 = _actor$getProperty$ge12.call(_actor$getProperty7)) !== null && _actor$getProperty$ge13 !== void 0 && _actor$getProperty$ge13.getImageLoaded()) {
340
+ if (checkDims(actor.getProperty().getEmissionTexture())) {
341
+ usedTextures.push('_emissionMap = textureSample(EmissionTexture, EmissionTextureSampler, input.tcoordVS);');
342
+ }
343
+ }
344
+
345
+ code = vtkWebGPUShaderCache.substitute(code, '//VTK::TCoord::Impl', usedTextures).result;
246
346
  fDesc.setCode(code);
247
347
  };
248
348
 
@@ -309,7 +409,8 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
309
409
  default:
310
410
  return 'line-list';
311
411
  }
312
- };
412
+ }; // TODO: calculate tangents
413
+
313
414
 
314
415
  publicAPI.buildVertexInput = function () {
315
416
  var _model$renderable$get, _model$renderable;
@@ -379,7 +480,9 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
379
480
 
380
481
  if (!model.is2D && ( // no lighting on Property2D
381
482
  usage === BufferUsage.Triangles || usage === BufferUsage.Strips)) {
382
- var normals = pd.getPointData().getNormals();
483
+ var normals = pd.getPointData().getNormals(); // https://vtk.org/doc/nightly/html/classvtkPolyDataTangents.html
484
+ // Need to find some way of using precomputed tangents (or computing new ones)
485
+
383
486
  var _buffRequest2 = {
384
487
  format: 'snorm8x4',
385
488
  indexBuffer: indexBuffer,
@@ -466,7 +569,7 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
466
569
  };
467
570
 
468
571
  publicAPI.updateTextures = function () {
469
- var _model$renderable$get2, _model$renderable2;
572
+ var _model$renderable$get2, _model$renderable2, _actor$getProperty$ge14, _actor$getProperty8, _actor$getProperty$ge15, _actor$getProperty9, _actor$getProperty$ge16, _actor$getProperty10, _actor$getProperty$ge17, _actor$getProperty11, _actor$getProperty$ge18, _actor$getProperty12, _actor$getProperty$ge19, _actor$getProperty13, _renderer$getBackgrou;
470
573
 
471
574
  // we keep track of new and used textures so
472
575
  // that we can clean up any unused textures so we don't hold onto them
@@ -483,28 +586,69 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
483
586
  }
484
587
 
485
588
  model.colorTexture.setInputData(idata);
486
- newTextures.push(model.colorTexture);
589
+ newTextures.push(['Diffuse', model.colorTexture]);
487
590
  } // actor textures?
488
591
 
489
592
 
490
593
  var actor = model.WebGPUActor.getRenderable();
491
- var textures = actor.getTextures();
594
+ var renderer = model.WebGPURenderer.getRenderable(); // Reusing the old code for new and old textures, just loading in from properties instead of actor.getTextures()
595
+
596
+ var textures = []; // Feels like there should be a better way than individually adding all
597
+
598
+ if ((_actor$getProperty$ge14 = (_actor$getProperty8 = actor.getProperty()).getDiffuseTexture) !== null && _actor$getProperty$ge14 !== void 0 && _actor$getProperty$ge14.call(_actor$getProperty8)) {
599
+ var pair = ['Diffuse', actor.getProperty().getDiffuseTexture()];
600
+ textures.push(pair);
601
+ }
602
+
603
+ if (actor.getTextures()[0]) {
604
+ var _pair = ['Diffuse', actor.getTextures()[0]];
605
+ textures.push(_pair);
606
+ }
607
+
608
+ if ((_actor$getProperty$ge15 = (_actor$getProperty9 = actor.getProperty()).getRoughnessTexture) !== null && _actor$getProperty$ge15 !== void 0 && _actor$getProperty$ge15.call(_actor$getProperty9)) {
609
+ var _pair2 = ['Roughness', actor.getProperty().getRoughnessTexture()];
610
+ textures.push(_pair2);
611
+ }
612
+
613
+ if ((_actor$getProperty$ge16 = (_actor$getProperty10 = actor.getProperty()).getMetallicTexture) !== null && _actor$getProperty$ge16 !== void 0 && _actor$getProperty$ge16.call(_actor$getProperty10)) {
614
+ var _pair3 = ['Metallic', actor.getProperty().getMetallicTexture()];
615
+ textures.push(_pair3);
616
+ }
617
+
618
+ if ((_actor$getProperty$ge17 = (_actor$getProperty11 = actor.getProperty()).getNormalTexture) !== null && _actor$getProperty$ge17 !== void 0 && _actor$getProperty$ge17.call(_actor$getProperty11)) {
619
+ var _pair4 = ['Normal', actor.getProperty().getNormalTexture()];
620
+ textures.push(_pair4);
621
+ }
622
+
623
+ if ((_actor$getProperty$ge18 = (_actor$getProperty12 = actor.getProperty()).getAmbientOcclusionTexture) !== null && _actor$getProperty$ge18 !== void 0 && _actor$getProperty$ge18.call(_actor$getProperty12)) {
624
+ var _pair5 = ['AmbientOcclusion', actor.getProperty().getAmbientOcclusionTexture()];
625
+ textures.push(_pair5);
626
+ }
627
+
628
+ if ((_actor$getProperty$ge19 = (_actor$getProperty13 = actor.getProperty()).getEmissionTexture) !== null && _actor$getProperty$ge19 !== void 0 && _actor$getProperty$ge19.call(_actor$getProperty13)) {
629
+ var _pair6 = ['Emission', actor.getProperty().getEmissionTexture()];
630
+ textures.push(_pair6);
631
+ }
632
+
633
+ if ((_renderer$getBackgrou = renderer.getBackgroundTexture) !== null && _renderer$getBackgrou !== void 0 && _renderer$getBackgrou.call(renderer)) {
634
+ var _pair7 = ['Background', renderer.getBackgroundTexture()];
635
+ textures.push(_pair7);
636
+ }
492
637
 
493
638
  for (var i = 0; i < textures.length; i++) {
494
- if (textures[i].getInputData() || textures[i].getJsImageData() || textures[i].getCanvas()) {
639
+ if (textures[i][1].getInputData() || textures[i][1].getJsImageData() || textures[i][1].getCanvas()) {
495
640
  newTextures.push(textures[i]);
496
641
  }
497
642
 
498
- if (textures[i].getImage() && textures[i].getImageLoaded()) {
643
+ if (textures[i][1].getImage() && textures[i][1].getImageLoaded()) {
499
644
  newTextures.push(textures[i]);
500
645
  }
501
646
  }
502
647
 
503
- var usedCount = 0;
504
-
505
648
  for (var _i = 0; _i < newTextures.length; _i++) {
506
- var srcTexture = newTextures[_i];
507
- var newTex = model.device.getTextureManager().getTextureForVTKTexture(srcTexture);
649
+ var srcTexture = newTextures[_i][1];
650
+ var textureName = newTextures[_i][0];
651
+ var newTex = model.device.getTextureManager().getTextureForVTKTexture(srcTexture); // Generates hash
508
652
 
509
653
  if (newTex.getReady()) {
510
654
  // is this a new texture
@@ -512,7 +656,6 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
512
656
 
513
657
  for (var t = 0; t < model.textures.length; t++) {
514
658
  if (model.textures[t] === newTex) {
515
- usedCount++;
516
659
  found = true;
517
660
  usedTextures[t] = true;
518
661
  }
@@ -520,7 +663,7 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
520
663
 
521
664
  if (!found) {
522
665
  usedTextures[model.textures.length] = true;
523
- var tview = newTex.createView("Texture".concat(usedCount++));
666
+ var tview = newTex.createView("".concat(textureName, "Texture"));
524
667
  model.textures.push(newTex);
525
668
  model.textureViews.push(tview);
526
669
  var interpolate = srcTexture.getInterpolate() ? 'linear' : 'nearest';
@@ -623,14 +766,15 @@ var DEFAULT_VALUES = {
623
766
  }; // ----------------------------------------------------------------------------
624
767
 
625
768
  function extend(publicAPI, model) {
626
- var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
627
- Object.assign(model, DEFAULT_VALUES, initialValues); // Inheritance
769
+ var initiaLalues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
770
+ Object.assign(model, DEFAULT_VALUES, initiaLalues); // Inheritance
628
771
 
629
- vtkWebGPUSimpleMapper.extend(publicAPI, model, initialValues);
772
+ vtkWebGPUSimpleMapper.extend(publicAPI, model, initiaLalues);
630
773
  model.fragmentShaderTemplate = vtkWebGPUPolyDataFS;
631
774
  model.vertexShaderTemplate = vtkWebGPUPolyDataVS;
632
775
  model._tmpMat3 = mat3.identity(new Float64Array(9));
633
- model._tmpMat4 = mat4.identity(new Float64Array(16));
776
+ model._tmpMat4 = mat4.identity(new Float64Array(16)); // UBO
777
+
634
778
  model.UBO = vtkWebGPUUniformBuffer.newInstance({
635
779
  label: 'mapperUBO'
636
780
  });
@@ -643,12 +787,21 @@ function extend(publicAPI, model) {
643
787
  model.UBO.addEntry('SpecularColor', 'vec4<f32>');
644
788
  model.UBO.addEntry('AmbientIntensity', 'f32');
645
789
  model.UBO.addEntry('DiffuseIntensity', 'f32');
790
+ model.UBO.addEntry('Roughness', 'f32');
791
+ model.UBO.addEntry('Metallic', 'f32');
792
+ model.UBO.addEntry('Ambient', 'f32');
793
+ model.UBO.addEntry('Normal', 'f32');
794
+ model.UBO.addEntry('Emission', 'f32');
795
+ model.UBO.addEntry('NormalStrength', 'f32');
796
+ model.UBO.addEntry('BaseIOR', 'f32');
646
797
  model.UBO.addEntry('SpecularIntensity', 'f32');
647
798
  model.UBO.addEntry('LineWidth', 'f32');
648
799
  model.UBO.addEntry('Opacity', 'f32');
649
- model.UBO.addEntry('SpecularPower', 'f32');
650
800
  model.UBO.addEntry('ZValue', 'f32');
651
- model.UBO.addEntry('PropID', 'u32'); // Build VTK API
801
+ model.UBO.addEntry('PropID', 'u32');
802
+ model.UBO.addEntry('ClipNear', 'f32');
803
+ model.UBO.addEntry('ClipFar', 'f32');
804
+ model.UBO.addEntry('Time', 'u32'); // Build VTK API
652
805
 
653
806
  setGet(publicAPI, model, ['cellArray', 'currentInput', 'cellOffset', 'is2D', 'primitiveType', 'renderEncoder']);
654
807
  model.textures = []; // Object methods
@@ -29,8 +29,9 @@ function vtkWebGPUGlyph3DCellArrayMapper(publicAPI, model) {
29
29
  var vDesc = pipeline.getShaderDescription('vertex');
30
30
  vDesc.addBuiltinInput('u32', '@builtin(instance_index) instanceIndex');
31
31
  vDesc.addBuiltinOutput('vec4<f32>', '@builtin(position) Position');
32
+ if (!vDesc.hasOutput('vertexVC')) vDesc.addOutput('vec3<f32>', 'vertexVC');
32
33
  var code = vDesc.getCode();
33
- code = vtkWebGPUShaderCache.substitute(code, '//VTK::Position::Impl', [' output.Position = rendererUBO.SCPCMatrix*mapperUBO.BCSCMatrix', ' *glyphSSBO.values[input.instanceIndex].matrix', ' *vertexBC;']).result;
34
+ code = vtkWebGPUShaderCache.substitute(code, '//VTK::Position::Impl', [' var vertexSC: vec4<f32> = mapperUBO.BCSCMatrix*glyphSSBO.values[input.instanceIndex].matrix*vertexBC;', ' output.vertexVC = (rendererUBO.SCVCMatrix*vertexSC).xyz;', ' output.Position = rendererUBO.SCPCMatrix*vertexSC;']).result;
34
35
  vDesc.setCode(code);
35
36
  };
36
37
 
@@ -106,7 +106,10 @@ function vtkWebGPUImageMapper(publicAPI, model) {
106
106
  var modelToIndex = image.getWorldToIndex();
107
107
  mat4.multiply(tmpMat4, modelToIndex, tmpMat4); // tmpMat4 is now SC -> Index, save this as we need it later
108
108
 
109
- mat4.invert(tmp3Mat4, tmpMat4);
109
+ mat4.invert(tmp3Mat4, tmpMat4); // need translation and scale
110
+
111
+ mat4.fromTranslation(tmp2Mat4, [0.5, 0.5, 0.5]);
112
+ mat4.multiply(tmpMat4, tmp2Mat4, tmpMat4);
110
113
  var dims = image.getDimensions();
111
114
  mat4.identity(tmp2Mat4);
112
115
  mat4.scale(tmp2Mat4, tmp2Mat4, [1.0 / dims[0], 1.0 / dims[1], 1.0 / dims[2]]);
@@ -143,22 +146,22 @@ function vtkWebGPUImageMapper(publicAPI, model) {
143
146
  }
144
147
 
145
148
  ptsArray1[axis0] = nSlice;
146
- ptsArray1[axis1] = ext[axis1 * 2];
147
- ptsArray1[axis2] = ext[axis2 * 2];
149
+ ptsArray1[axis1] = ext[axis1 * 2] - 0.5;
150
+ ptsArray1[axis2] = ext[axis2 * 2] - 0.5;
148
151
  ptsArray1[3] = 1.0;
149
152
  vec4.transformMat4(ptsArray1, ptsArray1, tmp3Mat4);
150
153
  model.UBO.setArray('Origin', ptsArray1);
151
154
  ptsArray2[axis0] = nSlice;
152
- ptsArray2[axis1] = ext[axis1 * 2 + 1];
153
- ptsArray2[axis2] = ext[axis2 * 2];
155
+ ptsArray2[axis1] = ext[axis1 * 2 + 1] + 0.5;
156
+ ptsArray2[axis2] = ext[axis2 * 2] - 0.5;
154
157
  ptsArray2[3] = 1.0;
155
158
  vec4.transformMat4(ptsArray2, ptsArray2, tmp3Mat4);
156
159
  vec4.subtract(ptsArray2, ptsArray2, ptsArray1);
157
160
  ptsArray2[3] = 1.0;
158
161
  model.UBO.setArray('Axis1', ptsArray2);
159
162
  ptsArray2[axis0] = nSlice;
160
- ptsArray2[axis1] = ext[axis1 * 2];
161
- ptsArray2[axis2] = ext[axis2 * 2 + 1];
163
+ ptsArray2[axis1] = ext[axis1 * 2] - 0.5;
164
+ ptsArray2[axis2] = ext[axis2 * 2 + 1] + 0.5;
162
165
  ptsArray2[3] = 1.0;
163
166
  vec4.transformMat4(ptsArray2, ptsArray2, tmp3Mat4);
164
167
  vec4.subtract(ptsArray2, ptsArray2, ptsArray1);
@@ -179,7 +182,7 @@ function vtkWebGPUImageMapper(publicAPI, model) {
179
182
  var target = iComps ? i : 0;
180
183
  var cfun = actor.getProperty().getRGBTransferFunction(target);
181
184
 
182
- if (cfun && actor.getProperty().getUseLookupTableScalarRange()) {
185
+ if (cfun) {
183
186
  var cRange = cfun.getRange();
184
187
  cw = cRange[1] - cRange[0];
185
188
  cl = 0.5 * (cRange[1] + cRange[0]);
@@ -83,17 +83,6 @@ function vtkWebGPUPipeline(publicAPI, model) {
83
83
  publicAPI.bindVertexInput = function (renderEncoder, vInput) {
84
84
  vInput.bindBuffers(renderEncoder);
85
85
  };
86
-
87
- publicAPI.addDrawCallback = function (cb) {
88
- model._drawCallbacks.push(cb);
89
- }; // handle anything that needs to be done when drawing
90
-
91
-
92
- publicAPI.draw = function (encoder) {
93
- for (var cb = 0; cb < model._drawCallbacks.length; cb++) {
94
- model._drawCallbacks[cb](encoder, publicAPI);
95
- }
96
- };
97
86
  } // ----------------------------------------------------------------------------
98
87
  // Object factory
99
88
  // ----------------------------------------------------------------------------
@@ -116,7 +105,6 @@ function extend(publicAPI, model) {
116
105
  obj(publicAPI, model);
117
106
  model.layouts = [];
118
107
  model.shaderDescriptions = [];
119
- model._drawCallbacks = [];
120
108
  get(publicAPI, model, ['handle', 'pipelineDescription']);
121
109
  setGet(publicAPI, model, ['device', 'renderEncoder', 'topology', 'vertexState']); // For more macro methods, see "Sources/macros.js"
122
110
  // Object specific methods
@@ -74,7 +74,6 @@ function vtkWebGPURenderEncoder(publicAPI, model) {
74
74
  }
75
75
 
76
76
  model.boundPipeline = pl;
77
- pl.draw(publicAPI);
78
77
  };
79
78
 
80
79
  publicAPI.replaceShaderCode = function (pipeline) {