super-three 0.160.1 → 0.162.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.
- package/LICENSE +1 -1
- package/build/three.cjs +867 -499
- package/build/three.module.js +867 -496
- package/build/three.module.min.js +1 -1
- package/examples/jsm/Addons.js +5 -1
- package/examples/jsm/capabilities/WebGPU.js +13 -9
- package/examples/jsm/controls/DragControls.js +91 -30
- package/examples/jsm/controls/OrbitControls.js +130 -15
- package/examples/jsm/controls/TransformControls.js +6 -6
- package/examples/jsm/curves/NURBSUtils.js +59 -4
- package/examples/jsm/curves/NURBSVolume.js +62 -0
- package/examples/jsm/exporters/GLTFExporter.js +11 -1
- package/examples/jsm/exporters/USDZExporter.js +8 -7
- package/examples/jsm/helpers/TextureHelper.js +3 -3
- package/examples/jsm/interactive/InteractiveGroup.js +15 -25
- package/examples/jsm/libs/rhino3dm/rhino3dm.js +1 -8723
- package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +1 -8734
- package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
- package/examples/jsm/libs/tween.module.js +32 -14
- package/examples/jsm/loaders/3DMLoader.js +57 -64
- package/examples/jsm/loaders/DDSLoader.js +1 -0
- package/examples/jsm/loaders/KTX2Loader.js +20 -5
- package/examples/jsm/loaders/LUT3dlLoader.js +78 -46
- package/examples/jsm/loaders/LUTCubeLoader.js +81 -67
- package/examples/jsm/loaders/LUTImageLoader.js +3 -2
- package/examples/jsm/loaders/MaterialXLoader.js +115 -16
- package/examples/jsm/loaders/SVGLoader.js +4 -3
- package/examples/jsm/loaders/VOXLoader.js +9 -2
- package/examples/jsm/loaders/VRMLLoader.js +7 -3
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +144 -0
- package/examples/jsm/misc/ProgressiveLightMap.js +1 -0
- package/examples/jsm/misc/Timer.js +13 -4
- package/examples/jsm/nodes/Nodes.js +24 -11
- package/examples/jsm/nodes/accessors/AccessorsUtils.js +10 -0
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +5 -3
- package/examples/jsm/nodes/accessors/CameraNode.js +9 -4
- package/examples/jsm/nodes/accessors/ClippingNode.js +144 -0
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +12 -1
- package/examples/jsm/nodes/accessors/MaterialNode.js +2 -2
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +2 -12
- package/examples/jsm/nodes/accessors/MorphNode.js +8 -8
- package/examples/jsm/nodes/accessors/ReferenceNode.js +87 -29
- package/examples/jsm/nodes/accessors/SkinningNode.js +31 -10
- package/examples/jsm/nodes/accessors/StorageBufferNode.js +45 -0
- package/examples/jsm/nodes/accessors/TangentNode.js +8 -2
- package/examples/jsm/nodes/accessors/TextureNode.js +1 -1
- package/examples/jsm/nodes/accessors/TextureStoreNode.js +56 -3
- package/examples/jsm/nodes/accessors/UniformsNode.js +140 -0
- package/examples/jsm/nodes/accessors/VertexColorNode.js +70 -0
- package/examples/jsm/nodes/code/CodeNode.js +6 -0
- package/examples/jsm/nodes/core/AssignNode.js +68 -12
- package/examples/jsm/nodes/core/AttributeNode.js +1 -1
- package/examples/jsm/nodes/core/Node.js +14 -4
- package/examples/jsm/nodes/core/NodeBuilder.js +26 -27
- package/examples/jsm/nodes/core/NodeFrame.js +18 -10
- package/examples/jsm/nodes/core/TempNode.js +1 -1
- package/examples/jsm/nodes/core/constants.js +1 -0
- package/examples/jsm/nodes/display/AfterImageNode.js +148 -0
- package/examples/jsm/nodes/display/AnamorphicNode.js +148 -0
- package/examples/jsm/nodes/display/BlendModeNode.js +30 -1
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +3 -0
- package/examples/jsm/nodes/display/GaussianBlurNode.js +33 -13
- package/examples/jsm/nodes/display/NormalMapNode.js +3 -5
- package/examples/jsm/nodes/display/PassNode.js +3 -2
- package/examples/jsm/nodes/display/ToneMappingNode.js +46 -3
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +1 -4
- package/examples/jsm/nodes/display/ViewportNode.js +0 -2
- package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +4 -4
- package/examples/jsm/nodes/fog/FogNode.js +2 -1
- package/examples/jsm/nodes/lighting/AmbientLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +13 -5
- package/examples/jsm/nodes/lighting/LightingContextNode.js +1 -1
- package/examples/jsm/nodes/lighting/LightsNode.js +1 -1
- package/examples/jsm/nodes/materials/Line2NodeMaterial.js +18 -30
- package/examples/jsm/nodes/materials/Materials.js +1 -0
- package/examples/jsm/nodes/materials/MeshSSSNodeMaterial.js +84 -0
- package/examples/jsm/nodes/materials/NodeMaterial.js +43 -10
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +1 -7
- package/examples/jsm/nodes/math/CondNode.js +42 -7
- package/examples/jsm/nodes/math/MathNode.js +32 -2
- package/examples/jsm/nodes/math/MathUtils.js +15 -0
- package/examples/jsm/nodes/math/OperatorNode.js +13 -5
- package/examples/jsm/nodes/math/TriNoise3D.js +71 -0
- package/examples/jsm/nodes/shadernode/ShaderNode.js +10 -1
- package/examples/jsm/nodes/utils/JoinNode.js +2 -2
- package/examples/jsm/nodes/utils/LoopNode.js +5 -3
- package/examples/jsm/nodes/utils/ReflectorNode.js +227 -0
- package/examples/jsm/nodes/utils/RotateNode.js +68 -0
- package/examples/jsm/nodes/utils/RotateUVNode.js +1 -9
- package/examples/jsm/nodes/utils/SplitNode.js +4 -4
- package/examples/jsm/nodes/utils/StorageArrayElementNode.js +91 -0
- package/examples/jsm/objects/GroundedSkybox.js +50 -0
- package/examples/jsm/objects/QuadMesh.js +8 -2
- package/examples/jsm/objects/Water2.js +8 -8
- package/examples/jsm/postprocessing/GTAOPass.js +11 -1
- package/examples/jsm/postprocessing/OutputPass.js +2 -0
- package/examples/jsm/renderers/common/Backend.js +14 -0
- package/examples/jsm/renderers/common/Background.js +2 -2
- package/examples/jsm/renderers/common/Bindings.js +1 -1
- package/examples/jsm/renderers/common/ClippingContext.js +165 -0
- package/examples/jsm/renderers/common/DataMap.js +1 -1
- package/examples/jsm/renderers/common/Info.js +25 -1
- package/examples/jsm/renderers/common/Pipelines.js +8 -8
- package/examples/jsm/renderers/common/PostProcessing.js +2 -2
- package/examples/jsm/renderers/common/ProgrammableStage.js +3 -1
- package/examples/jsm/renderers/common/RenderContext.js +2 -0
- package/examples/jsm/renderers/common/RenderContexts.js +2 -13
- package/examples/jsm/renderers/common/RenderObject.js +46 -1
- package/examples/jsm/renderers/common/RenderObjects.js +3 -1
- package/examples/jsm/renderers/common/Renderer.js +290 -17
- package/examples/jsm/renderers/common/StorageBufferAttribute.js +17 -0
- package/examples/jsm/renderers/common/StorageInstancedBufferAttribute.js +17 -0
- package/examples/jsm/renderers/common/Textures.js +28 -18
- package/examples/jsm/renderers/common/UniformsGroup.js +6 -4
- package/examples/jsm/renderers/common/nodes/NodeBuilderState.js +2 -1
- package/examples/jsm/renderers/common/nodes/NodeStorageBuffer.js +23 -0
- package/examples/jsm/renderers/common/nodes/NodeUniformBuffer.js +23 -0
- package/examples/jsm/renderers/common/nodes/Nodes.js +5 -2
- package/examples/jsm/renderers/webgl/WebGLBackend.js +653 -272
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +171 -39
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +95 -8
- package/examples/jsm/renderers/webgl/utils/WebGLConstants.js +11 -0
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +197 -0
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +424 -11
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +3 -2
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +1 -21
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +2 -2
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +300 -112
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +7 -2
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +71 -79
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -1
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +38 -4
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +87 -14
- package/examples/jsm/shaders/OutputShader.js +4 -0
- package/examples/jsm/transpiler/AST.js +1 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
- package/examples/jsm/transpiler/TSLEncoder.js +1 -1
- package/examples/jsm/utils/BufferGeometryUtils.js +23 -27
- package/examples/jsm/utils/SkeletonUtils.js +14 -3
- package/examples/jsm/utils/SortUtils.js +2 -0
- package/examples/jsm/webxr/ARButton.js +12 -2
- package/examples/jsm/webxr/VRButton.js +25 -7
- package/examples/jsm/webxr/XRButton.js +12 -3
- package/examples/jsm/webxr/XRControllerModelFactory.js +14 -1
- package/examples/jsm/webxr/XRHandMeshModel.js +3 -1
- package/package.json +5 -4
- package/src/Three.Legacy.js +20 -0
- package/src/Three.js +0 -1
- package/src/audio/Audio.js +1 -3
- package/src/cameras/PerspectiveCamera.js +35 -0
- package/src/constants.js +2 -6
- package/src/core/BufferAttribute.js +2 -12
- package/src/core/BufferGeometry.js +23 -29
- package/src/core/InterleavedBuffer.js +2 -1
- package/src/core/InterleavedBufferAttribute.js +20 -0
- package/src/core/Object3D.js +11 -0
- package/src/core/Raycaster.js +18 -4
- package/src/core/RenderTarget.js +44 -21
- package/src/extras/PMREMGenerator.js +2 -0
- package/src/extras/curves/EllipseCurve.js +2 -2
- package/src/helpers/SpotLightHelper.js +18 -1
- package/src/loaders/DataTextureLoader.js +0 -4
- package/src/loaders/MaterialLoader.js +1 -0
- package/src/loaders/ObjectLoader.js +2 -1
- package/src/materials/Material.js +2 -1
- package/src/materials/MeshBasicMaterial.js +3 -0
- package/src/materials/MeshLambertMaterial.js +3 -0
- package/src/materials/MeshPhongMaterial.js +3 -0
- package/src/materials/MeshStandardMaterial.js +3 -0
- package/src/materials/ShaderMaterial.js +2 -1
- package/src/math/Quaternion.js +13 -12
- package/src/math/Triangle.js +0 -30
- package/src/math/Vector3.js +7 -7
- package/src/objects/BatchedMesh.js +6 -7
- package/src/objects/InstancedMesh.js +53 -0
- package/src/objects/Mesh.js +0 -1
- package/src/objects/SkinnedMesh.js +0 -8
- package/src/renderers/WebGLCubeRenderTarget.js +1 -10
- package/src/renderers/WebGLRenderer.js +20 -23
- package/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js +9 -0
- package/src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl.js +56 -11
- package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +1 -0
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/morphinstance_vertex.glsl.js +14 -0
- package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +11 -2
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +38 -7
- package/src/renderers/shaders/ShaderChunk.js +2 -0
- package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +3 -2
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +3 -2
- package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +3 -2
- package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +2 -2
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +2 -2
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +4 -1
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/points.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -0
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib.js +2 -1
- package/src/renderers/shaders/UniformsLib.js +1 -0
- package/src/renderers/webgl/WebGLAttributes.js +2 -2
- package/src/renderers/webgl/WebGLBackground.js +18 -0
- package/src/renderers/webgl/WebGLCubeMaps.js +1 -1
- package/src/renderers/webgl/WebGLMaterials.js +24 -1
- package/src/renderers/webgl/WebGLMorphtargets.js +15 -8
- package/src/renderers/webgl/WebGLProgram.js +42 -4
- package/src/renderers/webgl/WebGLPrograms.js +38 -27
- package/src/renderers/webgl/WebGLState.js +11 -21
- package/src/renderers/webgl/WebGLTextures.js +170 -66
- package/src/renderers/webxr/WebXRDepthSensing.js +105 -0
- package/src/renderers/webxr/WebXRManager.js +46 -0
- package/src/scenes/Scene.js +8 -0
- package/src/textures/Source.js +1 -0
- package/src/textures/Texture.js +1 -29
- package/build/three.js +0 -54519
- package/build/three.min.js +0 -7
- package/examples/jsm/nodes/core/ArrayUniformNode.js +0 -26
- package/examples/jsm/objects/GroundProjectedSkybox.js +0 -172
- package/src/renderers/WebGLMultipleRenderTargets.js +0 -82
|
@@ -3,6 +3,7 @@ import * as MathUtils from '../../math/MathUtils.js';
|
|
|
3
3
|
import { ImageUtils } from '../../extras/ImageUtils.js';
|
|
4
4
|
import { createElementNS } from '../../utils.js';
|
|
5
5
|
import { ColorManagement } from '../../math/ColorManagement.js';
|
|
6
|
+
import { Vector2 } from '../../math/Vector2.js';
|
|
6
7
|
|
|
7
8
|
function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
|
|
8
9
|
|
|
@@ -11,6 +12,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
11
12
|
const supportsInvalidateFramebuffer = typeof navigator === 'undefined' ? false : /OculusBrowser/g.test( navigator.userAgent );
|
|
12
13
|
const multiviewExt = extensions.has( 'OCULUS_multiview' ) ? extensions.get( 'OCULUS_multiview' ) : null;
|
|
13
14
|
|
|
15
|
+
const _imageDimensions = new Vector2();
|
|
14
16
|
const _videoTextures = new WeakMap();
|
|
15
17
|
let _canvas;
|
|
16
18
|
|
|
@@ -51,11 +53,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
51
53
|
|
|
52
54
|
let scale = 1;
|
|
53
55
|
|
|
56
|
+
const dimensions = getDimensions( image );
|
|
57
|
+
|
|
54
58
|
// handle case if texture exceeds max size
|
|
55
59
|
|
|
56
|
-
if (
|
|
60
|
+
if ( dimensions.width > maxSize || dimensions.height > maxSize ) {
|
|
57
61
|
|
|
58
|
-
scale = maxSize / Math.max(
|
|
62
|
+
scale = maxSize / Math.max( dimensions.width, dimensions.height );
|
|
59
63
|
|
|
60
64
|
}
|
|
61
65
|
|
|
@@ -67,12 +71,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
67
71
|
|
|
68
72
|
if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
|
|
69
73
|
( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
|
|
70
|
-
( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap )
|
|
74
|
+
( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ||
|
|
75
|
+
( typeof VideoFrame !== 'undefined' && image instanceof VideoFrame ) ) {
|
|
71
76
|
|
|
72
77
|
const floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
|
|
73
78
|
|
|
74
|
-
const width = floor( scale *
|
|
75
|
-
const height = floor( scale *
|
|
79
|
+
const width = floor( scale * dimensions.width );
|
|
80
|
+
const height = floor( scale * dimensions.height );
|
|
76
81
|
|
|
77
82
|
if ( _canvas === undefined ) _canvas = createCanvas( width, height );
|
|
78
83
|
|
|
@@ -86,7 +91,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
86
91
|
const context = canvas.getContext( '2d' );
|
|
87
92
|
context.drawImage( image, 0, 0, width, height );
|
|
88
93
|
|
|
89
|
-
console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' +
|
|
94
|
+
console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + dimensions.width + 'x' + dimensions.height + ') to (' + width + 'x' + height + ').' );
|
|
90
95
|
|
|
91
96
|
return canvas;
|
|
92
97
|
|
|
@@ -94,7 +99,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
94
99
|
|
|
95
100
|
if ( 'data' in image ) {
|
|
96
101
|
|
|
97
|
-
console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' +
|
|
102
|
+
console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + dimensions.width + 'x' + dimensions.height + ').' );
|
|
98
103
|
|
|
99
104
|
}
|
|
100
105
|
|
|
@@ -110,7 +115,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
110
115
|
|
|
111
116
|
function isPowerOfTwo( image ) {
|
|
112
117
|
|
|
113
|
-
|
|
118
|
+
const dimensions = getDimensions( image );
|
|
119
|
+
|
|
120
|
+
return MathUtils.isPowerOfTwo( dimensions.width ) && MathUtils.isPowerOfTwo( dimensions.height );
|
|
114
121
|
|
|
115
122
|
}
|
|
116
123
|
|
|
@@ -177,6 +184,17 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
177
184
|
|
|
178
185
|
}
|
|
179
186
|
|
|
187
|
+
if ( glFormat === _gl.RG_INTEGER ) {
|
|
188
|
+
|
|
189
|
+
if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RG8UI;
|
|
190
|
+
if ( glType === _gl.UNSIGNED_SHORT ) internalFormat = _gl.RG16UI;
|
|
191
|
+
if ( glType === _gl.UNSIGNED_INT ) internalFormat = _gl.RG32UI;
|
|
192
|
+
if ( glType === _gl.BYTE ) internalFormat = _gl.RG8I;
|
|
193
|
+
if ( glType === _gl.SHORT ) internalFormat = _gl.RG16I;
|
|
194
|
+
if ( glType === _gl.INT ) internalFormat = _gl.RG32I;
|
|
195
|
+
|
|
196
|
+
}
|
|
197
|
+
|
|
180
198
|
if ( glFormat === _gl.RGBA ) {
|
|
181
199
|
|
|
182
200
|
const transfer = forceLinearTransfer ? LinearTransfer : ColorManagement.getTransfer( colorSpace );
|
|
@@ -324,18 +342,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
324
342
|
|
|
325
343
|
function deallocateRenderTarget( renderTarget ) {
|
|
326
344
|
|
|
327
|
-
const texture = renderTarget.texture;
|
|
328
|
-
|
|
329
345
|
const renderTargetProperties = properties.get( renderTarget );
|
|
330
|
-
const textureProperties = properties.get( texture );
|
|
331
|
-
|
|
332
|
-
if ( textureProperties.__webglTexture !== undefined ) {
|
|
333
|
-
|
|
334
|
-
_gl.deleteTexture( textureProperties.__webglTexture );
|
|
335
|
-
|
|
336
|
-
info.memory.textures --;
|
|
337
|
-
|
|
338
|
-
}
|
|
339
346
|
|
|
340
347
|
if ( renderTarget.depthTexture ) {
|
|
341
348
|
|
|
@@ -390,27 +397,24 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
390
397
|
|
|
391
398
|
}
|
|
392
399
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
for ( let i = 0, il = texture.length; i < il; i ++ ) {
|
|
400
|
+
const textures = renderTarget.textures;
|
|
396
401
|
|
|
397
|
-
|
|
402
|
+
for ( let i = 0, il = textures.length; i < il; i ++ ) {
|
|
398
403
|
|
|
399
|
-
|
|
404
|
+
const attachmentProperties = properties.get( textures[ i ] );
|
|
400
405
|
|
|
401
|
-
|
|
406
|
+
if ( attachmentProperties.__webglTexture ) {
|
|
402
407
|
|
|
403
|
-
|
|
408
|
+
_gl.deleteTexture( attachmentProperties.__webglTexture );
|
|
404
409
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
properties.remove( texture[ i ] );
|
|
410
|
+
info.memory.textures --;
|
|
408
411
|
|
|
409
412
|
}
|
|
410
413
|
|
|
414
|
+
properties.remove( textures[ i ] );
|
|
415
|
+
|
|
411
416
|
}
|
|
412
417
|
|
|
413
|
-
properties.remove( texture );
|
|
414
418
|
properties.remove( renderTarget );
|
|
415
419
|
|
|
416
420
|
}
|
|
@@ -574,6 +578,14 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
574
578
|
|
|
575
579
|
function setTextureParameters( textureType, texture, supportsMips ) {
|
|
576
580
|
|
|
581
|
+
if ( texture.type === FloatType && extensions.has( 'OES_texture_float_linear' ) === false &&
|
|
582
|
+
( texture.magFilter === LinearFilter || texture.magFilter === LinearMipmapNearestFilter || texture.magFilter === NearestMipmapLinearFilter || texture.magFilter === LinearMipmapLinearFilter ||
|
|
583
|
+
texture.minFilter === LinearFilter || texture.minFilter === LinearMipmapNearestFilter || texture.minFilter === NearestMipmapLinearFilter || texture.minFilter === LinearMipmapLinearFilter ) ) {
|
|
584
|
+
|
|
585
|
+
console.warn( 'THREE.WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device.' );
|
|
586
|
+
|
|
587
|
+
}
|
|
588
|
+
|
|
577
589
|
if ( supportsMips ) {
|
|
578
590
|
|
|
579
591
|
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, wrappingToGL[ texture.wrapS ] );
|
|
@@ -625,8 +637,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
625
637
|
|
|
626
638
|
if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) {
|
|
627
639
|
|
|
628
|
-
const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
|
|
629
|
-
|
|
630
640
|
if ( texture.magFilter === NearestFilter ) return;
|
|
631
641
|
if ( texture.minFilter !== NearestMipmapLinearFilter && texture.minFilter !== LinearMipmapLinearFilter ) return;
|
|
632
642
|
if ( texture.type === FloatType && extensions.has( 'OES_texture_float_linear' ) === false ) return; // verify extension for WebGL 1 and WebGL 2
|
|
@@ -634,6 +644,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
634
644
|
|
|
635
645
|
if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
|
|
636
646
|
|
|
647
|
+
const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
|
|
637
648
|
_gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
|
|
638
649
|
properties.get( texture ).__currentAnisotropy = texture.anisotropy;
|
|
639
650
|
|
|
@@ -804,6 +815,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
804
815
|
|
|
805
816
|
const useTexStorage = ( isWebGL2 && texture.isVideoTexture !== true && glInternalFormat !== RGB_ETC1_Format );
|
|
806
817
|
const allocateMemory = ( sourceProperties.__version === undefined ) || ( forceUpload === true );
|
|
818
|
+
const dataReady = source.dataReady;
|
|
807
819
|
const levels = getMipLevels( texture, image, supportsMips );
|
|
808
820
|
|
|
809
821
|
if ( texture.isDepthTexture ) {
|
|
@@ -916,7 +928,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
916
928
|
|
|
917
929
|
if ( useTexStorage ) {
|
|
918
930
|
|
|
919
|
-
|
|
931
|
+
if ( dataReady ) {
|
|
932
|
+
|
|
933
|
+
state.texSubImage2D( _gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data );
|
|
934
|
+
|
|
935
|
+
}
|
|
920
936
|
|
|
921
937
|
} else {
|
|
922
938
|
|
|
@@ -938,7 +954,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
938
954
|
|
|
939
955
|
}
|
|
940
956
|
|
|
941
|
-
|
|
957
|
+
if ( dataReady ) {
|
|
958
|
+
|
|
959
|
+
state.texSubImage2D( _gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, glFormat, glType, image.data );
|
|
960
|
+
|
|
961
|
+
}
|
|
942
962
|
|
|
943
963
|
} else {
|
|
944
964
|
|
|
@@ -968,7 +988,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
968
988
|
|
|
969
989
|
if ( useTexStorage ) {
|
|
970
990
|
|
|
971
|
-
|
|
991
|
+
if ( dataReady ) {
|
|
992
|
+
|
|
993
|
+
state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data, 0, 0 );
|
|
994
|
+
|
|
995
|
+
}
|
|
972
996
|
|
|
973
997
|
} else {
|
|
974
998
|
|
|
@@ -986,7 +1010,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
986
1010
|
|
|
987
1011
|
if ( useTexStorage ) {
|
|
988
1012
|
|
|
989
|
-
|
|
1013
|
+
if ( dataReady ) {
|
|
1014
|
+
|
|
1015
|
+
state.texSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, glType, mipmap.data );
|
|
1016
|
+
|
|
1017
|
+
}
|
|
990
1018
|
|
|
991
1019
|
} else {
|
|
992
1020
|
|
|
@@ -1016,7 +1044,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1016
1044
|
|
|
1017
1045
|
if ( useTexStorage ) {
|
|
1018
1046
|
|
|
1019
|
-
|
|
1047
|
+
if ( dataReady ) {
|
|
1048
|
+
|
|
1049
|
+
state.compressedTexSubImage2D( _gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data );
|
|
1050
|
+
|
|
1051
|
+
}
|
|
1020
1052
|
|
|
1021
1053
|
} else {
|
|
1022
1054
|
|
|
@@ -1034,7 +1066,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1034
1066
|
|
|
1035
1067
|
if ( useTexStorage ) {
|
|
1036
1068
|
|
|
1037
|
-
|
|
1069
|
+
if ( dataReady ) {
|
|
1070
|
+
|
|
1071
|
+
state.texSubImage2D( _gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data );
|
|
1072
|
+
|
|
1073
|
+
}
|
|
1038
1074
|
|
|
1039
1075
|
} else {
|
|
1040
1076
|
|
|
@@ -1058,7 +1094,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1058
1094
|
|
|
1059
1095
|
}
|
|
1060
1096
|
|
|
1061
|
-
|
|
1097
|
+
if ( dataReady ) {
|
|
1098
|
+
|
|
1099
|
+
state.texSubImage3D( _gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data );
|
|
1100
|
+
|
|
1101
|
+
}
|
|
1062
1102
|
|
|
1063
1103
|
} else {
|
|
1064
1104
|
|
|
@@ -1076,7 +1116,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1076
1116
|
|
|
1077
1117
|
}
|
|
1078
1118
|
|
|
1079
|
-
|
|
1119
|
+
if ( dataReady ) {
|
|
1120
|
+
|
|
1121
|
+
state.texSubImage3D( _gl.TEXTURE_3D, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data );
|
|
1122
|
+
|
|
1123
|
+
}
|
|
1080
1124
|
|
|
1081
1125
|
} else {
|
|
1082
1126
|
|
|
@@ -1121,7 +1165,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1121
1165
|
|
|
1122
1166
|
if ( useTexStorage && allocateMemory ) {
|
|
1123
1167
|
|
|
1124
|
-
|
|
1168
|
+
const dimensions = getDimensions( mipmaps[ 0 ] );
|
|
1169
|
+
|
|
1170
|
+
state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, dimensions.width, dimensions.height );
|
|
1125
1171
|
|
|
1126
1172
|
}
|
|
1127
1173
|
|
|
@@ -1131,7 +1177,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1131
1177
|
|
|
1132
1178
|
if ( useTexStorage ) {
|
|
1133
1179
|
|
|
1134
|
-
|
|
1180
|
+
if ( dataReady ) {
|
|
1181
|
+
|
|
1182
|
+
state.texSubImage2D( _gl.TEXTURE_2D, i, 0, 0, glFormat, glType, mipmap );
|
|
1183
|
+
|
|
1184
|
+
}
|
|
1135
1185
|
|
|
1136
1186
|
} else {
|
|
1137
1187
|
|
|
@@ -1149,11 +1199,17 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1149
1199
|
|
|
1150
1200
|
if ( allocateMemory ) {
|
|
1151
1201
|
|
|
1152
|
-
|
|
1202
|
+
const dimensions = getDimensions( image );
|
|
1203
|
+
|
|
1204
|
+
state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, dimensions.width, dimensions.height );
|
|
1153
1205
|
|
|
1154
1206
|
}
|
|
1155
1207
|
|
|
1156
|
-
|
|
1208
|
+
if ( dataReady ) {
|
|
1209
|
+
|
|
1210
|
+
state.texSubImage2D( _gl.TEXTURE_2D, 0, 0, 0, glFormat, glType, image );
|
|
1211
|
+
|
|
1212
|
+
}
|
|
1157
1213
|
|
|
1158
1214
|
} else {
|
|
1159
1215
|
|
|
@@ -1235,6 +1291,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1235
1291
|
|
|
1236
1292
|
const useTexStorage = ( isWebGL2 && texture.isVideoTexture !== true );
|
|
1237
1293
|
const allocateMemory = ( sourceProperties.__version === undefined ) || ( forceUpload === true );
|
|
1294
|
+
const dataReady = source.dataReady;
|
|
1238
1295
|
let levels = getMipLevels( texture, image, supportsMips );
|
|
1239
1296
|
|
|
1240
1297
|
setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, supportsMips );
|
|
@@ -1263,7 +1320,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1263
1320
|
|
|
1264
1321
|
if ( useTexStorage ) {
|
|
1265
1322
|
|
|
1266
|
-
|
|
1323
|
+
if ( dataReady ) {
|
|
1324
|
+
|
|
1325
|
+
state.compressedTexSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data );
|
|
1326
|
+
|
|
1327
|
+
}
|
|
1267
1328
|
|
|
1268
1329
|
} else {
|
|
1269
1330
|
|
|
@@ -1281,7 +1342,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1281
1342
|
|
|
1282
1343
|
if ( useTexStorage ) {
|
|
1283
1344
|
|
|
1284
|
-
|
|
1345
|
+
if ( dataReady ) {
|
|
1346
|
+
|
|
1347
|
+
state.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data );
|
|
1348
|
+
|
|
1349
|
+
}
|
|
1285
1350
|
|
|
1286
1351
|
} else {
|
|
1287
1352
|
|
|
@@ -1307,7 +1372,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1307
1372
|
|
|
1308
1373
|
if ( mipmaps.length > 0 ) levels ++;
|
|
1309
1374
|
|
|
1310
|
-
|
|
1375
|
+
const dimensions = getDimensions( cubeImage[ 0 ] );
|
|
1376
|
+
|
|
1377
|
+
state.texStorage2D( _gl.TEXTURE_CUBE_MAP, levels, glInternalFormat, dimensions.width, dimensions.height );
|
|
1311
1378
|
|
|
1312
1379
|
}
|
|
1313
1380
|
|
|
@@ -1317,7 +1384,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1317
1384
|
|
|
1318
1385
|
if ( useTexStorage ) {
|
|
1319
1386
|
|
|
1320
|
-
|
|
1387
|
+
if ( dataReady ) {
|
|
1388
|
+
|
|
1389
|
+
state.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, cubeImage[ i ].width, cubeImage[ i ].height, glFormat, glType, cubeImage[ i ].data );
|
|
1390
|
+
|
|
1391
|
+
}
|
|
1321
1392
|
|
|
1322
1393
|
} else {
|
|
1323
1394
|
|
|
@@ -1332,7 +1403,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1332
1403
|
|
|
1333
1404
|
if ( useTexStorage ) {
|
|
1334
1405
|
|
|
1335
|
-
|
|
1406
|
+
if ( dataReady ) {
|
|
1407
|
+
|
|
1408
|
+
state.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, 0, 0, mipmapImage.width, mipmapImage.height, glFormat, glType, mipmapImage.data );
|
|
1409
|
+
|
|
1410
|
+
}
|
|
1336
1411
|
|
|
1337
1412
|
} else {
|
|
1338
1413
|
|
|
@@ -1346,7 +1421,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1346
1421
|
|
|
1347
1422
|
if ( useTexStorage ) {
|
|
1348
1423
|
|
|
1349
|
-
|
|
1424
|
+
if ( dataReady ) {
|
|
1425
|
+
|
|
1426
|
+
state.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, glFormat, glType, cubeImage[ i ] );
|
|
1427
|
+
|
|
1428
|
+
}
|
|
1350
1429
|
|
|
1351
1430
|
} else {
|
|
1352
1431
|
|
|
@@ -1360,7 +1439,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1360
1439
|
|
|
1361
1440
|
if ( useTexStorage ) {
|
|
1362
1441
|
|
|
1363
|
-
|
|
1442
|
+
if ( dataReady ) {
|
|
1443
|
+
|
|
1444
|
+
state.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, 0, 0, glFormat, glType, mipmap.image[ i ] );
|
|
1445
|
+
|
|
1446
|
+
}
|
|
1364
1447
|
|
|
1365
1448
|
} else {
|
|
1366
1449
|
|
|
@@ -1581,7 +1664,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1581
1664
|
|
|
1582
1665
|
} else {
|
|
1583
1666
|
|
|
1584
|
-
const textures = renderTarget.
|
|
1667
|
+
const textures = renderTarget.textures;
|
|
1585
1668
|
|
|
1586
1669
|
for ( let i = 0; i < textures.length; i ++ ) {
|
|
1587
1670
|
|
|
@@ -1793,7 +1876,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1793
1876
|
|
|
1794
1877
|
renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
|
|
1795
1878
|
|
|
1796
|
-
|
|
1879
|
+
const textures = renderTarget.textures;
|
|
1880
|
+
|
|
1881
|
+
const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
|
|
1882
|
+
const isMultipleRenderTargets = ( textures.length > 1 );
|
|
1883
|
+
const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
|
|
1884
|
+
|
|
1885
|
+
if ( ! isMultipleRenderTargets ) {
|
|
1797
1886
|
|
|
1798
1887
|
if ( textureProperties.__webglTexture === undefined ) {
|
|
1799
1888
|
|
|
@@ -1806,10 +1895,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1806
1895
|
|
|
1807
1896
|
}
|
|
1808
1897
|
|
|
1809
|
-
const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
|
|
1810
|
-
const isMultipleRenderTargets = ( renderTarget.isWebGLMultipleRenderTargets === true );
|
|
1811
|
-
const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
|
|
1812
|
-
|
|
1813
1898
|
// Setup framebuffer
|
|
1814
1899
|
|
|
1815
1900
|
if ( isCube ) {
|
|
@@ -1858,8 +1943,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1858
1943
|
|
|
1859
1944
|
if ( capabilities.drawBuffers ) {
|
|
1860
1945
|
|
|
1861
|
-
const textures = renderTarget.texture;
|
|
1862
|
-
|
|
1863
1946
|
for ( let i = 0, il = textures.length; i < il; i ++ ) {
|
|
1864
1947
|
|
|
1865
1948
|
const attachmentProperties = properties.get( textures[ i ] );
|
|
@@ -1884,8 +1967,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1884
1967
|
|
|
1885
1968
|
if ( ( isWebGL2 && renderTarget.samples > 0 ) && useMultisampledRTT( renderTarget ) === false ) {
|
|
1886
1969
|
|
|
1887
|
-
const textures = isMultipleRenderTargets ? texture : [ texture ];
|
|
1888
|
-
|
|
1889
1970
|
renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
|
|
1890
1971
|
renderTargetProperties.__webglColorRenderbuffer = [];
|
|
1891
1972
|
|
|
@@ -1958,8 +2039,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
1958
2039
|
|
|
1959
2040
|
} else if ( isMultipleRenderTargets ) {
|
|
1960
2041
|
|
|
1961
|
-
const textures = renderTarget.texture;
|
|
1962
|
-
|
|
1963
2042
|
for ( let i = 0, il = textures.length; i < il; i ++ ) {
|
|
1964
2043
|
|
|
1965
2044
|
const attachment = textures[ i ];
|
|
@@ -2044,7 +2123,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
2044
2123
|
|
|
2045
2124
|
const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
|
|
2046
2125
|
|
|
2047
|
-
const textures = renderTarget.
|
|
2126
|
+
const textures = renderTarget.textures;
|
|
2048
2127
|
|
|
2049
2128
|
for ( let i = 0, il = textures.length; i < il; i ++ ) {
|
|
2050
2129
|
|
|
@@ -2069,14 +2148,14 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
2069
2148
|
|
|
2070
2149
|
if ( ( isWebGL2 && renderTarget.samples > 0 ) && useMultisampledRTT( renderTarget ) === false ) {
|
|
2071
2150
|
|
|
2072
|
-
const textures = renderTarget.
|
|
2151
|
+
const textures = renderTarget.textures;
|
|
2073
2152
|
const width = renderTarget.width;
|
|
2074
2153
|
const height = renderTarget.height;
|
|
2075
2154
|
let mask = _gl.COLOR_BUFFER_BIT;
|
|
2076
2155
|
const invalidationArray = [];
|
|
2077
2156
|
const depthStyle = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;
|
|
2078
2157
|
const renderTargetProperties = properties.get( renderTarget );
|
|
2079
|
-
const isMultipleRenderTargets = (
|
|
2158
|
+
const isMultipleRenderTargets = ( textures.length > 1 );
|
|
2080
2159
|
|
|
2081
2160
|
// If MRT we need to remove FBO attachments
|
|
2082
2161
|
if ( isMultipleRenderTargets ) {
|
|
@@ -2260,6 +2339,31 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
2260
2339
|
|
|
2261
2340
|
}
|
|
2262
2341
|
|
|
2342
|
+
function getDimensions( image ) {
|
|
2343
|
+
|
|
2344
|
+
if ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) {
|
|
2345
|
+
|
|
2346
|
+
// if intrinsic data are not available, fallback to width/height
|
|
2347
|
+
|
|
2348
|
+
_imageDimensions.width = image.naturalWidth || image.width;
|
|
2349
|
+
_imageDimensions.height = image.naturalHeight || image.height;
|
|
2350
|
+
|
|
2351
|
+
} else if ( typeof VideoFrame !== 'undefined' && image instanceof VideoFrame ) {
|
|
2352
|
+
|
|
2353
|
+
_imageDimensions.width = image.displayWidth;
|
|
2354
|
+
_imageDimensions.height = image.displayHeight;
|
|
2355
|
+
|
|
2356
|
+
} else {
|
|
2357
|
+
|
|
2358
|
+
_imageDimensions.width = image.width;
|
|
2359
|
+
_imageDimensions.height = image.height;
|
|
2360
|
+
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
return _imageDimensions;
|
|
2364
|
+
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2263
2367
|
//
|
|
2264
2368
|
|
|
2265
2369
|
this.allocateTextureUnit = allocateTextureUnit;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { PlaneGeometry } from '../../geometries/PlaneGeometry.js';
|
|
2
|
+
import { ShaderMaterial } from '../../materials/ShaderMaterial.js';
|
|
3
|
+
import { Mesh } from '../../objects/Mesh.js';
|
|
4
|
+
import { Texture } from '../../textures/Texture.js';
|
|
5
|
+
|
|
6
|
+
const _occlusion_vertex = `
|
|
7
|
+
void main() {
|
|
8
|
+
|
|
9
|
+
gl_Position = vec4( position, 1.0 );
|
|
10
|
+
|
|
11
|
+
}`;
|
|
12
|
+
|
|
13
|
+
const _occlusion_fragment = `
|
|
14
|
+
uniform sampler2DArray depthColor;
|
|
15
|
+
uniform float depthWidth;
|
|
16
|
+
uniform float depthHeight;
|
|
17
|
+
|
|
18
|
+
void main() {
|
|
19
|
+
|
|
20
|
+
vec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight );
|
|
21
|
+
|
|
22
|
+
if ( coord.x >= 1.0 ) {
|
|
23
|
+
|
|
24
|
+
gl_FragDepthEXT = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r;
|
|
25
|
+
|
|
26
|
+
} else {
|
|
27
|
+
|
|
28
|
+
gl_FragDepthEXT = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r;
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}`;
|
|
33
|
+
|
|
34
|
+
class WebXRDepthSensing {
|
|
35
|
+
|
|
36
|
+
constructor() {
|
|
37
|
+
|
|
38
|
+
this.texture = null;
|
|
39
|
+
this.mesh = null;
|
|
40
|
+
|
|
41
|
+
this.depthNear = 0;
|
|
42
|
+
this.depthFar = 0;
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
init( renderer, depthData, renderState ) {
|
|
47
|
+
|
|
48
|
+
if ( this.texture === null ) {
|
|
49
|
+
|
|
50
|
+
const texture = new Texture();
|
|
51
|
+
|
|
52
|
+
const texProps = renderer.properties.get( texture );
|
|
53
|
+
texProps.__webglTexture = depthData.texture;
|
|
54
|
+
|
|
55
|
+
if ( ( depthData.depthNear != renderState.depthNear ) || ( depthData.depthFar != renderState.depthFar ) ) {
|
|
56
|
+
|
|
57
|
+
this.depthNear = depthData.depthNear;
|
|
58
|
+
this.depthFar = depthData.depthFar;
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this.texture = texture;
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
render( renderer, cameraXR ) {
|
|
69
|
+
|
|
70
|
+
if ( this.texture !== null ) {
|
|
71
|
+
|
|
72
|
+
if ( this.mesh === null ) {
|
|
73
|
+
|
|
74
|
+
const viewport = cameraXR.cameras[ 0 ].viewport;
|
|
75
|
+
const material = new ShaderMaterial( {
|
|
76
|
+
extensions: { fragDepth: true },
|
|
77
|
+
vertexShader: _occlusion_vertex,
|
|
78
|
+
fragmentShader: _occlusion_fragment,
|
|
79
|
+
uniforms: {
|
|
80
|
+
depthColor: { value: this.texture },
|
|
81
|
+
depthWidth: { value: viewport.z },
|
|
82
|
+
depthHeight: { value: viewport.w }
|
|
83
|
+
}
|
|
84
|
+
} );
|
|
85
|
+
|
|
86
|
+
this.mesh = new Mesh( new PlaneGeometry( 20, 20 ), material );
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
renderer.render( this.mesh, cameraXR );
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
reset() {
|
|
97
|
+
|
|
98
|
+
this.texture = null;
|
|
99
|
+
this.mesh = null;
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { WebXRDepthSensing };
|