x_ite 8.10.1 → 8.11.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.
Files changed (137) hide show
  1. package/Makefile +3 -0
  2. package/build/bin/version.pl +28 -20
  3. package/build/docs/glTF-samples.pl +151 -0
  4. package/build/docs/nodes.pl +1 -1
  5. package/build/src/nodes.pl +41 -0
  6. package/dist/assets/components/Annotation.js +13 -13
  7. package/dist/assets/components/Annotation.min.js +1 -1
  8. package/dist/assets/components/CADGeometry.js +13 -13
  9. package/dist/assets/components/CADGeometry.min.js +1 -1
  10. package/dist/assets/components/CubeMapTexturing.js +30 -26
  11. package/dist/assets/components/CubeMapTexturing.min.js +1 -1
  12. package/dist/assets/components/DIS.js +14 -14
  13. package/dist/assets/components/DIS.min.js +1 -1
  14. package/dist/assets/components/EventUtilities.js +9 -9
  15. package/dist/assets/components/EventUtilities.min.js +1 -1
  16. package/dist/assets/components/Geometry2D.js +19 -19
  17. package/dist/assets/components/Geometry2D.min.js +1 -1
  18. package/dist/assets/components/Geospatial.js +33 -33
  19. package/dist/assets/components/Geospatial.min.js +1 -1
  20. package/dist/assets/components/HAnim.js +394 -30
  21. package/dist/assets/components/HAnim.min.js +1 -1
  22. package/dist/assets/components/KeyDeviceSensor.js +8 -8
  23. package/dist/assets/components/KeyDeviceSensor.min.js +1 -1
  24. package/dist/assets/components/Layout.js +26 -26
  25. package/dist/assets/components/Layout.min.js +1 -1
  26. package/dist/assets/components/NURBS.js +24 -24
  27. package/dist/assets/components/NURBS.min.js +1 -1
  28. package/dist/assets/components/ParticleSystems.js +73 -74
  29. package/dist/assets/components/ParticleSystems.min.js +1 -1
  30. package/dist/assets/components/Picking.js +18 -18
  31. package/dist/assets/components/Picking.min.js +1 -1
  32. package/dist/assets/components/RigidBodyPhysics.js +18 -18
  33. package/dist/assets/components/RigidBodyPhysics.min.js +1 -1
  34. package/dist/assets/components/Scripting.js +37 -37
  35. package/dist/assets/components/Scripting.min.js +1 -1
  36. package/dist/assets/components/Text.js +55 -63
  37. package/dist/assets/components/Text.min.js +1 -1
  38. package/dist/assets/components/TextureProjector.js +14 -14
  39. package/dist/assets/components/TextureProjector.min.js +1 -1
  40. package/dist/assets/components/Texturing3D.js +35 -31
  41. package/dist/assets/components/Texturing3D.min.js +1 -1
  42. package/dist/assets/components/VolumeRendering.js +20 -20
  43. package/dist/assets/components/VolumeRendering.min.js +1 -1
  44. package/dist/assets/components/X_ITE.js +9 -9
  45. package/dist/assets/components/X_ITE.min.js +1 -1
  46. package/dist/x_ite.css +1 -1
  47. package/dist/x_ite.js +1456 -844
  48. package/dist/x_ite.min.js +1 -1
  49. package/dist/x_ite.zip +0 -0
  50. package/docs/_config.yml +2 -2
  51. package/docs/_posts/components/Core/MetadataBoolean.md +6 -4
  52. package/docs/_posts/components/Core/MetadataDouble.md +6 -4
  53. package/docs/_posts/components/Core/MetadataFloat.md +6 -4
  54. package/docs/_posts/components/Core/MetadataInteger.md +6 -4
  55. package/docs/_posts/components/Core/MetadataSet.md +6 -4
  56. package/docs/_posts/components/Core/MetadataString.md +6 -4
  57. package/docs/_posts/components/DIS/DISEntityTypeMapping.md +1 -1
  58. package/docs/_posts/components/HAnim/HAnimMotion.md +48 -48
  59. package/docs/_posts/components/RigidBodyPhysics/Contact.md +1 -1
  60. package/docs/_posts/getting-started.md +45 -35
  61. package/docs/_posts/reference/browser-services.md +6 -0
  62. package/docs/_tabs/playground.html +215 -15
  63. package/docs/assets/css/style.scss +35 -2
  64. package/docs/assets/js/example.js +95 -3
  65. package/docs/laboratory/gltf-sample-viewer.html +603 -235
  66. package/package.json +2 -2
  67. package/src/assets/shaders/Types.glsl.js +4 -0
  68. package/src/assets/shaders/webgl1/include/Hatch.glsl.js +2 -3
  69. package/src/assets/shaders/webgl2/Compose.fs.js +29 -0
  70. package/src/assets/shaders/webgl2/Compose.vs.js +14 -0
  71. package/src/assets/shaders/webgl2/include/Fragment.glsl.js +24 -2
  72. package/src/assets/shaders/webgl2/include/Hatch.glsl.js +2 -3
  73. package/src/assets/shaders/webgl2/include/Stipple.glsl.js +5 -3
  74. package/src/bookmarks.js +92 -5
  75. package/src/examples.js +1 -0
  76. package/src/standard/Math/Numbers/Quaternion.js +191 -13
  77. package/src/standard/Math/Numbers/Rotation4.js +23 -0
  78. package/src/standard/Time/{MicroTime.js → Time.js} +21 -28
  79. package/src/x_ite/Base/X3DChildObject.js +5 -4
  80. package/src/x_ite/Browser/Core/BrowserOptions.js +71 -60
  81. package/src/x_ite/Browser/Core/Context.js +2 -2
  82. package/src/x_ite/Browser/Core/X3DCoreContext.js +6 -0
  83. package/src/x_ite/Browser/DOMIntegration.js +0 -17
  84. package/src/x_ite/Browser/Navigation/ExamineViewer.js +5 -4
  85. package/src/x_ite/Browser/Navigation/X3DFlyViewer.js +7 -4
  86. package/src/x_ite/Browser/Rendering/X3DRenderingContext.js +20 -15
  87. package/src/x_ite/Browser/Shaders/Shaders.js +19 -15
  88. package/src/x_ite/Browser/Text/X3DTextContext.js +16 -16
  89. package/src/x_ite/Browser/Time/X3DTimeContext.js +3 -2
  90. package/src/x_ite/Browser/VERSION.js +1 -1
  91. package/src/x_ite/Browser/VolumeRendering/VolumeMaterial.js +2 -2
  92. package/src/x_ite/Browser/X3DBrowser.js +1 -2
  93. package/src/x_ite/Browser/X3DBrowserContext.js +0 -5
  94. package/src/x_ite/Components/Core/MetadataBoolean.js +8 -1
  95. package/src/x_ite/Components/Core/MetadataDouble.js +8 -1
  96. package/src/x_ite/Components/Core/MetadataFloat.js +8 -1
  97. package/src/x_ite/Components/Core/MetadataInteger.js +8 -1
  98. package/src/x_ite/Components/Core/MetadataSet.js +8 -1
  99. package/src/x_ite/Components/Core/MetadataString.js +8 -1
  100. package/src/x_ite/Components/Core/X3DPrototypeInstance.js +9 -6
  101. package/src/x_ite/Components/CubeMapTexturing/ImageCubeMapTexture.js +2 -1
  102. package/src/x_ite/Components/DIS/DISEntityTypeMapping.js +1 -1
  103. package/src/x_ite/Components/EnvironmentalEffects/X3DBackgroundNode.js +5 -1
  104. package/src/x_ite/Components/Grouping/X3DGroupingNode.js +2 -0
  105. package/src/x_ite/Components/HAnim/HAnimHumanoid.js +34 -2
  106. package/src/x_ite/Components/HAnim/HAnimMotion.js +331 -15
  107. package/src/x_ite/Components/Lighting/DirectionalLight.js +1 -3
  108. package/src/x_ite/Components/Lighting/PointLight.js +1 -3
  109. package/src/x_ite/Components/Lighting/SpotLight.js +1 -3
  110. package/src/x_ite/Components/Networking/X3DUrlObject.js +5 -4
  111. package/src/x_ite/Components/ParticleSystems/ParticleSystem.js +47 -51
  112. package/src/x_ite/Components/Rendering/X3DGeometryNode.js +4 -2
  113. package/src/x_ite/Components/RigidBodyPhysics/Contact.js +1 -1
  114. package/src/x_ite/Components/Shaders/X3DProgrammableShaderObject.js +1 -1
  115. package/src/x_ite/Components/Shape/FillProperties.js +4 -0
  116. package/src/x_ite/Components/Shape/LineProperties.js +4 -0
  117. package/src/x_ite/Components/Shape/PointProperties.js +4 -0
  118. package/src/x_ite/Components/Shape/X3DMaterialNode.js +44 -20
  119. package/src/x_ite/Components/Sound/AudioClip.js +2 -1
  120. package/src/x_ite/Components/Text/X3DFontStyleNode.js +13 -23
  121. package/src/x_ite/Components/Texturing/ImageTexture.js +2 -1
  122. package/src/x_ite/Components/Texturing/MovieTexture.js +2 -1
  123. package/src/x_ite/Components/Texturing3D/ImageTextureAtlas.js +2 -1
  124. package/src/x_ite/Components/Time/TimeSensor.js +25 -24
  125. package/src/x_ite/Components/Time/X3DTimeDependentNode.js +5 -4
  126. package/src/x_ite/Execution/BindableList.js +3 -3
  127. package/src/x_ite/Execution/X3DScene.js +2 -0
  128. package/src/x_ite/Parser/XMLParser.js +12 -2
  129. package/src/x_ite/Rendering/MultiSampleFrameBuffer.js +264 -26
  130. package/src/x_ite/Rendering/PointingBuffer.js +5 -7
  131. package/src/x_ite/Rendering/TextureBuffer.js +6 -14
  132. package/src/x_ite/Rendering/X3DRenderObject.js +28 -28
  133. package/src/x_ite/X3D.js +0 -1
  134. package/src/x_ite/X3DCanvasElement.js +2 -0
  135. package/src/x_ite.html +23 -24
  136. package/x_ite.min.html +23 -24
  137. /package/build/{bin → docs}/tags.pl +0 -0
@@ -45,21 +45,24 @@
45
45
  *
46
46
  ******************************************************************************/
47
47
 
48
- function MultiSampleFrameBuffer (browser, width, height, samples)
48
+ function MultiSampleFrameBuffer (browser, width, height, samples, oit)
49
49
  {
50
50
  const gl = browser .getContext ();
51
51
 
52
52
  if (gl .getVersion () === 1 || width === 0 || height === 0)
53
53
  return Fallback;
54
54
 
55
- this .browser = browser;
56
- this .width = width;
57
- this .height = height;
58
- this .samples = Math .min (samples, gl .getParameter (gl .MAX_SAMPLES));
55
+ this .context = gl;
56
+ this .width = width;
57
+ this .height = height;
58
+ this .samples = samples;
59
+ this .oit = oit;
60
+ this .lastBuffer = [ ];
59
61
 
60
62
  // Create frame buffer.
61
63
 
62
- this .lastBuffer = gl .getParameter (gl .FRAMEBUFFER_BINDING);
64
+ this .lastBuffer .push (gl .getParameter (gl .FRAMEBUFFER_BINDING));
65
+
63
66
  this .frameBuffer = gl .createFramebuffer ();
64
67
 
65
68
  gl .bindFramebuffer (gl .FRAMEBUFFER, this .frameBuffer);
@@ -69,7 +72,12 @@ function MultiSampleFrameBuffer (browser, width, height, samples)
69
72
  this .colorBuffer = gl .createRenderbuffer ();
70
73
 
71
74
  gl .bindRenderbuffer (gl .RENDERBUFFER, this .colorBuffer);
72
- gl .renderbufferStorageMultisample (gl .RENDERBUFFER, this .samples, gl .RGBA8, width, height);
75
+
76
+ if (samples)
77
+ gl .renderbufferStorageMultisample (gl .RENDERBUFFER, samples, gl .RGBA8, width, height);
78
+ else
79
+ gl .renderbufferStorage (gl .RENDERBUFFER, gl .RGBA8, width, height);
80
+
73
81
  gl .framebufferRenderbuffer (gl .FRAMEBUFFER, gl .COLOR_ATTACHMENT0, gl .RENDERBUFFER, this .colorBuffer);
74
82
 
75
83
  // Create depth buffer.
@@ -77,17 +85,168 @@ function MultiSampleFrameBuffer (browser, width, height, samples)
77
85
  this .depthBuffer = gl .createRenderbuffer ();
78
86
 
79
87
  gl .bindRenderbuffer (gl .RENDERBUFFER, this .depthBuffer);
80
- gl .renderbufferStorageMultisample (gl .RENDERBUFFER, this .samples, gl .DEPTH_COMPONENT24, width, height);
81
- gl .framebufferRenderbuffer (gl .FRAMEBUFFER, gl .DEPTH_ATTACHMENT, gl .RENDERBUFFER, this .depthBuffer);
82
88
 
83
- const status = gl .checkFramebufferStatus (gl .FRAMEBUFFER) === gl .FRAMEBUFFER_COMPLETE;
89
+ if (samples)
90
+ gl .renderbufferStorageMultisample (gl .RENDERBUFFER, samples, gl .DEPTH_COMPONENT24, width, height);
91
+ else
92
+ gl .renderbufferStorage (gl .RENDERBUFFER, gl .DEPTH_COMPONENT24, width, height);
93
+
94
+ gl .framebufferRenderbuffer (gl .FRAMEBUFFER, gl .DEPTH_ATTACHMENT, gl .RENDERBUFFER, this .depthBuffer);
95
+
96
+ const status1 = gl .checkFramebufferStatus (gl .FRAMEBUFFER) === gl .FRAMEBUFFER_COMPLETE;
97
+
98
+ gl .bindFramebuffer (gl .FRAMEBUFFER, this .lastBuffer .pop ());
99
+
100
+ // Always check that our frame buffer is ok.
101
+
102
+ if (!status1)
103
+ throw new Error ("Couldn't create frame buffer.");
104
+
105
+ if (!oit)
106
+ return;
107
+
108
+ // Create oit frame buffer.
109
+
110
+ this .lastBuffer .push (gl .getParameter (gl .FRAMEBUFFER_BINDING));
111
+
112
+ this .oitFrameBuffer = gl .createFramebuffer ();
113
+
114
+ gl .bindFramebuffer (gl .FRAMEBUFFER, this .oitFrameBuffer);
115
+
116
+ // Set draw buffers.
117
+
118
+ gl .drawBuffers ([
119
+ gl .COLOR_ATTACHMENT0, // gl_FragData [0]
120
+ gl .COLOR_ATTACHMENT1, // gl_FragData [1]
121
+ ]);
122
+
123
+ if (samples)
124
+ {
125
+ // Create accum and revealage buffer.
126
+
127
+ this .accumRevealageBuffer = gl .createRenderbuffer ();
128
+
129
+ gl .bindRenderbuffer (gl .RENDERBUFFER, this .accumRevealageBuffer);
130
+ gl .renderbufferStorageMultisample (gl .RENDERBUFFER, samples, gl .RGBA32F, width, height);
131
+ gl .framebufferRenderbuffer (gl .FRAMEBUFFER, gl .COLOR_ATTACHMENT0, gl .RENDERBUFFER, this .accumRevealageBuffer);
132
+
133
+ // Create alpha buffer.
134
+
135
+ this .alphaBuffer = gl .createRenderbuffer ();
136
+
137
+ gl .bindRenderbuffer (gl .RENDERBUFFER, this .alphaBuffer);
138
+ gl .renderbufferStorageMultisample (gl .RENDERBUFFER, samples, gl .RGBA32F, width, height);
139
+ gl .framebufferRenderbuffer (gl .FRAMEBUFFER, gl .COLOR_ATTACHMENT1, gl .RENDERBUFFER, this .alphaBuffer);
140
+
141
+ // Add depth buffer.
142
+
143
+ gl .framebufferRenderbuffer (gl .FRAMEBUFFER, gl .DEPTH_ATTACHMENT, gl .RENDERBUFFER, this .depthBuffer);
144
+
145
+ // Create accum texture buffer.
146
+
147
+ this .accumRevealageTextureBuffer = gl .createFramebuffer ();
148
+
149
+ gl .bindFramebuffer (gl .FRAMEBUFFER, this .accumRevealageTextureBuffer);
150
+
151
+ // Create accum texture.
152
+
153
+ this .accumRevealageTexture = gl .createTexture ();
154
+
155
+ gl .bindTexture (gl .TEXTURE_2D, this .accumRevealageTexture);
156
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_WRAP_S, gl .CLAMP_TO_EDGE);
157
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_WRAP_T, gl .CLAMP_TO_EDGE);
158
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_MIN_FILTER, gl .NEAREST);
159
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_MAG_FILTER, gl .NEAREST);
160
+
161
+ gl .texImage2D (gl .TEXTURE_2D, 0, gl .RGBA32F, width, height, 0, gl .RGBA, gl .FLOAT, null);
162
+ gl .framebufferTexture2D (gl .FRAMEBUFFER, gl .COLOR_ATTACHMENT0, gl .TEXTURE_2D, this .accumRevealageTexture, 0);
163
+
164
+ // Create alpha texture buffer.
165
+
166
+ this .alphaTextureBuffer = gl .createFramebuffer ();
167
+
168
+ gl .bindFramebuffer (gl .FRAMEBUFFER, this .alphaTextureBuffer);
169
+
170
+ // Create alpha texture.
171
+
172
+ this .alphaTexture = gl .createTexture ();
173
+
174
+ gl .bindTexture (gl .TEXTURE_2D, this .alphaTexture);
175
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_WRAP_S, gl .CLAMP_TO_EDGE);
176
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_WRAP_T, gl .CLAMP_TO_EDGE);
177
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_MIN_FILTER, gl .NEAREST);
178
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_MAG_FILTER, gl .NEAREST);
179
+
180
+ gl .texImage2D (gl .TEXTURE_2D, 0, gl .RGBA32F, width, height, 0, gl .RGBA, gl .FLOAT, null);
181
+ gl .framebufferTexture2D (gl .FRAMEBUFFER, gl .COLOR_ATTACHMENT0, gl .TEXTURE_2D, this .alphaTexture, 0);
182
+ }
183
+ else
184
+ {
185
+ // Create accum texture.
186
+
187
+ this .accumRevealageTexture = gl .createTexture ();
188
+
189
+ gl .bindTexture (gl .TEXTURE_2D, this .accumRevealageTexture);
190
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_WRAP_S, gl .CLAMP_TO_EDGE);
191
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_WRAP_T, gl .CLAMP_TO_EDGE);
192
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_MIN_FILTER, gl .NEAREST);
193
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_MAG_FILTER, gl .NEAREST);
84
194
 
85
- gl .bindFramebuffer (gl .FRAMEBUFFER, this .lastBuffer);
195
+ gl .texImage2D (gl .TEXTURE_2D, 0, gl .RGBA32F, width, height, 0, gl .RGBA, gl .FLOAT, null);
196
+ gl .framebufferTexture2D (gl .FRAMEBUFFER, gl .COLOR_ATTACHMENT0, gl .TEXTURE_2D, this .accumRevealageTexture, 0);
197
+
198
+ // Create alpha texture.
199
+
200
+ this .alphaTexture = gl .createTexture ();
201
+
202
+ gl .bindTexture (gl .TEXTURE_2D, this .alphaTexture);
203
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_WRAP_S, gl .CLAMP_TO_EDGE);
204
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_WRAP_T, gl .CLAMP_TO_EDGE);
205
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_MIN_FILTER, gl .NEAREST);
206
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_MAG_FILTER, gl .NEAREST);
207
+
208
+ gl .texImage2D (gl .TEXTURE_2D, 0, gl .RGBA32F, width, height, 0, gl .RGBA, gl .FLOAT, null);
209
+ gl .framebufferTexture2D (gl .FRAMEBUFFER, gl .COLOR_ATTACHMENT1, gl .TEXTURE_2D, this .alphaTexture, 0);
210
+
211
+ // Add depth buffer.
212
+
213
+ gl .framebufferRenderbuffer (gl .FRAMEBUFFER, gl .DEPTH_ATTACHMENT, gl .RENDERBUFFER, this .depthBuffer);
214
+ }
215
+
216
+ const status2 = gl .checkFramebufferStatus (gl .FRAMEBUFFER) === gl .FRAMEBUFFER_COMPLETE;
217
+
218
+ gl .bindTexture (gl .TEXTURE_2D, null);
219
+ gl .bindFramebuffer (gl .FRAMEBUFFER, this .lastBuffer .pop ());
86
220
 
87
221
  // Always check that our frame buffer is ok.
88
222
 
89
- if (!status)
223
+ if (!status2)
90
224
  throw new Error ("Couldn't create frame buffer.");
225
+
226
+ // Get compose shader and texture units.
227
+
228
+ this .shaderNode = browser .getComposeShader ();
229
+ this .program = this .shaderNode .getProgram ();
230
+
231
+ gl .useProgram (this .program);
232
+
233
+ const
234
+ accumRevealageTextureUnit = gl .getUniformLocation (this .program, "x3d_AccumRevealageTexture"),
235
+ alphaTextureUnit = gl .getUniformLocation (this .program, "x3d_AlphaTexture");
236
+
237
+ gl .uniform1i (accumRevealageTextureUnit, 0);
238
+ gl .uniform1i (alphaTextureUnit, 1);
239
+
240
+ // Quad for compose pass.
241
+
242
+ this .quadArray = gl .createVertexArray ();
243
+ this .quadBuffer = gl .createBuffer ();
244
+
245
+ gl .bindVertexArray (this .quadArray);
246
+ gl .bindBuffer (gl .ARRAY_BUFFER, this .quadBuffer);
247
+ gl .bufferData (gl .ARRAY_BUFFER, new Float32Array ([-1, 1, -1, -1, 1, -1, -1, 1, 1, -1, 1, 1]), gl .STATIC_DRAW);
248
+ gl .vertexAttribPointer (0, 2, gl .FLOAT, false, 0, 0);
249
+ gl .enableVertexAttribArray (null);
91
250
  }
92
251
 
93
252
  Object .assign (MultiSampleFrameBuffer .prototype,
@@ -104,42 +263,118 @@ Object .assign (MultiSampleFrameBuffer .prototype,
104
263
  {
105
264
  return this .samples;
106
265
  },
266
+ getOrderIndependentTransparency ()
267
+ {
268
+ return this .oit;
269
+ },
107
270
  bind ()
108
271
  {
109
- const gl = this .browser .getContext ();
272
+ const { context: gl, lastBuffer, frameBuffer } = this;
110
273
 
111
- this .lastBuffer = gl .getParameter (gl .FRAMEBUFFER_BINDING);
274
+ lastBuffer .push (gl .getParameter (gl .FRAMEBUFFER_BINDING));
112
275
 
113
- gl .bindFramebuffer (gl .FRAMEBUFFER, this .frameBuffer);
276
+ gl .bindFramebuffer (gl .FRAMEBUFFER, frameBuffer);
277
+
278
+ gl .clearColor (0, 0, 0, 0);
279
+ gl .clear (gl .COLOR_BUFFER_BIT);
114
280
  },
115
- unbind ()
281
+ bindForOrderIndependentTransparency ()
116
282
  {
117
- const gl = this .browser .getContext ();
283
+ const { context: gl, lastBuffer, oitFrameBuffer } = this;
284
+
285
+ lastBuffer .push (gl .getParameter (gl .FRAMEBUFFER_BINDING));
118
286
 
119
- gl .bindFramebuffer (gl .FRAMEBUFFER, this .lastBuffer);
287
+ gl .bindFramebuffer (gl .FRAMEBUFFER, oitFrameBuffer);
288
+
289
+ gl .clearColor (0, 0, 0, 1);
290
+ gl .clear (gl .COLOR_BUFFER_BIT);
291
+ gl .blendFuncSeparate (gl .ONE, gl .ONE, gl .ZERO, gl .ONE_MINUS_SRC_ALPHA);
120
292
  },
121
293
  blit ()
122
294
  {
123
- const gl = this .browser .getContext ();
295
+ const { context: gl, width, height, samples } = this;
124
296
 
125
297
  // Reset viewport before blit, otherwise only last layer size is used.
126
- gl .viewport (0, 0, this .width, this .height);
127
- gl .scissor (0, 0, this .width, this .height);
298
+ gl .viewport (0, 0, width, height);
299
+ gl .scissor (0, 0, width, height);
128
300
 
129
301
  gl .bindFramebuffer (gl .READ_FRAMEBUFFER, this .frameBuffer);
130
302
  gl .bindFramebuffer (gl .DRAW_FRAMEBUFFER, null);
131
303
 
132
- gl .blitFramebuffer (0, 0, this .width, this .height,
133
- 0, 0, this .width, this .height,
134
- gl .COLOR_BUFFER_BIT, gl .LINEAR);
304
+ gl .blitFramebuffer (0, 0, width, height,
305
+ 0, 0, width, height,
306
+ gl .COLOR_BUFFER_BIT, samples ? gl .LINEAR : gl .NEAREST);
307
+ },
308
+ compose ()
309
+ {
310
+ const { context: gl, width, height, samples, program } = this;
311
+
312
+ // TODO: Combining lights and lights with shadows, can cause feedback loop of texture.
313
+ // TODO: VolumeRendering shader is not made for OIT.
314
+
315
+ // Reset viewport before blit, otherwise only last layer size is used.
316
+ gl .viewport (0, 0, width, height);
317
+ gl .scissor (0, 0, width, height);
318
+
319
+ if (samples)
320
+ {
321
+ gl .bindFramebuffer (gl .READ_FRAMEBUFFER, this .oitFrameBuffer);
322
+
323
+ gl .readBuffer (gl .COLOR_ATTACHMENT0);
324
+ gl .bindFramebuffer (gl .DRAW_FRAMEBUFFER, this .accumRevealageTextureBuffer);
325
+
326
+ gl .blitFramebuffer (0, 0, width, height,
327
+ 0, 0, width, height,
328
+ gl .COLOR_BUFFER_BIT, gl .LINEAR);
329
+
330
+ gl .readBuffer (gl .COLOR_ATTACHMENT1);
331
+ gl .bindFramebuffer (gl .DRAW_FRAMEBUFFER, this .alphaTextureBuffer);
332
+
333
+ gl .blitFramebuffer (0, 0, width, height,
334
+ 0, 0, width, height,
335
+ gl .COLOR_BUFFER_BIT, gl .LINEAR);
336
+ }
337
+
338
+ gl .useProgram (program);
339
+ gl .activeTexture (gl .TEXTURE0 + 0);
340
+ gl .bindTexture (gl .TEXTURE_2D, this .accumRevealageTexture);
341
+ gl .activeTexture (gl .TEXTURE0 + 1);
342
+ gl .bindTexture (gl .TEXTURE_2D, this .alphaTexture);
343
+
344
+ gl .bindFramebuffer (gl .FRAMEBUFFER, this .frameBuffer);
345
+ gl .disable (gl .DEPTH_TEST);
346
+ gl .enable (gl .BLEND);
347
+ gl .blendFunc (gl .ONE, gl .ONE_MINUS_SRC_ALPHA);
348
+ gl .enable (gl .CULL_FACE);
349
+ gl .frontFace (gl .CCW);
350
+ gl .bindVertexArray (this .quadArray);
351
+ gl .drawArrays (gl .TRIANGLES, 0, 6);
352
+ gl .disable (gl .BLEND);
353
+ gl .enable (gl .DEPTH_TEST);
354
+ },
355
+ unbind ()
356
+ {
357
+ const { context: gl, lastBuffer } = this;
358
+
359
+ gl .bindFramebuffer (gl .FRAMEBUFFER, lastBuffer .pop ());
135
360
  },
136
361
  dispose ()
137
362
  {
138
- const gl = this .browser .getContext ();
363
+ const gl = this .context;
139
364
 
140
365
  gl .deleteFramebuffer (this .frameBuffer);
141
366
  gl .deleteRenderbuffer (this .colorBuffer);
142
367
  gl .deleteRenderbuffer (this .depthBuffer);
368
+
369
+ gl .deleteFramebuffer (this .oitFrameBuffer);
370
+ gl .deleteFramebuffer (this .accumRevealageTextureBuffer);
371
+ gl .deleteFramebuffer (this .alphaTextureBuffer);
372
+ gl .deleteRenderbuffer (this .accumRevealageBuffer);
373
+ gl .deleteRenderbuffer (this .alphaBuffer);
374
+ gl .deleteTexture (this .accumRevealageTexture);
375
+ gl .deleteTexture (this .alphaTexture)
376
+ gl .deleteVertexArray (this .quadArray);
377
+ gl .deleteBuffer (this .quadBuffer);
143
378
  },
144
379
  });
145
380
 
@@ -147,9 +382,12 @@ const Fallback = {
147
382
  getWidth: Function .prototype,
148
383
  getHeight: Function .prototype,
149
384
  getSamples: Function .prototype,
385
+ getOrderIndependentTransparency: Function .prototype,
150
386
  bind: Function .prototype,
151
- unbind: Function .prototype,
387
+ clear: Function .prototype,
152
388
  blit: Function .prototype,
389
+ compose: Function .prototype,
390
+ unbind: Function .prototype,
153
391
  dispose: Function .prototype,
154
392
  };
155
393
 
@@ -49,7 +49,7 @@ function PointingBuffer (browser)
49
49
  {
50
50
  const gl = browser .getContext ();
51
51
 
52
- this .browser = browser;
52
+ this .context = gl;
53
53
  this .array = new Float32Array (4);
54
54
 
55
55
  // Create frame buffer.
@@ -124,7 +124,7 @@ Object .assign (PointingBuffer .prototype,
124
124
  {
125
125
  bind ()
126
126
  {
127
- const gl = this .browser .getContext ();
127
+ const gl = this .context;
128
128
 
129
129
  this .lastBuffer = gl .getParameter (gl .FRAMEBUFFER_BINDING);
130
130
 
@@ -134,15 +134,13 @@ Object .assign (PointingBuffer .prototype,
134
134
  },
135
135
  unbind ()
136
136
  {
137
- const gl = this .browser .getContext ();
137
+ const gl = this .context;
138
138
 
139
139
  gl .bindFramebuffer (gl .FRAMEBUFFER, this .lastBuffer);
140
140
  },
141
141
  getHit (hit)
142
142
  {
143
- const
144
- gl = this .browser .getContext (),
145
- array = this .array;
143
+ const { context: gl, array } = this;
146
144
 
147
145
  // Id, point
148
146
 
@@ -173,7 +171,7 @@ Object .assign (PointingBuffer .prototype,
173
171
  },
174
172
  dispose ()
175
173
  {
176
- const gl = this .browser .getContext ();
174
+ const gl = this .context;
177
175
 
178
176
  gl .deleteFramebuffer (this .frameBuffer);
179
177
 
@@ -53,7 +53,7 @@ function TextureBuffer (browser, width, height, float = false)
53
53
  {
54
54
  const gl = browser .getContext ();
55
55
 
56
- this .browser = browser;
56
+ this .context = gl;
57
57
  this .width = width;
58
58
  this .height = height;
59
59
 
@@ -152,11 +152,7 @@ Object .assign (TextureBuffer .prototype,
152
152
  },
153
153
  readPixels ()
154
154
  {
155
- const
156
- gl = this .browser .getContext (),
157
- array = this .array,
158
- width = this .width,
159
- height = this .height;
155
+ const { context: gl, array, width, height } = this;
160
156
 
161
157
  gl .readPixels (0, 0, width, height, gl .RGBA, gl .UNSIGNED_BYTE, array);
162
158
 
@@ -170,11 +166,7 @@ Object .assign (TextureBuffer .prototype,
170
166
 
171
167
  return function (projectionMatrix, viewport)
172
168
  {
173
- const
174
- gl = this .browser .getContext (),
175
- array = this .array,
176
- width = this .width,
177
- height = this .height;
169
+ const { context: gl, array, width, height } = this;
178
170
 
179
171
  gl .readPixels (0, 0, width, height, gl .RGBA, gl .FLOAT, array);
180
172
 
@@ -207,7 +199,7 @@ Object .assign (TextureBuffer .prototype,
207
199
  })(),
208
200
  bind ()
209
201
  {
210
- const gl = this .browser .getContext ();
202
+ const gl = this .context;
211
203
 
212
204
  this .lastBuffer = gl .getParameter (gl .FRAMEBUFFER_BINDING);
213
205
 
@@ -215,13 +207,13 @@ Object .assign (TextureBuffer .prototype,
215
207
  },
216
208
  unbind ()
217
209
  {
218
- const gl = this .browser .getContext ();
210
+ const gl = this .context;
219
211
 
220
212
  gl .bindFramebuffer (gl .FRAMEBUFFER, this .lastBuffer);
221
213
  },
222
214
  delete ()
223
215
  {
224
- const gl = this .browser .getContext ();
216
+ const gl = this .context;
225
217
 
226
218
  gl .deleteFramebuffer (this .frameBuffer);
227
219
  gl .deleteTexture (this .colorTexture);
@@ -58,11 +58,14 @@ import Rotation4 from "../../standard/Math/Numbers/Rotation4.js";
58
58
  import Matrix4 from "../../standard/Math/Numbers/Matrix4.js";
59
59
  import MatrixStack from "../../standard/Math/Utility/MatrixStack.js";
60
60
  import StopWatch from "../../standard/Time/StopWatch.js";
61
+ import Time from "../../standard/Time/Time.js";
61
62
 
62
63
  const DEPTH_BUFFER_SIZE = 16;
63
64
 
64
65
  function X3DRenderObject (executionContext)
65
66
  {
67
+ const browser = executionContext .getBrowser ();
68
+
66
69
  this .viewVolumes = [ ];
67
70
  this .cameraSpaceMatrix = new MatrixStack (Matrix4);
68
71
  this .viewMatrix = new MatrixStack (Matrix4);
@@ -99,17 +102,7 @@ function X3DRenderObject (executionContext)
99
102
  this .transparentShapes = [ ];
100
103
  this .transparencySorter = new MergeSort (this .transparentShapes, (a, b) => a .distance < b .distance);
101
104
  this .speed = 0;
102
-
103
- try
104
- {
105
- this .depthBuffer = new TextureBuffer (executionContext .getBrowser (), DEPTH_BUFFER_SIZE, DEPTH_BUFFER_SIZE, true);
106
- }
107
- catch (error)
108
- {
109
- console .error (error);
110
-
111
- this .getDepth = function () { return 0; };
112
- }
105
+ this .depthBuffer = new TextureBuffer (browser, DEPTH_BUFFER_SIZE, DEPTH_BUFFER_SIZE, true);
113
106
  }
114
107
 
115
108
  Object .assign (X3DRenderObject .prototype,
@@ -160,6 +153,10 @@ Object .assign (X3DRenderObject .prototype,
160
153
  {
161
154
  return this .cameraSpaceMatrixArray;
162
155
  },
156
+ getLogarithmicDepthBuffer ()
157
+ {
158
+ return this .logarithmicDepthBuffer;
159
+ },
163
160
  getHitRay ()
164
161
  {
165
162
  return this .hitRay;
@@ -711,9 +708,6 @@ Object .assign (X3DRenderObject .prototype,
711
708
 
712
709
  // Render all objects
713
710
 
714
- gl .depthMask (true);
715
- gl .enable (gl .DEPTH_TEST);
716
- gl .disable (gl .BLEND);
717
711
  gl .disable (gl .CULL_FACE);
718
712
 
719
713
  for (let s = 0; s < numShapes; ++ s)
@@ -950,9 +944,6 @@ Object .assign (X3DRenderObject .prototype,
950
944
 
951
945
  // Render all objects
952
946
 
953
- gl .depthMask (true);
954
- gl .enable (gl .DEPTH_TEST);
955
- gl .disable (gl .BLEND);
956
947
  gl .disable (gl .CULL_FACE);
957
948
 
958
949
  for (let s = 0; s < numShapes; ++ s)
@@ -997,10 +988,14 @@ Object .assign (X3DRenderObject .prototype,
997
988
  shadows = globalShadows .at (-1),
998
989
  headlight = this .getNavigationInfo () ._headlight .getValue (),
999
990
  numGlobalLights = globalObjects .reduce ((n, c) => n + !!c .lightNode, 0),
1000
- numGlobalTextureProjectors = globalObjects .reduce ((n, c) => n + !!c .textureProjectorNode, 0);
991
+ numGlobalTextureProjectors = globalObjects .reduce ((n, c) => n + !!c .textureProjectorNode, 0),
992
+ oit = browser .getFrameBuffer () .getOrderIndependentTransparency ();
993
+
1001
994
 
995
+ this .renderTime = Time .now ();
1002
996
 
1003
- this .renderTime = Date .now ();
997
+ this .logarithmicDepthBuffer = browser .getBrowserOption ("LogarithmicDepthBuffer")
998
+ || this .getViewpoint () .getLogarithmicDepthBuffer ();
1004
999
 
1005
1000
 
1006
1001
  // PREPARATIONS
@@ -1048,17 +1043,14 @@ Object .assign (X3DRenderObject .prototype,
1048
1043
  // Draw background.
1049
1044
 
1050
1045
  gl .clear (gl .DEPTH_BUFFER_BIT);
1046
+ gl .blendFuncSeparate (gl .SRC_ALPHA, gl .ONE_MINUS_SRC_ALPHA, gl .ONE, gl .ONE_MINUS_SRC_ALPHA);
1051
1047
 
1052
1048
  this .getBackground () .display (gl, this, viewport);
1053
1049
 
1054
- // Sorted blend
1050
+ // Sorted blend or order independent transparency
1055
1051
 
1056
1052
  // Render opaque objects first
1057
1053
 
1058
- gl .depthMask (true);
1059
- gl .enable (gl .DEPTH_TEST);
1060
- gl .disable (gl .BLEND);
1061
-
1062
1054
  const opaqueShapes = this .opaqueShapes;
1063
1055
 
1064
1056
  for (let i = 0, length = this .numOpaqueShapes; i < length; ++ i)
@@ -1077,12 +1069,15 @@ Object .assign (X3DRenderObject .prototype,
1077
1069
 
1078
1070
  // Render transparent objects
1079
1071
 
1080
- gl .depthMask (false);
1081
- gl .enable (gl .BLEND);
1082
-
1083
1072
  const transparentShapes = this .transparentShapes;
1084
1073
 
1085
- this .transparencySorter .sort (0, this .numTransparentShapes);
1074
+ if (oit)
1075
+ browser .getFrameBuffer () .bindForOrderIndependentTransparency ();
1076
+ else
1077
+ this .transparencySorter .sort (0, this .numTransparentShapes);
1078
+
1079
+ gl .depthMask (false);
1080
+ gl .enable (gl .BLEND);
1086
1081
 
1087
1082
  for (let i = 0, length = this .numTransparentShapes; i < length; ++ i)
1088
1083
  {
@@ -1101,6 +1096,11 @@ Object .assign (X3DRenderObject .prototype,
1101
1096
  gl .depthMask (true);
1102
1097
  gl .disable (gl .BLEND);
1103
1098
 
1099
+ if (oit)
1100
+ {
1101
+ browser .getFrameBuffer () .compose ();
1102
+ browser .getFrameBuffer () .unbind ();
1103
+ }
1104
1104
 
1105
1105
  // POST DRAW
1106
1106
 
package/src/x_ite/X3D.js CHANGED
@@ -76,7 +76,6 @@ import RouteArray from "./Routing/RouteArray.js";
76
76
  import X3DRoute from "./Routing/X3DRoute.js";
77
77
  import X3DConstants from "./Base/X3DConstants.js";
78
78
  import Legacy from "./Browser/Legacy.js";
79
- import MicroTime from "../standard/Time/MicroTime.js";
80
79
  import jQuery from "../lib/jquery.js";
81
80
  import libtess from "../lib/libtess.js";
82
81
 
@@ -88,6 +88,8 @@ class X3DCanvasElement extends HTMLElement
88
88
  "notifications",
89
89
  "oninitialized",
90
90
  "onshutdown",
91
+ "orderIndependentTransparency",
92
+ "orderindependenttransparency",
91
93
  "splashScreen",
92
94
  "splashscreen",
93
95
  "src",