super-three 0.162.0 → 0.163.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 (122) hide show
  1. package/build/three.cjs +407 -1014
  2. package/build/three.module.js +406 -1013
  3. package/build/three.module.min.js +1 -1
  4. package/examples/jsm/controls/TransformControls.js +3 -3
  5. package/examples/jsm/exporters/GLTFExporter.js +21 -4
  6. package/examples/jsm/exporters/USDZExporter.js +15 -0
  7. package/examples/jsm/geometries/TextGeometry.js +10 -2
  8. package/examples/jsm/interactive/HTMLMesh.js +7 -9
  9. package/examples/jsm/libs/fflate.module.js +694 -496
  10. package/examples/jsm/lines/LineMaterial.js +0 -2
  11. package/examples/jsm/loaders/3MFLoader.js +2 -0
  12. package/examples/jsm/loaders/EXRLoader.js +89 -19
  13. package/examples/jsm/loaders/FBXLoader.js +1 -1
  14. package/examples/jsm/loaders/GLTFLoader.js +6 -0
  15. package/examples/jsm/loaders/KTX2Loader.js +2 -6
  16. package/examples/jsm/loaders/LUT3dlLoader.js +0 -15
  17. package/examples/jsm/loaders/LUTCubeLoader.js +0 -14
  18. package/examples/jsm/loaders/LUTImageLoader.js +0 -14
  19. package/examples/jsm/loaders/RGBMLoader.js +16 -0
  20. package/examples/jsm/misc/GPUComputationRenderer.js +0 -6
  21. package/examples/jsm/nodes/Nodes.js +6 -1
  22. package/examples/jsm/nodes/accessors/BatchNode.js +78 -0
  23. package/examples/jsm/nodes/accessors/InstanceNode.js +25 -2
  24. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +1 -1
  25. package/examples/jsm/nodes/accessors/MorphNode.js +13 -3
  26. package/examples/jsm/nodes/accessors/NormalNode.js +12 -2
  27. package/examples/jsm/nodes/accessors/ReferenceNode.js +1 -1
  28. package/examples/jsm/nodes/accessors/RendererReferenceNode.js +29 -0
  29. package/examples/jsm/nodes/accessors/TextureNode.js +30 -7
  30. package/examples/jsm/nodes/core/Node.js +55 -4
  31. package/examples/jsm/nodes/core/NodeBuilder.js +21 -16
  32. package/examples/jsm/nodes/core/NodeFrame.js +10 -10
  33. package/examples/jsm/nodes/core/NodeUtils.js +2 -2
  34. package/examples/jsm/nodes/core/UniformNode.js +20 -0
  35. package/examples/jsm/nodes/display/PassNode.js +17 -1
  36. package/examples/jsm/nodes/display/ToneMappingNode.js +8 -4
  37. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +6 -0
  38. package/examples/jsm/nodes/fog/FogExp2Node.js +4 -5
  39. package/examples/jsm/nodes/fog/FogNode.js +13 -3
  40. package/examples/jsm/nodes/fog/FogRangeNode.js +4 -3
  41. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +1 -1
  42. package/examples/jsm/nodes/lighting/EnvironmentNode.js +12 -69
  43. package/examples/jsm/nodes/materials/NodeMaterial.js +33 -11
  44. package/examples/jsm/nodes/pmrem/PMREMNode.js +193 -0
  45. package/examples/jsm/nodes/pmrem/PMREMUtils.js +288 -0
  46. package/examples/jsm/nodes/shadernode/ShaderNode.js +1 -1
  47. package/examples/jsm/nodes/utils/EquirectUVNode.js +1 -1
  48. package/examples/jsm/objects/QuadMesh.js +7 -23
  49. package/examples/jsm/physics/RapierPhysics.js +4 -4
  50. package/examples/jsm/postprocessing/GlitchPass.js +0 -3
  51. package/examples/jsm/postprocessing/LUTPass.js +5 -71
  52. package/examples/jsm/postprocessing/SAOPass.js +0 -1
  53. package/examples/jsm/postprocessing/SSAOPass.js +0 -3
  54. package/examples/jsm/renderers/common/Animation.js +3 -0
  55. package/examples/jsm/renderers/common/Background.js +5 -5
  56. package/examples/jsm/renderers/common/Info.js +11 -19
  57. package/examples/jsm/renderers/common/PostProcessing.js +12 -4
  58. package/examples/jsm/renderers/common/RenderContext.js +1 -1
  59. package/examples/jsm/renderers/common/RenderObject.js +4 -4
  60. package/examples/jsm/renderers/common/RenderObjects.js +1 -1
  61. package/examples/jsm/renderers/common/Renderer.js +25 -8
  62. package/examples/jsm/renderers/common/extras/PMREMGenerator.js +777 -0
  63. package/examples/jsm/renderers/common/nodes/Nodes.js +5 -18
  64. package/examples/jsm/renderers/webgl/WebGLBackend.js +148 -24
  65. package/examples/jsm/renderers/webgl/WebGLBufferRenderer.js +141 -0
  66. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +3 -3
  67. package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +1 -1
  68. package/examples/jsm/renderers/webgl/utils/WebGLConstants.js +1 -0
  69. package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +43 -0
  70. package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +3 -2
  71. package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +0 -2
  72. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +0 -2
  73. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +54 -25
  74. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +5 -3
  75. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +25 -0
  76. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +18 -4
  77. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +92 -18
  78. package/examples/jsm/utils/GPUStatsPanel.js +10 -45
  79. package/examples/jsm/utils/TextureUtils.js +1 -1
  80. package/package.json +1 -1
  81. package/src/Three.js +0 -1
  82. package/src/animation/AnimationClip.js +1 -1
  83. package/src/constants.js +3 -3
  84. package/src/core/Object3D.js +10 -7
  85. package/src/extras/PMREMGenerator.js +9 -0
  86. package/src/loaders/ObjectLoader.js +2 -0
  87. package/src/materials/ShaderMaterial.js +0 -4
  88. package/src/math/Spherical.js +4 -5
  89. package/src/objects/BatchedMesh.js +4 -3
  90. package/src/objects/InstancedMesh.js +10 -0
  91. package/src/renderers/WebGLRenderer.js +55 -114
  92. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +2 -2
  93. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
  94. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +2 -10
  95. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +2 -16
  96. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +32 -22
  97. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +1 -1
  98. package/src/renderers/shaders/ShaderLib.js +1 -1
  99. package/src/renderers/shaders/UniformsUtils.js +10 -1
  100. package/src/renderers/webgl/WebGLAttributes.js +6 -33
  101. package/src/renderers/webgl/WebGLBindingStates.js +14 -51
  102. package/src/renderers/webgl/WebGLBufferRenderer.js +3 -25
  103. package/src/renderers/webgl/WebGLCapabilities.js +2 -12
  104. package/src/renderers/webgl/WebGLCubeUVMaps.js +10 -6
  105. package/src/renderers/webgl/WebGLExtensions.js +4 -19
  106. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +3 -25
  107. package/src/renderers/webgl/WebGLLights.js +6 -32
  108. package/src/renderers/webgl/WebGLMaterials.js +2 -3
  109. package/src/renderers/webgl/WebGLMorphtargets.js +79 -217
  110. package/src/renderers/webgl/WebGLProgram.js +18 -47
  111. package/src/renderers/webgl/WebGLPrograms.js +20 -32
  112. package/src/renderers/webgl/WebGLRenderStates.js +8 -6
  113. package/src/renderers/webgl/WebGLState.js +15 -59
  114. package/src/renderers/webgl/WebGLTextures.js +75 -237
  115. package/src/renderers/webgl/WebGLUniformsGroups.js +1 -1
  116. package/src/renderers/webgl/WebGLUtils.js +6 -57
  117. package/src/renderers/webxr/WebXRDepthSensing.js +2 -3
  118. package/src/renderers/webxr/WebXRManager.js +2 -2
  119. package/src/scenes/Scene.js +7 -1
  120. package/src/textures/Texture.js +11 -1
  121. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +0 -37
  122. package/src/renderers/WebGL1Renderer.js +0 -7
@@ -2,7 +2,7 @@ import DataMap from '../DataMap.js';
2
2
  import ChainMap from '../ChainMap.js';
3
3
  import NodeBuilderState from './NodeBuilderState.js';
4
4
  import { NoToneMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping } from 'three';
5
- import { NodeFrame, objectGroup, renderGroup, frameGroup, cubeTexture, texture, rangeFog, densityFog, reference, toneMapping, equirectUV, viewportBottomLeft, normalWorld } from '../../../nodes/Nodes.js';
5
+ import { NodeFrame, objectGroup, renderGroup, frameGroup, cubeTexture, texture, rangeFog, densityFog, reference, toneMapping, viewportBottomLeft, normalWorld, pmremTexture } from '../../../nodes/Nodes.js';
6
6
 
7
7
  class Nodes extends DataMap {
8
8
 
@@ -275,7 +275,7 @@ class Nodes extends DataMap {
275
275
 
276
276
  if ( rendererData.toneMapping !== rendererToneMapping ) {
277
277
 
278
- const rendererToneMappingNode = rendererData.rendererToneMappingNode || toneMapping( rendererToneMapping, reference( 'toneMappingExposure', 'float', renderer ) );
278
+ const rendererToneMappingNode = rendererData.rendererToneMappingNode || toneMapping( rendererToneMapping );
279
279
  rendererToneMappingNode.toneMapping = rendererToneMapping;
280
280
 
281
281
  rendererData.rendererToneMappingNode = rendererToneMappingNode;
@@ -305,26 +305,13 @@ class Nodes extends DataMap {
305
305
 
306
306
  let backgroundNode = null;
307
307
 
308
- if ( background.isCubeTexture === true ) {
308
+ if ( background.isCubeTexture === true || ( background.mapping === EquirectangularReflectionMapping || background.mapping === EquirectangularRefractionMapping ) ) {
309
309
 
310
- backgroundNode = cubeTexture( background, normalWorld );
310
+ backgroundNode = pmremTexture( background, normalWorld );
311
311
 
312
312
  } else if ( background.isTexture === true ) {
313
313
 
314
- let nodeUV = null;
315
-
316
- if ( background.mapping === EquirectangularReflectionMapping || background.mapping === EquirectangularRefractionMapping ) {
317
-
318
- nodeUV = equirectUV();
319
- background.flipY = false;
320
-
321
- } else {
322
-
323
- nodeUV = viewportBottomLeft;
324
-
325
- }
326
-
327
- backgroundNode = texture( background, nodeUV ).setUpdateMatrix( true );
314
+ backgroundNode = texture( background, viewportBottomLeft ).setUpdateMatrix( true );
328
315
 
329
316
  } else if ( background.isColor !== true ) {
330
317
 
@@ -10,6 +10,7 @@ import WebGLTextureUtils from './utils/WebGLTextureUtils.js';
10
10
  import WebGLExtensions from './utils/WebGLExtensions.js';
11
11
  import WebGLCapabilities from './utils/WebGLCapabilities.js';
12
12
  import { GLFeatureName } from './utils/WebGLConstants.js';
13
+ import { WebGLBufferRenderer } from './WebGLBufferRenderer.js';
13
14
 
14
15
  //
15
16
 
@@ -39,14 +40,18 @@ class WebGLBackend extends Backend {
39
40
  this.capabilities = new WebGLCapabilities( this );
40
41
  this.attributeUtils = new WebGLAttributeUtils( this );
41
42
  this.textureUtils = new WebGLTextureUtils( this );
43
+ this.bufferRenderer = new WebGLBufferRenderer( this );
44
+
42
45
  this.state = new WebGLState( this );
43
46
  this.utils = new WebGLUtils( this );
44
47
 
45
48
  this.vaoCache = {};
46
49
  this.transformFeedbackCache = {};
47
50
  this.discard = false;
51
+ this.trackTimestamp = ( parameters.trackTimestamp === true );
48
52
 
49
53
  this.extensions.get( 'EXT_color_buffer_float' );
54
+ this.disjoint = this.extensions.get( 'EXT_disjoint_timer_query_webgl2' );
50
55
  this.parallel = this.extensions.get( 'KHR_parallel_shader_compile' );
51
56
  this._currentContext = null;
52
57
 
@@ -64,6 +69,96 @@ class WebGLBackend extends Backend {
64
69
 
65
70
  }
66
71
 
72
+
73
+ initTimestampQuery( renderContext ) {
74
+
75
+ if ( ! this.disjoint || ! this.trackTimestamp ) return;
76
+
77
+ const renderContextData = this.get( renderContext );
78
+
79
+ if ( this.queryRunning ) {
80
+
81
+ if ( ! renderContextData.queryQueue ) renderContextData.queryQueue = [];
82
+ renderContextData.queryQueue.push( renderContext );
83
+ return;
84
+
85
+ }
86
+
87
+ if ( renderContextData.activeQuery ) {
88
+
89
+ this.gl.endQuery( this.disjoint.TIME_ELAPSED_EXT );
90
+ renderContextData.activeQuery = null;
91
+
92
+ }
93
+
94
+ renderContextData.activeQuery = this.gl.createQuery();
95
+
96
+ if ( renderContextData.activeQuery !== null ) {
97
+
98
+ this.gl.beginQuery( this.disjoint.TIME_ELAPSED_EXT, renderContextData.activeQuery );
99
+ this.queryRunning = true;
100
+
101
+ }
102
+
103
+ }
104
+
105
+ // timestamp utils
106
+
107
+ prepareTimestampBuffer( renderContext ) {
108
+
109
+ if ( ! this.disjoint || ! this.trackTimestamp ) return;
110
+
111
+ const renderContextData = this.get( renderContext );
112
+
113
+ if ( renderContextData.activeQuery ) {
114
+
115
+ this.gl.endQuery( this.disjoint.TIME_ELAPSED_EXT );
116
+
117
+ if ( ! renderContextData.gpuQueries ) renderContextData.gpuQueries = [];
118
+ renderContextData.gpuQueries.push( { query: renderContextData.activeQuery } );
119
+ renderContextData.activeQuery = null;
120
+ this.queryRunning = false;
121
+
122
+ if ( renderContextData.queryQueue && renderContextData.queryQueue.length > 0 ) {
123
+
124
+ const nextRenderContext = renderContextData.queryQueue.shift();
125
+ this.initTimestampQuery( nextRenderContext );
126
+
127
+ }
128
+
129
+ }
130
+
131
+ }
132
+
133
+ async resolveTimestampAsync( renderContext, type = 'render' ) {
134
+
135
+ if ( ! this.disjoint || ! this.trackTimestamp ) return;
136
+
137
+ const renderContextData = this.get( renderContext );
138
+
139
+ if ( ! renderContextData.gpuQueries ) renderContextData.gpuQueries = [];
140
+
141
+ for ( let i = 0; i < renderContextData.gpuQueries.length; i ++ ) {
142
+
143
+ const queryInfo = renderContextData.gpuQueries[ i ];
144
+ const available = this.gl.getQueryParameter( queryInfo.query, this.gl.QUERY_RESULT_AVAILABLE );
145
+ const disjoint = this.gl.getParameter( this.disjoint.GPU_DISJOINT_EXT );
146
+
147
+ if ( available && ! disjoint ) {
148
+
149
+ const elapsed = this.gl.getQueryParameter( queryInfo.query, this.gl.QUERY_RESULT );
150
+ const duration = Number( elapsed ) / 1000000; // Convert nanoseconds to milliseconds
151
+ this.gl.deleteQuery( queryInfo.query );
152
+ renderContextData.gpuQueries.splice( i, 1 ); // Remove the processed query
153
+ i --;
154
+ this.renderer.info.updateTimestamp( type, duration );
155
+
156
+ }
157
+
158
+ }
159
+
160
+ }
161
+
67
162
  getContext() {
68
163
 
69
164
  return this.gl;
@@ -78,6 +173,7 @@ class WebGLBackend extends Backend {
78
173
  //
79
174
 
80
175
  //
176
+ this.initTimestampQuery( renderContext );
81
177
 
82
178
  renderContextData.previousContext = this._currentContext;
83
179
  this._currentContext = renderContext;
@@ -219,6 +315,7 @@ class WebGLBackend extends Backend {
219
315
 
220
316
  }
221
317
 
318
+ this.prepareTimestampBuffer( renderContext );
222
319
 
223
320
  }
224
321
 
@@ -379,11 +476,12 @@ class WebGLBackend extends Backend {
379
476
 
380
477
  }
381
478
 
382
- beginCompute( /*computeGroup*/ ) {
479
+ beginCompute( computeGroup ) {
383
480
 
384
481
  const gl = this.gl;
385
482
 
386
483
  gl.bindFramebuffer( gl.FRAMEBUFFER, null );
484
+ this.initTimestampQuery( computeGroup );
387
485
 
388
486
  }
389
487
 
@@ -456,7 +554,7 @@ class WebGLBackend extends Backend {
456
554
 
457
555
  }
458
556
 
459
- finishCompute( /*computeGroup*/ ) {
557
+ finishCompute( computeGroup ) {
460
558
 
461
559
  const gl = this.gl;
462
560
 
@@ -464,6 +562,8 @@ class WebGLBackend extends Backend {
464
562
 
465
563
  gl.disable( gl.RASTERIZER_DISCARD );
466
564
 
565
+ this.prepareTimestampBuffer( computeGroup );
566
+
467
567
  }
468
568
 
469
569
  draw( renderObject, info ) {
@@ -547,21 +647,22 @@ class WebGLBackend extends Backend {
547
647
 
548
648
  //
549
649
 
550
- let mode;
551
- if ( object.isPoints ) mode = gl.POINTS;
552
- else if ( object.isLineSegments ) mode = gl.LINES;
553
- else if ( object.isLine ) mode = gl.LINE_STRIP;
554
- else if ( object.isLineLoop ) mode = gl.LINE_LOOP;
650
+ const renderer = this.bufferRenderer;
651
+
652
+ if ( object.isPoints ) renderer.mode = gl.POINTS;
653
+ else if ( object.isLineSegments ) renderer.mode = gl.LINES;
654
+ else if ( object.isLine ) renderer.mode = gl.LINE_STRIP;
655
+ else if ( object.isLineLoop ) renderer.mode = gl.LINE_LOOP;
555
656
  else {
556
657
 
557
658
  if ( material.wireframe === true ) {
558
659
 
559
660
  state.setLineWidth( material.wireframeLinewidth * this.renderer.getPixelRatio() );
560
- mode = gl.LINES;
661
+ renderer.mode = gl.LINES;
561
662
 
562
663
  } else {
563
664
 
564
- mode = gl.TRIANGLES;
665
+ renderer.mode = gl.TRIANGLES;
565
666
 
566
667
  }
567
668
 
@@ -569,46 +670,63 @@ class WebGLBackend extends Backend {
569
670
 
570
671
  //
571
672
 
572
- const instanceCount = this.getInstanceCount( renderObject );
673
+
674
+ let count;
675
+
676
+ renderer.object = object;
573
677
 
574
678
  if ( index !== null ) {
575
679
 
576
680
  const indexData = this.get( index );
577
681
  const indexCount = ( drawRange.count !== Infinity ) ? drawRange.count : index.count;
578
682
 
579
- if ( instanceCount > 1 ) {
683
+ renderer.index = index.count;
684
+ renderer.type = indexData.type;
580
685
 
581
- gl.drawElementsInstanced( mode, index.count, indexData.type, firstVertex, instanceCount );
686
+ count = indexCount;
582
687
 
583
- } else {
688
+ } else {
584
689
 
585
- gl.drawElements( mode, index.count, indexData.type, firstVertex );
690
+ renderer.index = 0;
586
691
 
587
- }
692
+ const vertexCount = ( drawRange.count !== Infinity ) ? drawRange.count : geometry.attributes.position.count;
588
693
 
589
- info.update( object, indexCount, 1 );
694
+ count = vertexCount;
590
695
 
591
- } else {
696
+ }
697
+
698
+ const instanceCount = this.getInstanceCount( renderObject );
592
699
 
593
- const positionAttribute = geometry.attributes.position;
594
- const vertexCount = ( drawRange.count !== Infinity ) ? drawRange.count : positionAttribute.count;
700
+ if ( object.isBatchedMesh ) {
595
701
 
596
702
  if ( instanceCount > 1 ) {
597
703
 
598
- gl.drawArraysInstanced( mode, 0, vertexCount, instanceCount );
704
+ // TODO: Better support with InstancedBatchedMesh
705
+ if ( object._multiDrawInstances === undefined ) {
706
+
707
+ object._multiDrawInstances = new Int32Array( object._maxGeometryCount );
708
+
709
+ }
710
+
711
+ object._multiDrawInstances.fill( instanceCount );
712
+
713
+ renderer.renderMultiDrawInstances( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount, object._multiDrawInstances );
599
714
 
600
715
  } else {
601
716
 
602
- gl.drawArrays( mode, 0, vertexCount );
717
+ renderer.renderMultiDraw( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount );
603
718
 
604
719
  }
605
720
 
606
- //gl.drawArrays( mode, vertexCount, gl.UNSIGNED_SHORT, firstVertex );
721
+ } else if ( instanceCount > 1 ) {
607
722
 
608
- info.update( object, vertexCount, 1 );
723
+ renderer.renderInstances( firstVertex, count, instanceCount );
609
724
 
610
- }
725
+ } else {
611
726
 
727
+ renderer.render( firstVertex, count );
728
+
729
+ }
612
730
  //
613
731
 
614
732
  gl.bindVertexArray( null );
@@ -1027,6 +1145,12 @@ class WebGLBackend extends Backend {
1027
1145
 
1028
1146
  }
1029
1147
 
1148
+ copyTextureToTexture( position, srcTexture, dstTexture, level ) {
1149
+
1150
+ this.textureUtils.copyTextureToTexture( position, srcTexture, dstTexture, level );
1151
+
1152
+ }
1153
+
1030
1154
  copyFramebufferToTexture( texture, renderContext ) {
1031
1155
 
1032
1156
  this.textureUtils.copyFramebufferToTexture( texture, renderContext );
@@ -0,0 +1,141 @@
1
+ class WebGLBufferRenderer {
2
+
3
+ constructor( backend ) {
4
+
5
+ this.gl = backend.gl;
6
+ this.extensions = backend.extensions;
7
+ this.info = backend.renderer.info;
8
+ this.mode = null;
9
+ this.index = 0;
10
+ this.type = null;
11
+ this.object = null;
12
+
13
+ }
14
+
15
+ render( start, count ) {
16
+
17
+ const { gl, mode, object, type, info, index } = this;
18
+
19
+ if ( index !== 0 ) {
20
+
21
+ gl.drawElements( mode, count, type, start );
22
+
23
+ } else {
24
+
25
+ gl.drawArrays( mode, start, count );
26
+
27
+ }
28
+
29
+ info.update( object, count, mode, 1 );
30
+
31
+ }
32
+
33
+ renderInstances( start, count, primcount ) {
34
+
35
+ const { gl, mode, type, index, object, info } = this;
36
+
37
+ if ( primcount === 0 ) return;
38
+
39
+ if ( index !== 0 ) {
40
+
41
+ gl.drawElementsInstanced( mode, count, type, start, primcount );
42
+
43
+ } else {
44
+
45
+ gl.drawArraysInstanced( mode, start, count, primcount );
46
+
47
+ }
48
+
49
+ info.update( object, count, mode, primcount );
50
+
51
+ }
52
+
53
+ renderMultiDraw( starts, counts, drawCount ) {
54
+
55
+ const { extensions, mode, object, info } = this;
56
+
57
+ if ( drawCount === 0 ) return;
58
+
59
+ const extension = extensions.get( 'WEBGL_multi_draw' );
60
+
61
+ if ( extension === null ) {
62
+
63
+ for ( let i = 0; i < drawCount; i ++ ) {
64
+
65
+ this.render( starts[ i ], counts[ i ] );
66
+
67
+ }
68
+
69
+ } else {
70
+
71
+ if ( this.index !== 0 ) {
72
+
73
+ extension.multiDrawElementsWEBGL( mode, counts, 0, this.type, starts, 0, drawCount );
74
+
75
+ } else {
76
+
77
+ extension.multiDrawArraysWEBGL( mode, starts, 0, counts, 0, drawCount );
78
+
79
+ }
80
+
81
+ let elementCount = 0;
82
+ for ( let i = 0; i < drawCount; i ++ ) {
83
+
84
+ elementCount += counts[ i ];
85
+
86
+ }
87
+
88
+ info.update( object, elementCount, mode, 1 );
89
+
90
+ }
91
+
92
+ }
93
+
94
+ renderMultiDrawInstances( starts, counts, drawCount, primcount ) {
95
+
96
+ const { extensions, mode, object, info } = this;
97
+
98
+ if ( drawCount === 0 ) return;
99
+
100
+ const extension = extensions.get( 'WEBGL_multi_draw' );
101
+
102
+ if ( extension === null ) {
103
+
104
+ for ( let i = 0; i < drawCount; i ++ ) {
105
+
106
+ this.renderInstances( starts[ i ], counts[ i ], primcount[ i ] );
107
+
108
+ }
109
+
110
+ } else {
111
+
112
+ if ( this.index !== 0 ) {
113
+
114
+ extension.multiDrawElementsInstancedWEBGL( mode, counts, 0, this.type, starts, 0, primcount, 0, drawCount );
115
+
116
+ } else {
117
+
118
+ extension.multiDrawArraysInstancedWEBGL( mode, starts, 0, counts, 0, primcount, 0, drawCount );
119
+
120
+ }
121
+
122
+ let elementCount = 0;
123
+
124
+ for ( let i = 0; i < drawCount; i ++ ) {
125
+
126
+ elementCount += counts[ i ];
127
+
128
+ }
129
+
130
+ info.update( object, elementCount, mode, primcount );
131
+
132
+ }
133
+
134
+ }
135
+
136
+ //
137
+
138
+ }
139
+
140
+
141
+ export { WebGLBufferRenderer };
@@ -5,7 +5,7 @@ import NodeUniformsGroup from '../../common/nodes/NodeUniformsGroup.js';
5
5
 
6
6
  import { NodeSampledTexture, NodeSampledCubeTexture } from '../../common/nodes/NodeSampledTexture.js';
7
7
 
8
- import { RedFormat, RGFormat, IntType, DataTexture, RGBAFormat, FloatType } from 'three';
8
+ import { RedFormat, RGFormat, IntType, DataTexture, RGBFormat, RGBAFormat, FloatType } from 'three';
9
9
 
10
10
  const glslMethods = {
11
11
  [ MathNode.ATAN2 ]: 'atan',
@@ -104,7 +104,7 @@ ${ flowData.code }
104
104
 
105
105
  } else if ( itemSize === 3 ) {
106
106
 
107
- format = 6407; // patch since legacy doesn't use RGBFormat for rendering but here it's needed for packing optimization
107
+ format = RGBFormat;
108
108
 
109
109
  } else if ( itemSize === 4 ) {
110
110
 
@@ -390,7 +390,7 @@ ${ flowData.code }
390
390
 
391
391
  const array = dataAttribute.array;
392
392
 
393
- if ( ( array instanceof Uint32Array || array instanceof Int32Array ) === false ) {
393
+ if ( ( array instanceof Uint32Array || array instanceof Int32Array || array instanceof Uint16Array || array instanceof Int16Array ) === false ) {
394
394
 
395
395
  nodeType = nodeType.slice( 1 );
396
396
 
@@ -135,7 +135,7 @@ class WebGLAttributeUtils {
135
135
  bytesPerElement: array.BYTES_PER_ELEMENT,
136
136
  version: attribute.version,
137
137
  pbo: attribute.pbo,
138
- isInteger: type === gl.INT || type === gl.UNSIGNED_INT || attribute.gpuType === IntType,
138
+ isInteger: type === gl.INT || type === gl.UNSIGNED_INT || type === gl.UNSIGNED_SHORT || attribute.gpuType === IntType,
139
139
  id: _id ++
140
140
  };
141
141
 
@@ -7,5 +7,6 @@ export const GLFeatureName = {
7
7
  'WEBKIT_WEBGL_compressed_texture_pvrtc': 'texture-compression-pvrtc',
8
8
  'WEBGL_compressed_texture_s3tc': 'texture-compression-bc',
9
9
  'EXT_texture_compression_bptc': 'texture-compression-bptc',
10
+ 'EXT_disjoint_timer_query_webgl2': 'timestamp-query',
10
11
 
11
12
  };
@@ -143,6 +143,7 @@ class WebGLTextureUtils {
143
143
  if ( glType === gl.UNSIGNED_SHORT_5_6_5 ) internalFormat = gl.RGB565;
144
144
  if ( glType === gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = gl.RGB5_A1;
145
145
  if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = gl.RGB4;
146
+ if ( glType === gl.UNSIGNED_INT_5_9_9_9_REV ) internalFormat = gl.RGB9_E5;
146
147
 
147
148
  }
148
149
 
@@ -523,6 +524,48 @@ class WebGLTextureUtils {
523
524
 
524
525
  }
525
526
 
527
+ copyTextureToTexture( position, srcTexture, dstTexture, level = 0 ) {
528
+
529
+ const { gl, backend } = this;
530
+ const { state } = this.backend;
531
+
532
+ const width = srcTexture.image.width;
533
+ const height = srcTexture.image.height;
534
+ const { textureGPU: dstTextureGPU, glTextureType, glType, glFormat } = backend.get( dstTexture );
535
+
536
+ state.bindTexture( glTextureType, dstTextureGPU );
537
+
538
+ // As another texture upload may have changed pixelStorei
539
+ // parameters, make sure they are correct for the dstTexture
540
+ gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
541
+ gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
542
+ gl.pixelStorei( gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
543
+
544
+ if ( srcTexture.isDataTexture ) {
545
+
546
+ gl.texSubImage2D( gl.TEXTURE_2D, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
547
+
548
+ } else {
549
+
550
+ if ( srcTexture.isCompressedTexture ) {
551
+
552
+ gl.compressedTexSubImage2D( gl.TEXTURE_2D, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data );
553
+
554
+ } else {
555
+
556
+ gl.texSubImage2D( gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, srcTexture.image );
557
+
558
+ }
559
+
560
+ }
561
+
562
+ // Generate mipmaps only when copying level 0
563
+ if ( level === 0 && dstTexture.generateMipmaps ) gl.generateMipmap( gl.TEXTURE_2D );
564
+
565
+ state.unbindTexture();
566
+
567
+ }
568
+
526
569
  copyFramebufferToTexture( texture, renderContext ) {
527
570
 
528
571
  const { gl } = this;
@@ -1,4 +1,4 @@
1
- import { RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT5_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT1_Format, RGB_S3TC_DXT1_Format, DepthFormat, DepthStencilFormat, LuminanceAlphaFormat, LuminanceFormat, RedFormat, RGBAFormat, AlphaFormat, RedIntegerFormat, RGFormat, RGIntegerFormat, RGBAIntegerFormat, HalfFloatType, FloatType, UnsignedIntType, IntType, UnsignedShortType, ShortType, ByteType, UnsignedInt248Type, UnsignedShort5551Type, UnsignedShort4444Type, UnsignedByteType, RGBA_BPTC_Format, _SRGBAFormat, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format, SRGBColorSpace, NoColorSpace } from 'three';
1
+ import { RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT5_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT1_Format, RGB_S3TC_DXT1_Format, DepthFormat, DepthStencilFormat, LuminanceAlphaFormat, LuminanceFormat, RedFormat, RGBFormat, RGBAFormat, AlphaFormat, RedIntegerFormat, RGFormat, RGIntegerFormat, RGBAIntegerFormat, HalfFloatType, FloatType, UnsignedIntType, IntType, UnsignedShortType, ShortType, ByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedShort5551Type, UnsignedShort4444Type, UnsignedByteType, RGBA_BPTC_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format, SRGBColorSpace, NoColorSpace } from 'three';
2
2
 
3
3
  class WebGLUtils {
4
4
 
@@ -20,6 +20,7 @@ class WebGLUtils {
20
20
  if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE;
21
21
  if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4;
22
22
  if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1;
23
+ if ( p === UnsignedInt5999Type ) return gl.UNSIGNED_INT_5_9_9_9_REV;
23
24
 
24
25
  if ( p === ByteType ) return gl.BYTE;
25
26
  if ( p === ShortType ) return gl.SHORT;
@@ -35,7 +36,7 @@ class WebGLUtils {
35
36
  }
36
37
 
37
38
  if ( p === AlphaFormat ) return gl.ALPHA;
38
- if ( p === gl.RGB ) return gl.RGB; // patch since legacy doesn't use RGBFormat for rendering but here it's needed for packing optimization
39
+ if ( p === RGBFormat ) return gl.RGB;
39
40
  if ( p === RGBAFormat ) return gl.RGBA;
40
41
  if ( p === LuminanceFormat ) return gl.LUMINANCE;
41
42
  if ( p === LuminanceAlphaFormat ) return gl.LUMINANCE_ALPHA;
@@ -40,8 +40,6 @@ class GLSL1NodeBuilder extends NodeBuilder {
40
40
 
41
41
  getTextureBias( texture, textureProperty, uvSnippet, biasSnippet ) {
42
42
 
43
- if ( this.material.extensions !== undefined ) this.material.extensions.shaderTextureLOD = true;
44
-
45
43
  return `textureLod( ${textureProperty}, ${uvSnippet}, ${biasSnippet} )`;
46
44
 
47
45
  }
@@ -433,8 +433,6 @@ class WebGLNodeBuilder extends NodeBuilder {
433
433
 
434
434
  generateTextureLevel( texture, textureProperty, uvSnippet, biasSnippet ) {
435
435
 
436
- if ( this.material.extensions !== undefined ) this.material.extensions.shaderTextureLOD = true;
437
-
438
436
  return `textureLod( ${textureProperty}, ${uvSnippet}, ${biasSnippet} )`;
439
437
 
440
438
  }