@niivue/niivue 0.26.2 → 0.28.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.
@@ -0,0 +1,64 @@
1
+ export const orientCube = new Float32Array([
2
+ -1, -1, -1, 0.28, 0.28, 0.28, -1, -1, -1, 0.28, 0.28, 0.28, -1, 1, -1, 0.28,
3
+ 0.28, 0.28, 1, -1, -1, 0.28, 0.28, 0.28, 1, 1, -1, 0.28, 0.28, 0.28, 1, 1, -1,
4
+ 0.28, 0.28, 0.28, -1, -1, 1, 0.8, 0.8, 0.8, -1, -1, 1, 0.8, 0.8, 0.8, 1, -1,
5
+ 1, 0.8, 0.8, 0.8, -1, 1, 1, 0.8, 0.8, 0.8, 1, 1, 1, 0.8, 0.8, 0.8, 1, 1, 1,
6
+ 0.8, 0.8, 0.8, -1, 1, -1, 0, 0, 0.74, -1, 1, -1, 0, 0, 0.74, -1, 1, 1, 0, 0,
7
+ 0.74, 1, 1, -1, 0, 0, 0.74, 1, 1, 1, 0, 0, 0.74, 1, 1, 1, 0, 0, 0.74, -1, -1,
8
+ -1, 0.42, 0, 0.42, -1, -1, -1, 0.42, 0, 0.42, 1, -1, -1, 0.42, 0, 0.42, -1,
9
+ -1, 1, 0.42, 0, 0.42, 1, -1, 1, 0.42, 0, 0.42, 1, -1, 1, 0.42, 0, 0.42, -1,
10
+ -1, -1, 0.64, 0, 0, -1, -1, -1, 0.64, 0, 0, -1, -1, 1, 0.64, 0, 0, -1, 1, -1,
11
+ 0.64, 0, 0, -1, 1, 1, 0.64, 0, 0, -1, 1, 1, 0.64, 0, 0, 1, -1, -1, 0, 0.5, 0,
12
+ 1, -1, -1, 0, 0.5, 0, 1, 1, -1, 0, 0.5, 0, 1, -1, 1, 0, 0.5, 0, 1, 1, 1, 0,
13
+ 0.5, 0, 1, 1, 1, 0, 0.5, 0,
14
+ //P
15
+ -0.45, 1, -0.8, 0, 0, 0, -0.45, 1, -0.8, 0, 0, 0, -0.45, 1, 0.8, 0, 0, 0,
16
+ -0.25, 1, -0.8, 0, 0, 0, -0.25, 1, 0.8, 0, 0, 0, -0.25, 1, 0.8, 0, 0, 0,
17
+ -0.25, 1, 0.6, 0, 0, 0, -0.25, 1, 0.6, 0, 0, 0, -0.25, 1, 0.8, 0, 0, 0, 0.45,
18
+ 1, 0.6, 0, 0, 0, 0.25, 1, 0.8, 0, 0, 0, 0.25, 1, 0.8, 0, 0, 0, 0.25, 1, 0.1,
19
+ 0, 0, 0, 0.25, 1, 0.1, 0, 0, 0, 0.25, 1, 0.6, 0, 0, 0, 0.45, 1, 0.1, 0, 0, 0,
20
+ 0.45, 1, 0.6, 0, 0, 0, 0.45, 1, 0.6, 0, 0, 0, -0.25, 1, -0.1, 0, 0, 0, -0.25,
21
+ 1, -0.1, 0, 0, 0, -0.25, 1, 0.1, 0, 0, 0, 0.25, 1, -0.1, 0, 0, 0, 0.45, 1,
22
+ 0.1, 0, 0, 0, 0.45, 1, 0.1, 0, 0, 0,
23
+ //A
24
+ 0.45, -1, -0.8, 0, 0, 0, 0.45, -1, -0.8, 0, 0, 0, 0.05, -1, 0.8, 0, 0, 0,
25
+ 0.25, -1, -0.8, 0, 0, 0, -0.15, -1, 0.8, 0, 0, 0, -0.15, -1, 0.8, 0, 0, 0,
26
+ -0.25, -1, -0.8, 0, 0, 0, -0.25, -1, -0.8, 0, 0, 0, 0.05, -1, 0.8, 0, 0, 0,
27
+ -0.45, -1, -0.8, 0, 0, 0, -0.15, -1, 0.8, 0, 0, 0, -0.15, -1, 0.8, 0, 0, 0,
28
+ 0.13, -1, -0.3, 0, 0, 0, 0.13, -1, -0.3, 0, 0, 0, 0.07, -1, -0.1, 0, 0, 0,
29
+ -0.33, -1, -0.3, 0, 0, 0, -0.27, -1, -0.1, 0, 0, 0, -0.27, -1, -0.1, 0, 0, 0,
30
+ //S
31
+ -0.45, 0.6, 1, 0, 0, 0, -0.45, 0.6, 1, 0, 0, 0, -0.45, 0.4, 1, 0, 0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0, 0, 0, 0.1, 0.8, -1, 0, 0, 0, 0.1, 0.8, -1, 0, 0, 0,
48
+ //L
49
+ -1, -0.45, -0.8, 0, 0, 0, -1, -0.45, -0.8, 0, 0, 0, -1, -0.45, 0.8, 0, 0, 0,
50
+ -1, -0.25, -0.8, 0, 0, 0, -1, -0.25, 0.8, 0, 0, 0, -1, -0.25, 0.8, 0, 0, 0,
51
+ -1, -0.25, -0.8, 0, 0, 0, -1, -0.25, -0.8, 0, 0, 0, -1, -0.25, -0.6, 0, 0, 0,
52
+ -1, 0.45, -0.8, 0, 0, 0, -1, 0.45, -0.6, 0, 0, 0, -1, 0.45, -0.6, 0, 0, 0,
53
+ //R
54
+ 1, 0.45, -0.8, 0, 0, 0, 1, 0.45, -0.8, 0, 0, 0, 1, 0.45, 0.8, 0, 0, 0, 1,
55
+ 0.25, -0.8, 0, 0, 0, 1, 0.25, 0.8, 0, 0, 0, 1, 0.25, 0.8, 0, 0, 0, 1, 0.25,
56
+ 0.6, 0, 0, 0, 1, 0.25, 0.6, 0, 0, 0, 1, 0.25, 0.8, 0, 0, 0, 1, -0.45, 0.6, 0,
57
+ 0, 0, 1, -0.25, 0.8, 0, 0, 0, 1, -0.25, 0.8, 0, 0, 0, 1, -0.25, 0.1, 0, 0, 0,
58
+ 1, -0.25, 0.1, 0, 0, 0, 1, -0.25, 0.6, 0, 0, 0, 1, -0.45, 0.1, 0, 0, 0, 1,
59
+ -0.45, 0.6, 0, 0, 0, 1, -0.45, 0.6, 0, 0, 0, 1, 0.25, -0.1, 0, 0, 0, 1, 0.25,
60
+ -0.1, 0, 0, 0, 1, 0.25, 0.1, 0, 0, 0, 1, -0.25, -0.1, 0, 0, 0, 1, -0.45, 0.1,
61
+ 0, 0, 0, 1, -0.45, 0.1, 0, 0, 0, 1, -0.25, -0.8, 0, 0, 0, 1, -0.25, -0.8, 0,
62
+ 0, 0, 1, -0.05, -0.1, 0, 0, 0, 1, -0.45, -0.8, 0, 0, 0, 1, -0.25, -0.1, 0, 0,
63
+ 0, 1, -0.25, -0.1, 0, 0, 0,
64
+ ]);
@@ -46,7 +46,20 @@ vec4 applyClip (vec3 dir, inout vec4 samplePos, inout float len, inout bool isCl
46
46
  samplePos = vec4(samplePos.xyz+dir * disBackFace, disBackFace);
47
47
  }
48
48
  return samplePos;
49
- }`;
49
+ }
50
+ float frac2ndc(vec3 frac) {
51
+ //https://stackoverflow.com/questions/7777913/how-to-render-depth-linearly-in-modern-opengl-with-gl-fragcoord-z-in-fragment-sh
52
+ vec4 pos = vec4(frac.xyz, 1.0); //fraction
53
+ vec4 dim = vec4(vec3(textureSize(volume, 0)), 1.0);
54
+ pos = pos * dim;
55
+ vec4 shim = vec4(-0.5, -0.5, -0.5, 0.0);
56
+ pos += shim;
57
+ vec4 mm = transpose(matRAS) * pos;
58
+ float z_ndc = (mvpMtx * vec4(mm.xyz, 1.0)).z;
59
+ return (z_ndc + 1.0) / 2.0;
60
+
61
+ }
62
+ `;
50
63
  export var fragRenderShaderMIP =
51
64
  `#version 300 es
52
65
  #line 14
@@ -66,20 +79,7 @@ in vec3 vColor;
66
79
  out vec4 fColor;
67
80
  ` +
68
81
  kRenderFunc +
69
- `
70
- float frac2ndc(vec3 frac) {
71
- //https://stackoverflow.com/questions/7777913/how-to-render-depth-linearly-in-modern-opengl-with-gl-fragcoord-z-in-fragment-sh
72
- vec4 pos = vec4(frac.xyz, 1.0); //fraction
73
- vec4 dim = vec4(vec3(textureSize(volume, 0)), 1.0);
74
- pos = pos * dim;
75
- vec4 shim = vec4(-0.5, -0.5, -0.5, 0.0);
76
- pos += shim;
77
- vec4 mm = transpose(matRAS) * pos;
78
- float z_ndc = (mvpMtx * vec4(mm.xyz, 1.0)).z;
79
- return (z_ndc + 1.0) / 2.0;
80
-
81
- }
82
- void main() {
82
+ `void main() {
83
83
  fColor = vec4(0.0,0.0,0.0,0.0);
84
84
  //fColor = vec4(vColor.rgb, 1.0); return;
85
85
  vec3 start = vColor;
@@ -219,20 +219,7 @@ in vec3 vColor;
219
219
  out vec4 fColor;
220
220
  ` +
221
221
  kRenderFunc +
222
- `
223
- float frac2ndc(vec3 frac) {
224
- //https://stackoverflow.com/questions/7777913/how-to-render-depth-linearly-in-modern-opengl-with-gl-fragcoord-z-in-fragment-sh
225
- vec4 pos = vec4(frac.xyz, 1.0); //fraction
226
- vec4 dim = vec4(vec3(textureSize(volume, 0)), 1.0);
227
- pos = pos * dim;
228
- vec4 shim = vec4(-0.5, -0.5, -0.5, 0.0);
229
- pos += shim;
230
- vec4 mm = transpose(matRAS) * pos;
231
- float z_ndc = (mvpMtx * vec4(mm.xyz, 1.0)).z;
232
- return (z_ndc + 1.0) / 2.0;
233
-
234
- }
235
- void main() {
222
+ `void main() {
236
223
  if (fColor.x > 2.0) {
237
224
  fColor = vec4(1.0, 0.0, 0.0, 0.5);
238
225
  return;
@@ -1019,7 +1006,6 @@ precision highp float;
1019
1006
  uniform float opacity;
1020
1007
  out vec4 color;
1021
1008
  vec4 packFloatToVec4i(const float value) {
1022
- //this Papaya function uses BSD 3-clause license Copyright (c) 2012-2015, RII-UTHSCSA
1023
1009
  const vec4 bitSh = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);
1024
1010
  const vec4 bitMsk = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);
1025
1011
  vec4 res = fract(value * bitSh);
@@ -1236,16 +1222,6 @@ void main() {
1236
1222
  color = vec4(a + d + s, opacity);
1237
1223
  }`;
1238
1224
 
1239
- export var fragDepthPickingShader = `#version 300 es
1240
- precision highp int;
1241
- precision highp float;
1242
- uniform int id;
1243
- in vec3 vColor;
1244
- out vec4 color;
1245
- void main() {
1246
- color = vec4(vColor, float(id & 255) / 255.0);
1247
- }`;
1248
-
1249
1225
  export var fragVolumePickingShader =
1250
1226
  `#version 300 es
1251
1227
  #line 506
@@ -1257,14 +1233,17 @@ uniform vec3 texVox;
1257
1233
  uniform vec4 clipPlane;
1258
1234
  uniform highp sampler3D volume, overlay;
1259
1235
  uniform float overlays;
1260
- uniform int id;
1236
+ uniform mat4 matRAS;
1237
+ uniform mat4 mvpMtx;
1261
1238
  in vec3 vColor;
1262
1239
  out vec4 fColor;
1263
1240
  ` +
1264
1241
  kRenderFunc +
1265
1242
  `
1266
1243
  void main() {
1244
+ int id = 254;
1267
1245
  vec3 start = vColor;
1246
+ gl_FragDepth = 0.0;
1268
1247
  fColor = vec4(0.0, 0.0, 0.0, 0.0); //assume no hit: ID = 0
1269
1248
  float fid = float(id & 255)/ 255.0;
1270
1249
  vec3 backPosition = GetBackPosition(start);
@@ -1288,6 +1267,7 @@ void main() {
1288
1267
  float val = texture(volume, samplePos.xyz).a;
1289
1268
  if (val > 0.01) {
1290
1269
  fColor = vec4(samplePos.rgb, fid);
1270
+ gl_FragDepth = frac2ndc(samplePos.xyz);
1291
1271
  break;
1292
1272
  }
1293
1273
  samplePos += deltaDirFast; //advance ray position
@@ -1304,6 +1284,7 @@ void main() {
1304
1284
  float val = texture(overlay, samplePos.xyz).a;
1305
1285
  if (val > 0.01) {
1306
1286
  fColor = vec4(samplePos.rgb, fid);
1287
+ gl_FragDepth = frac2ndc(samplePos.xyz);
1307
1288
  return;
1308
1289
  }
1309
1290
  samplePos += deltaDirFast; //advance ray position
@@ -1311,3 +1292,33 @@ void main() {
1311
1292
  //if (fColor.a == 0.0) discard; //no hit in either background or overlays
1312
1293
  //you only get here if there is a hit with the background that is closer than any overlay
1313
1294
  }`;
1295
+
1296
+ export var vertOrientCubeShader = `#version 300 es
1297
+ // an attribute is an input (in) to a vertex shader.
1298
+ // It will receive data from a buffer
1299
+ layout(location=0) in vec3 a_position;
1300
+ layout(location=1) in vec3 a_color;
1301
+ // A matrix to transform the positions by
1302
+ uniform mat4 u_matrix;
1303
+ out vec3 vColor;
1304
+ // all shaders have a main function
1305
+ void main() {
1306
+ // Multiply the position by the matrix.
1307
+ vec4 pos = vec4(a_position, 1.0);
1308
+ gl_Position = u_matrix * vec4(pos);
1309
+ vColor = a_color;
1310
+ }
1311
+ `;
1312
+
1313
+ export var fragOrientCubeShader = `#version 300 es
1314
+ precision highp float;
1315
+
1316
+ uniform vec4 u_color;
1317
+ in vec3 vColor;
1318
+ // we need to declare an output for the fragment shader
1319
+ out vec4 outColor;
1320
+
1321
+ void main() {
1322
+ outColor = vec4(vColor, 1.0);
1323
+ }
1324
+ `;