super-three 0.172.0 → 0.173.1
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 +439 -380
- package/build/three.core.js +413 -41
- package/build/three.core.min.js +2 -2
- package/build/three.module.js +28 -344
- package/build/three.module.min.js +2 -2
- package/build/three.tsl.js +11 -3
- package/build/three.tsl.min.js +2 -2
- package/build/three.webgpu.js +7550 -1798
- package/build/three.webgpu.min.js +2 -2
- package/build/three.webgpu.nodes.js +7551 -1798
- package/build/three.webgpu.nodes.min.js +2 -2
- package/examples/jsm/animation/CCDIKSolver.js +6 -5
- package/examples/jsm/capabilities/WebGPU.js +1 -1
- package/examples/jsm/controls/ArcballControls.js +23 -21
- package/examples/jsm/exporters/GLTFExporter.js +26 -25
- package/examples/jsm/geometries/TextGeometry.js +1 -12
- package/examples/jsm/interactive/InteractiveGroup.js +108 -51
- package/examples/jsm/libs/demuxer_mp4.js +109 -0
- package/examples/jsm/loaders/GCodeLoader.js +3 -1
- package/examples/jsm/loaders/GLTFLoader.js +0 -2
- package/examples/jsm/loaders/TDSLoader.js +0 -1
- package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
- package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
- package/examples/jsm/misc/ProgressiveLightMap.js +4 -3
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +4 -3
- package/examples/jsm/misc/Volume.js +7 -5
- package/examples/jsm/misc/VolumeSlice.js +5 -3
- package/examples/jsm/objects/WaterMesh.js +25 -20
- package/examples/jsm/physics/JoltPhysics.js +7 -7
- package/examples/jsm/physics/RapierPhysics.js +4 -4
- package/examples/jsm/postprocessing/EffectComposer.js +23 -2
- package/examples/jsm/postprocessing/OutputPass.js +2 -0
- package/examples/jsm/postprocessing/Pass.js +6 -1
- package/examples/jsm/shaders/OutputShader.js +5 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
- package/examples/jsm/transpiler/TSLEncoder.js +2 -0
- package/package.json +1 -1
- package/src/Three.Core.js +2 -0
- package/src/Three.TSL.js +9 -1
- package/src/cameras/ArrayCamera.js +1 -0
- package/src/constants.js +6 -1
- package/src/core/BufferAttribute.js +4 -0
- package/src/core/EventDispatcher.js +8 -6
- package/src/extras/ImageUtils.js +1 -11
- package/src/loaders/nodes/NodeObjectLoader.js +1 -1
- package/src/materials/nodes/MeshBasicNodeMaterial.js +1 -1
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +1 -1
- package/src/materials/nodes/NodeMaterial.js +5 -5
- package/src/materials/nodes/NodeMaterials.js +0 -1
- package/src/materials/nodes/PointsNodeMaterial.js +109 -7
- package/src/materials/nodes/SpriteNodeMaterial.js +1 -1
- package/src/materials/nodes/VolumeNodeMaterial.js +3 -3
- package/src/materials/nodes/manager/NodeMaterialObserver.js +8 -0
- package/src/nodes/Nodes.js +4 -0
- package/src/nodes/TSL.js +4 -0
- package/src/nodes/accessors/Arrays.js +30 -8
- package/src/nodes/accessors/BatchNode.js +3 -3
- package/src/nodes/accessors/BufferAttributeNode.js +1 -1
- package/src/nodes/accessors/Camera.js +64 -3
- package/src/nodes/accessors/InstanceNode.js +1 -1
- package/src/nodes/accessors/MaterialNode.js +9 -9
- package/src/nodes/accessors/ModelViewProjectionNode.js +1 -1
- package/src/nodes/accessors/Normal.js +6 -2
- package/src/nodes/accessors/Object3DNode.js +0 -1
- package/src/nodes/accessors/Position.js +6 -6
- package/src/nodes/accessors/ReferenceBaseNode.js +2 -4
- package/src/nodes/accessors/ReferenceNode.js +2 -3
- package/src/nodes/accessors/StorageBufferNode.js +42 -5
- package/src/nodes/accessors/Tangent.js +2 -2
- package/src/nodes/accessors/Texture3DNode.js +1 -1
- package/src/nodes/accessors/TextureNode.js +12 -5
- package/src/nodes/accessors/UniformArrayNode.js +9 -3
- package/src/nodes/accessors/VelocityNode.js +0 -2
- package/src/nodes/code/ScriptableNode.js +3 -3
- package/src/nodes/core/ArrayNode.js +125 -0
- package/src/nodes/core/ConstNode.js +8 -0
- package/src/nodes/core/Node.js +14 -1
- package/src/nodes/core/NodeBuilder.js +229 -19
- package/src/nodes/core/NodeUtils.js +11 -1
- package/src/nodes/core/NodeVar.js +17 -1
- package/src/nodes/core/OutputStructNode.js +19 -9
- package/src/nodes/core/StackNode.js +20 -1
- package/src/nodes/core/StructNode.js +121 -0
- package/src/nodes/core/StructType.js +13 -0
- package/src/nodes/core/StructTypeNode.js +82 -21
- package/src/nodes/core/TempNode.js +1 -1
- package/src/nodes/core/VarNode.js +94 -7
- package/src/nodes/core/VaryingNode.js +19 -3
- package/src/nodes/display/BlendModes.js +88 -1
- package/src/nodes/display/BumpMapNode.js +6 -6
- package/src/nodes/display/NormalMapNode.js +6 -6
- package/src/nodes/display/PassNode.js +3 -1
- package/src/nodes/display/ScreenNode.js +9 -0
- package/src/nodes/fog/Fog.js +17 -0
- package/src/nodes/gpgpu/AtomicFunctionNode.js +20 -4
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +8 -0
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +1 -1
- package/src/nodes/lighting/ShadowNode.js +1 -1
- package/src/nodes/math/ConditionalNode.js +8 -1
- package/src/nodes/math/MathNode.js +14 -1
- package/src/nodes/math/OperatorNode.js +96 -18
- package/src/nodes/pmrem/PMREMUtils.js +1 -1
- package/src/nodes/shapes/Shapes.js +33 -0
- package/src/nodes/tsl/TSLBase.js +1 -0
- package/src/nodes/tsl/TSLCore.js +22 -2
- package/src/nodes/utils/ArrayElementNode.js +1 -1
- package/src/nodes/utils/LoopNode.js +8 -1
- package/src/nodes/utils/MemberNode.js +68 -0
- package/src/nodes/utils/StorageArrayElementNode.js +14 -0
- package/src/nodes/utils/Timer.js +21 -0
- package/src/objects/BatchedMesh.js +1 -1
- package/src/objects/Line.js +6 -6
- package/src/renderers/WebGLRenderer.js +7 -0
- package/src/renderers/common/Animation.js +23 -1
- package/src/renderers/common/Backend.js +58 -15
- package/src/renderers/common/Background.js +14 -0
- package/src/renderers/common/Binding.js +1 -1
- package/src/renderers/common/BufferUtils.js +1 -1
- package/src/renderers/common/BundleGroup.js +1 -1
- package/src/renderers/common/ChainMap.js +9 -7
- package/src/renderers/common/ClippingContext.js +1 -1
- package/src/renderers/common/Color4.js +7 -3
- package/src/renderers/common/Geometries.js +2 -23
- package/src/renderers/common/Info.js +1 -45
- package/src/renderers/common/Lighting.js +8 -6
- package/src/renderers/common/Pipelines.js +3 -3
- package/src/renderers/common/PostProcessing.js +24 -8
- package/src/renderers/common/QuadMesh.js +1 -1
- package/src/renderers/common/RenderBundles.js +9 -3
- package/src/renderers/common/RenderContext.js +37 -3
- package/src/renderers/common/RenderContexts.js +30 -17
- package/src/renderers/common/RenderList.js +2 -2
- package/src/renderers/common/RenderLists.js +9 -3
- package/src/renderers/common/RenderObject.js +76 -17
- package/src/renderers/common/RenderObjects.js +9 -7
- package/src/renderers/common/Renderer.js +86 -67
- package/src/renderers/common/SampledTexture.js +0 -1
- package/src/renderers/common/StorageBufferAttribute.js +1 -1
- package/src/renderers/common/StorageInstancedBufferAttribute.js +1 -1
- package/src/renderers/common/StorageTexture.js +1 -1
- package/src/renderers/common/Textures.js +14 -7
- package/src/renderers/common/TimestampQueryPool.js +39 -0
- package/src/renderers/common/Uniform.js +37 -1
- package/src/renderers/common/UniformsGroup.js +2 -0
- package/src/renderers/common/XRManager.js +1193 -0
- package/src/renderers/common/XRRenderTarget.js +74 -0
- package/src/renderers/common/extras/PMREMGenerator.js +53 -8
- package/src/renderers/common/nodes/NodeBuilderState.js +4 -4
- package/src/renderers/common/nodes/NodeLibrary.js +5 -5
- package/src/renderers/common/nodes/NodeSampledTexture.js +0 -1
- package/src/renderers/common/nodes/NodeUniform.js +54 -2
- package/src/renderers/common/nodes/Nodes.js +25 -18
- package/src/renderers/webgl/WebGLBackground.js +4 -0
- package/src/renderers/webgl-fallback/WebGLBackend.js +295 -110
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +347 -17
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +57 -0
- package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
- package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +323 -11
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +167 -21
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +359 -0
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
- package/src/renderers/webgpu/WebGPUBackend.js +132 -149
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +6 -4
- package/src/renderers/webgpu/WebGPURenderer.js +5 -4
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +615 -41
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +85 -6
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +85 -0
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +102 -3
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +98 -1
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +257 -9
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +274 -0
- package/src/renderers/webgpu/utils/WebGPUUtils.js +86 -4
- package/src/renderers/webxr/WebXRManager.js +13 -2
- package/src/textures/VideoFrameTexture.js +35 -0
- package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -176
- package/examples/jsm/objects/InstancedPoints.js +0 -19
- package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -209
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -37
|
@@ -45,39 +45,109 @@ precision highp isampler2DArray;
|
|
|
45
45
|
precision lowp sampler2DShadow;
|
|
46
46
|
`;
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* A node builder targeting GLSL.
|
|
50
|
+
*
|
|
51
|
+
* This module generates GLSL shader code from node materials and also
|
|
52
|
+
* generates the respective bindings and vertex buffer definitions. These
|
|
53
|
+
* data are later used by the renderer to create render and compute pipelines
|
|
54
|
+
* for render objects.
|
|
55
|
+
*
|
|
56
|
+
* @augments NodeBuilder
|
|
57
|
+
*/
|
|
48
58
|
class GLSLNodeBuilder extends NodeBuilder {
|
|
49
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Constructs a new GLSL node builder renderer.
|
|
62
|
+
*
|
|
63
|
+
* @param {Object3D} object - The 3D object.
|
|
64
|
+
* @param {Renderer} renderer - The renderer.
|
|
65
|
+
*/
|
|
50
66
|
constructor( object, renderer ) {
|
|
51
67
|
|
|
52
68
|
super( object, renderer, new GLSLNodeParser() );
|
|
53
69
|
|
|
70
|
+
/**
|
|
71
|
+
* A dictionary holds for each shader stage ('vertex', 'fragment', 'compute')
|
|
72
|
+
* another dictionary which manages UBOs per group ('render','frame','object').
|
|
73
|
+
*
|
|
74
|
+
* @type {Object<String,Object<String,NodeUniformsGroup>>}
|
|
75
|
+
*/
|
|
54
76
|
this.uniformGroups = {};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* An array that holds objects defining the varying and attribute data in
|
|
80
|
+
* context of Transform Feedback.
|
|
81
|
+
*
|
|
82
|
+
* @type {Object<String,Map<String,Object>>}
|
|
83
|
+
*/
|
|
55
84
|
this.transforms = [];
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A dictionary that holds for each shader stage a Map of used extensions.
|
|
88
|
+
*
|
|
89
|
+
* @type {Object<String,Map<String,Object>>}
|
|
90
|
+
*/
|
|
56
91
|
this.extensions = {};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* A dictionary that holds for each shader stage an Array of used builtins.
|
|
95
|
+
*
|
|
96
|
+
* @type {Object<String,Array<String>>}
|
|
97
|
+
*/
|
|
57
98
|
this.builtins = { vertex: [], fragment: [], compute: [] };
|
|
58
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Whether comparison in shader code are generated with methods or not.
|
|
102
|
+
*
|
|
103
|
+
* @type {Boolean}
|
|
104
|
+
* @default true
|
|
105
|
+
*/
|
|
59
106
|
this.useComparisonMethod = true;
|
|
60
107
|
|
|
61
108
|
}
|
|
62
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Checks if the given texture requires a manual conversion to the working color space.
|
|
112
|
+
*
|
|
113
|
+
* @param {Texture} texture - The texture to check.
|
|
114
|
+
* @return {Boolean} Whether the given texture requires a conversion to working color space or not.
|
|
115
|
+
*/
|
|
63
116
|
needsToWorkingColorSpace( texture ) {
|
|
64
117
|
|
|
65
118
|
return texture.isVideoTexture === true && texture.colorSpace !== NoColorSpace;
|
|
66
119
|
|
|
67
120
|
}
|
|
68
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Returns the native shader method name for a given generic name.
|
|
124
|
+
*
|
|
125
|
+
* @param {String} method - The method name to resolve.
|
|
126
|
+
* @return {String} The resolved GLSL method name.
|
|
127
|
+
*/
|
|
69
128
|
getMethod( method ) {
|
|
70
129
|
|
|
71
130
|
return glslMethods[ method ] || method;
|
|
72
131
|
|
|
73
132
|
}
|
|
74
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Returns the output struct name. Not relevant for GLSL.
|
|
136
|
+
*
|
|
137
|
+
* @return {String}
|
|
138
|
+
*/
|
|
75
139
|
getOutputStructName() {
|
|
76
140
|
|
|
77
141
|
return '';
|
|
78
142
|
|
|
79
143
|
}
|
|
80
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Builds the given shader node.
|
|
147
|
+
*
|
|
148
|
+
* @param {ShaderNodeInternal} shaderNode - The shader node.
|
|
149
|
+
* @return {String} The GLSL function code.
|
|
150
|
+
*/
|
|
81
151
|
buildFunctionCode( shaderNode ) {
|
|
82
152
|
|
|
83
153
|
const layout = shaderNode.layout;
|
|
@@ -108,6 +178,12 @@ ${ flowData.code }
|
|
|
108
178
|
|
|
109
179
|
}
|
|
110
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Setups the Pixel Buffer Object (PBO) for the given storage
|
|
183
|
+
* buffer node.
|
|
184
|
+
*
|
|
185
|
+
* @param {StorageBufferNode} storageBufferNode - The storage buffer node.
|
|
186
|
+
*/
|
|
111
187
|
setupPBO( storageBufferNode ) {
|
|
112
188
|
|
|
113
189
|
const attribute = storageBufferNode.value;
|
|
@@ -176,6 +252,13 @@ ${ flowData.code }
|
|
|
176
252
|
|
|
177
253
|
}
|
|
178
254
|
|
|
255
|
+
/**
|
|
256
|
+
* Returns a GLSL snippet that represents the property name of the given node.
|
|
257
|
+
*
|
|
258
|
+
* @param {Node} node - The node.
|
|
259
|
+
* @param {String} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
260
|
+
* @return {String} The property name.
|
|
261
|
+
*/
|
|
179
262
|
getPropertyName( node, shaderStage = this.shaderStage ) {
|
|
180
263
|
|
|
181
264
|
if ( node.isNodeUniform && node.node.isTextureNode !== true && node.node.isBufferNode !== true ) {
|
|
@@ -188,6 +271,13 @@ ${ flowData.code }
|
|
|
188
271
|
|
|
189
272
|
}
|
|
190
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Setups the Pixel Buffer Object (PBO) for the given storage
|
|
276
|
+
* buffer node.
|
|
277
|
+
*
|
|
278
|
+
* @param {StorageArrayElementNode} storageArrayElementNode - The storage array element node.
|
|
279
|
+
* @return {String} The property name.
|
|
280
|
+
*/
|
|
191
281
|
generatePBO( storageArrayElementNode ) {
|
|
192
282
|
|
|
193
283
|
const { node, indexNode } = storageArrayElementNode;
|
|
@@ -270,6 +360,16 @@ ${ flowData.code }
|
|
|
270
360
|
|
|
271
361
|
}
|
|
272
362
|
|
|
363
|
+
/**
|
|
364
|
+
* Generates the GLSL snippet that reads a single texel from a texture without sampling or filtering.
|
|
365
|
+
*
|
|
366
|
+
* @param {Texture} texture - The texture.
|
|
367
|
+
* @param {String} textureProperty - The name of the texture uniform in the shader.
|
|
368
|
+
* @param {String} uvIndexSnippet - A GLSL snippet that represents texture coordinates used for sampling.
|
|
369
|
+
* @param {String?} depthSnippet - A GLSL snippet that represents the 0-based texture array index to sample.
|
|
370
|
+
* @param {String} [levelSnippet='0u'] - A GLSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
371
|
+
* @return {String} The GLSL snippet.
|
|
372
|
+
*/
|
|
273
373
|
generateTextureLoad( texture, textureProperty, uvIndexSnippet, depthSnippet, levelSnippet = '0' ) {
|
|
274
374
|
|
|
275
375
|
if ( depthSnippet ) {
|
|
@@ -284,6 +384,15 @@ ${ flowData.code }
|
|
|
284
384
|
|
|
285
385
|
}
|
|
286
386
|
|
|
387
|
+
/**
|
|
388
|
+
* Generates the GLSL snippet for sampling/loading the given texture.
|
|
389
|
+
*
|
|
390
|
+
* @param {Texture} texture - The texture.
|
|
391
|
+
* @param {String} textureProperty - The name of the texture uniform in the shader.
|
|
392
|
+
* @param {String} uvSnippet - A GLSL snippet that represents texture coordinates used for sampling.
|
|
393
|
+
* @param {String?} depthSnippet - A GLSL snippet that represents the 0-based texture array index to sample.
|
|
394
|
+
* @return {String} The GLSL snippet.
|
|
395
|
+
*/
|
|
287
396
|
generateTexture( texture, textureProperty, uvSnippet, depthSnippet ) {
|
|
288
397
|
|
|
289
398
|
if ( texture.isDepthTexture ) {
|
|
@@ -300,24 +409,63 @@ ${ flowData.code }
|
|
|
300
409
|
|
|
301
410
|
}
|
|
302
411
|
|
|
412
|
+
/**
|
|
413
|
+
* Generates the GLSL snippet when sampling textures with explicit mip level.
|
|
414
|
+
*
|
|
415
|
+
* @param {Texture} texture - The texture.
|
|
416
|
+
* @param {String} textureProperty - The name of the texture uniform in the shader.
|
|
417
|
+
* @param {String} uvSnippet - A GLSL snippet that represents texture coordinates used for sampling.
|
|
418
|
+
* @param {String} levelSnippet - A GLSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
419
|
+
* @return {String} The GLSL snippet.
|
|
420
|
+
*/
|
|
303
421
|
generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet ) {
|
|
304
422
|
|
|
305
423
|
return `textureLod( ${ textureProperty }, ${ uvSnippet }, ${ levelSnippet } )`;
|
|
306
424
|
|
|
307
425
|
}
|
|
308
426
|
|
|
427
|
+
/**
|
|
428
|
+
* Generates the GLSL snippet when sampling textures with a bias to the mip level.
|
|
429
|
+
*
|
|
430
|
+
* @param {Texture} texture - The texture.
|
|
431
|
+
* @param {String} textureProperty - The name of the texture uniform in the shader.
|
|
432
|
+
* @param {String} uvSnippet - A GLSL snippet that represents texture coordinates used for sampling.
|
|
433
|
+
* @param {String} biasSnippet - A GLSL snippet that represents the bias to apply to the mip level before sampling.
|
|
434
|
+
* @return {String} The GLSL snippet.
|
|
435
|
+
*/
|
|
309
436
|
generateTextureBias( texture, textureProperty, uvSnippet, biasSnippet ) {
|
|
310
437
|
|
|
311
438
|
return `texture( ${ textureProperty }, ${ uvSnippet }, ${ biasSnippet } )`;
|
|
312
439
|
|
|
313
440
|
}
|
|
314
441
|
|
|
442
|
+
/**
|
|
443
|
+
* Generates the GLSL snippet for sampling/loading the given texture using explicit gradients.
|
|
444
|
+
*
|
|
445
|
+
* @param {Texture} texture - The texture.
|
|
446
|
+
* @param {String} textureProperty - The name of the texture uniform in the shader.
|
|
447
|
+
* @param {String} uvSnippet - A GLSL snippet that represents texture coordinates used for sampling.
|
|
448
|
+
* @param {Array<String>} gradSnippet - An array holding both gradient GLSL snippets.
|
|
449
|
+
* @return {String} The GLSL snippet.
|
|
450
|
+
*/
|
|
315
451
|
generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet ) {
|
|
316
452
|
|
|
317
453
|
return `textureGrad( ${ textureProperty }, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
|
|
318
454
|
|
|
319
455
|
}
|
|
320
456
|
|
|
457
|
+
/**
|
|
458
|
+
* Generates the GLSL snippet for sampling a depth texture and comparing the sampled depth values
|
|
459
|
+
* against a reference value.
|
|
460
|
+
*
|
|
461
|
+
* @param {Texture} texture - The texture.
|
|
462
|
+
* @param {String} textureProperty - The name of the texture uniform in the shader.
|
|
463
|
+
* @param {String} uvSnippet - A GLSL snippet that represents texture coordinates used for sampling.
|
|
464
|
+
* @param {String} compareSnippet - A GLSL snippet that represents the reference value.
|
|
465
|
+
* @param {String?} depthSnippet - A GLSL snippet that represents 0-based texture array index to sample.
|
|
466
|
+
* @param {String} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
467
|
+
* @return {String} The GLSL snippet.
|
|
468
|
+
*/
|
|
321
469
|
generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet, shaderStage = this.shaderStage ) {
|
|
322
470
|
|
|
323
471
|
if ( shaderStage === 'fragment' ) {
|
|
@@ -332,6 +480,12 @@ ${ flowData.code }
|
|
|
332
480
|
|
|
333
481
|
}
|
|
334
482
|
|
|
483
|
+
/**
|
|
484
|
+
* Returns the variables of the given shader stage as a GLSL string.
|
|
485
|
+
*
|
|
486
|
+
* @param {String} shaderStage - The shader stage.
|
|
487
|
+
* @return {String} The GLSL snippet that defines the variables.
|
|
488
|
+
*/
|
|
335
489
|
getVars( shaderStage ) {
|
|
336
490
|
|
|
337
491
|
const snippets = [];
|
|
@@ -342,7 +496,7 @@ ${ flowData.code }
|
|
|
342
496
|
|
|
343
497
|
for ( const variable of vars ) {
|
|
344
498
|
|
|
345
|
-
snippets.push( `${ this.getVar( variable.type, variable.name ) };` );
|
|
499
|
+
snippets.push( `${ this.getVar( variable.type, variable.name, variable.count ) };` );
|
|
346
500
|
|
|
347
501
|
}
|
|
348
502
|
|
|
@@ -352,6 +506,12 @@ ${ flowData.code }
|
|
|
352
506
|
|
|
353
507
|
}
|
|
354
508
|
|
|
509
|
+
/**
|
|
510
|
+
* Returns the uniforms of the given shader stage as a GLSL string.
|
|
511
|
+
*
|
|
512
|
+
* @param {String} shaderStage - The shader stage.
|
|
513
|
+
* @return {String} The GLSL snippet that defines the uniforms.
|
|
514
|
+
*/
|
|
355
515
|
getUniforms( shaderStage ) {
|
|
356
516
|
|
|
357
517
|
const uniforms = this.uniforms[ shaderStage ];
|
|
@@ -469,6 +629,12 @@ ${ flowData.code }
|
|
|
469
629
|
|
|
470
630
|
}
|
|
471
631
|
|
|
632
|
+
/**
|
|
633
|
+
* Returns the type for a given buffer attribute.
|
|
634
|
+
*
|
|
635
|
+
* @param {BufferAttribute} attribute - The buffer attribute.
|
|
636
|
+
* @return {String} The type.
|
|
637
|
+
*/
|
|
472
638
|
getTypeFromAttribute( attribute ) {
|
|
473
639
|
|
|
474
640
|
let nodeType = super.getTypeFromAttribute( attribute );
|
|
@@ -493,6 +659,12 @@ ${ flowData.code }
|
|
|
493
659
|
|
|
494
660
|
}
|
|
495
661
|
|
|
662
|
+
/**
|
|
663
|
+
* Returns the shader attributes of the given shader stage as a GLSL string.
|
|
664
|
+
*
|
|
665
|
+
* @param {String} shaderStage - The shader stage.
|
|
666
|
+
* @return {String} The GLSL snippet that defines the shader attributes.
|
|
667
|
+
*/
|
|
496
668
|
getAttributes( shaderStage ) {
|
|
497
669
|
|
|
498
670
|
let snippet = '';
|
|
@@ -515,15 +687,19 @@ ${ flowData.code }
|
|
|
515
687
|
|
|
516
688
|
}
|
|
517
689
|
|
|
690
|
+
/**
|
|
691
|
+
* Returns the members of the given struct type node as a GLSL string.
|
|
692
|
+
*
|
|
693
|
+
* @param {StructTypeNode} struct - The struct type node.
|
|
694
|
+
* @return {String} The GLSL snippet that defines the struct members.
|
|
695
|
+
*/
|
|
518
696
|
getStructMembers( struct ) {
|
|
519
697
|
|
|
520
698
|
const snippets = [];
|
|
521
|
-
const members = struct.getMemberTypes();
|
|
522
699
|
|
|
523
|
-
for (
|
|
700
|
+
for ( const member of struct.members ) {
|
|
524
701
|
|
|
525
|
-
|
|
526
|
-
snippets.push( `layout( location = ${i} ) out ${ member} m${i};` );
|
|
702
|
+
snippets.push( `\t${ member.type } ${ member.name };` );
|
|
527
703
|
|
|
528
704
|
}
|
|
529
705
|
|
|
@@ -531,33 +707,57 @@ ${ flowData.code }
|
|
|
531
707
|
|
|
532
708
|
}
|
|
533
709
|
|
|
710
|
+
/**
|
|
711
|
+
* Returns the structs of the given shader stage as a GLSL string.
|
|
712
|
+
*
|
|
713
|
+
* @param {String} shaderStage - The shader stage.
|
|
714
|
+
* @return {String} The GLSL snippet that defines the structs.
|
|
715
|
+
*/
|
|
534
716
|
getStructs( shaderStage ) {
|
|
535
717
|
|
|
536
718
|
const snippets = [];
|
|
537
719
|
const structs = this.structs[ shaderStage ];
|
|
538
720
|
|
|
539
|
-
|
|
721
|
+
const outputSnippet = [];
|
|
540
722
|
|
|
541
|
-
|
|
723
|
+
for ( const struct of structs ) {
|
|
542
724
|
|
|
543
|
-
|
|
725
|
+
if ( struct.output ) {
|
|
726
|
+
|
|
727
|
+
for ( const member of struct.members ) {
|
|
728
|
+
|
|
729
|
+
outputSnippet.push( `layout( location = ${ member.index } ) out ${ member.type } ${ member.name };` );
|
|
730
|
+
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
} else {
|
|
734
|
+
|
|
735
|
+
let snippet = 'struct ' + struct.name + ' {\n';
|
|
736
|
+
snippet += this.getStructMembers( struct );
|
|
737
|
+
snippet += '\n};\n';
|
|
738
|
+
|
|
739
|
+
snippets.push( snippet );
|
|
544
740
|
|
|
545
|
-
|
|
741
|
+
}
|
|
546
742
|
|
|
547
|
-
|
|
743
|
+
}
|
|
548
744
|
|
|
549
|
-
|
|
550
|
-
snippet += this.getStructMembers( struct );
|
|
551
|
-
snippet += '\n';
|
|
745
|
+
if ( outputSnippet.length === 0 ) {
|
|
552
746
|
|
|
553
|
-
|
|
747
|
+
outputSnippet.push( 'layout( location = 0 ) out vec4 fragColor;' );
|
|
554
748
|
|
|
555
749
|
}
|
|
556
750
|
|
|
557
|
-
return
|
|
751
|
+
return '\n' + outputSnippet.join( '\n' ) + '\n\n' + snippets.join( '\n' );
|
|
558
752
|
|
|
559
753
|
}
|
|
560
754
|
|
|
755
|
+
/**
|
|
756
|
+
* Returns the varyings of the given shader stage as a GLSL string.
|
|
757
|
+
*
|
|
758
|
+
* @param {String} shaderStage - The shader stage.
|
|
759
|
+
* @return {String} The GLSL snippet that defines the varyings.
|
|
760
|
+
*/
|
|
561
761
|
getVaryings( shaderStage ) {
|
|
562
762
|
|
|
563
763
|
let snippet = '';
|
|
@@ -569,10 +769,20 @@ ${ flowData.code }
|
|
|
569
769
|
for ( const varying of varyings ) {
|
|
570
770
|
|
|
571
771
|
if ( shaderStage === 'compute' ) varying.needsInterpolation = true;
|
|
772
|
+
|
|
572
773
|
const type = this.getType( varying.type );
|
|
573
|
-
const flat = type.includes( 'int' ) || type.includes( 'uv' ) || type.includes( 'iv' ) ? 'flat ' : '';
|
|
574
774
|
|
|
575
|
-
|
|
775
|
+
if ( varying.needsInterpolation ) {
|
|
776
|
+
|
|
777
|
+
const flat = type.includes( 'int' ) || type.includes( 'uv' ) || type.includes( 'iv' ) ? 'flat ' : '';
|
|
778
|
+
|
|
779
|
+
snippet += `${flat} out ${type} ${varying.name};\n`;
|
|
780
|
+
|
|
781
|
+
} else {
|
|
782
|
+
|
|
783
|
+
snippet += `${type} ${varying.name};\n`; // generate variable (no varying required)
|
|
784
|
+
|
|
785
|
+
}
|
|
576
786
|
|
|
577
787
|
}
|
|
578
788
|
|
|
@@ -603,18 +813,33 @@ ${ flowData.code }
|
|
|
603
813
|
|
|
604
814
|
}
|
|
605
815
|
|
|
816
|
+
/**
|
|
817
|
+
* Returns the vertex index builtin.
|
|
818
|
+
*
|
|
819
|
+
* @return {String} The vertex index.
|
|
820
|
+
*/
|
|
606
821
|
getVertexIndex() {
|
|
607
822
|
|
|
608
823
|
return 'uint( gl_VertexID )';
|
|
609
824
|
|
|
610
825
|
}
|
|
611
826
|
|
|
827
|
+
/**
|
|
828
|
+
* Returns the instance index builtin.
|
|
829
|
+
*
|
|
830
|
+
* @return {String} The instance index.
|
|
831
|
+
*/
|
|
612
832
|
getInstanceIndex() {
|
|
613
833
|
|
|
614
834
|
return 'uint( gl_InstanceID )';
|
|
615
835
|
|
|
616
836
|
}
|
|
617
837
|
|
|
838
|
+
/**
|
|
839
|
+
* Returns the invocation local index builtin.
|
|
840
|
+
*
|
|
841
|
+
* @return {String} The invocation local index.
|
|
842
|
+
*/
|
|
618
843
|
getInvocationLocalIndex() {
|
|
619
844
|
|
|
620
845
|
const workgroupSize = this.object.workgroupSize;
|
|
@@ -625,6 +850,11 @@ ${ flowData.code }
|
|
|
625
850
|
|
|
626
851
|
}
|
|
627
852
|
|
|
853
|
+
/**
|
|
854
|
+
* Returns the draw index builtin.
|
|
855
|
+
*
|
|
856
|
+
* @return {String?} The drawIndex shader string. Returns `null` if `WEBGL_multi_draw` isn't supported by the device.
|
|
857
|
+
*/
|
|
628
858
|
getDrawIndex() {
|
|
629
859
|
|
|
630
860
|
const extensions = this.renderer.backend.extensions;
|
|
@@ -639,24 +869,46 @@ ${ flowData.code }
|
|
|
639
869
|
|
|
640
870
|
}
|
|
641
871
|
|
|
872
|
+
/**
|
|
873
|
+
* Returns the front facing builtin.
|
|
874
|
+
*
|
|
875
|
+
* @return {String} The front facing builtin.
|
|
876
|
+
*/
|
|
642
877
|
getFrontFacing() {
|
|
643
878
|
|
|
644
879
|
return 'gl_FrontFacing';
|
|
645
880
|
|
|
646
881
|
}
|
|
647
882
|
|
|
883
|
+
/**
|
|
884
|
+
* Returns the frag coord builtin.
|
|
885
|
+
*
|
|
886
|
+
* @return {String} The frag coord builtin.
|
|
887
|
+
*/
|
|
648
888
|
getFragCoord() {
|
|
649
889
|
|
|
650
890
|
return 'gl_FragCoord.xy';
|
|
651
891
|
|
|
652
892
|
}
|
|
653
893
|
|
|
894
|
+
/**
|
|
895
|
+
* Returns the frag depth builtin.
|
|
896
|
+
*
|
|
897
|
+
* @return {String} The frag depth builtin.
|
|
898
|
+
*/
|
|
654
899
|
getFragDepth() {
|
|
655
900
|
|
|
656
901
|
return 'gl_FragDepth';
|
|
657
902
|
|
|
658
903
|
}
|
|
659
904
|
|
|
905
|
+
/**
|
|
906
|
+
* Enables the given extension.
|
|
907
|
+
*
|
|
908
|
+
* @param {String} name - The extension name.
|
|
909
|
+
* @param {String} behavior - The extension behavior.
|
|
910
|
+
* @param {String} [shaderStage=this.shaderStage] - The shader stage.
|
|
911
|
+
*/
|
|
660
912
|
enableExtension( name, behavior, shaderStage = this.shaderStage ) {
|
|
661
913
|
|
|
662
914
|
const map = this.extensions[ shaderStage ] || ( this.extensions[ shaderStage ] = new Map() );
|
|
@@ -672,6 +924,12 @@ ${ flowData.code }
|
|
|
672
924
|
|
|
673
925
|
}
|
|
674
926
|
|
|
927
|
+
/**
|
|
928
|
+
* Returns the enabled extensions of the given shader stage as a GLSL string.
|
|
929
|
+
*
|
|
930
|
+
* @param {String} shaderStage - The shader stage.
|
|
931
|
+
* @return {String} The GLSL snippet that defines the enabled extensions.
|
|
932
|
+
*/
|
|
675
933
|
getExtensions( shaderStage ) {
|
|
676
934
|
|
|
677
935
|
const snippets = [];
|
|
@@ -705,12 +963,23 @@ ${ flowData.code }
|
|
|
705
963
|
|
|
706
964
|
}
|
|
707
965
|
|
|
966
|
+
/**
|
|
967
|
+
* Returns the clip distances builtin.
|
|
968
|
+
*
|
|
969
|
+
* @return {String} The clip distances builtin.
|
|
970
|
+
*/
|
|
708
971
|
getClipDistance() {
|
|
709
972
|
|
|
710
973
|
return 'gl_ClipDistance';
|
|
711
974
|
|
|
712
975
|
}
|
|
713
976
|
|
|
977
|
+
/**
|
|
978
|
+
* Whether the requested feature is available or not.
|
|
979
|
+
*
|
|
980
|
+
* @param {String} name - The requested feature.
|
|
981
|
+
* @return {Boolean} Whether the requested feature is supported or not.
|
|
982
|
+
*/
|
|
714
983
|
isAvailable( name ) {
|
|
715
984
|
|
|
716
985
|
let result = supports[ name ];
|
|
@@ -754,12 +1023,22 @@ ${ flowData.code }
|
|
|
754
1023
|
|
|
755
1024
|
}
|
|
756
1025
|
|
|
1026
|
+
/**
|
|
1027
|
+
* Whether to flip texture data along its vertical axis or not.
|
|
1028
|
+
*
|
|
1029
|
+
* @return {Boolean} Returns always `true` in context of GLSL.
|
|
1030
|
+
*/
|
|
757
1031
|
isFlipY() {
|
|
758
1032
|
|
|
759
1033
|
return true;
|
|
760
1034
|
|
|
761
1035
|
}
|
|
762
1036
|
|
|
1037
|
+
/**
|
|
1038
|
+
* Enables hardware clipping.
|
|
1039
|
+
*
|
|
1040
|
+
* @param {String} planeCount - The clipping plane count.
|
|
1041
|
+
*/
|
|
763
1042
|
enableHardwareClipping( planeCount ) {
|
|
764
1043
|
|
|
765
1044
|
this.enableExtension( 'GL_ANGLE_clip_cull_distance', 'require' );
|
|
@@ -768,12 +1047,24 @@ ${ flowData.code }
|
|
|
768
1047
|
|
|
769
1048
|
}
|
|
770
1049
|
|
|
1050
|
+
/**
|
|
1051
|
+
* Registers a transform in context of Transform Feedback.
|
|
1052
|
+
*
|
|
1053
|
+
* @param {String} varyingName - The varying name.
|
|
1054
|
+
* @param {AttributeNode} attributeNode - The attribute node.
|
|
1055
|
+
*/
|
|
771
1056
|
registerTransform( varyingName, attributeNode ) {
|
|
772
1057
|
|
|
773
1058
|
this.transforms.push( { varyingName, attributeNode } );
|
|
774
1059
|
|
|
775
1060
|
}
|
|
776
1061
|
|
|
1062
|
+
/**
|
|
1063
|
+
* Returns the transforms of the given shader stage as a GLSL string.
|
|
1064
|
+
*
|
|
1065
|
+
* @param {String} shaderStage - The shader stage.
|
|
1066
|
+
* @return {String} The GLSL snippet that defines the transforms.
|
|
1067
|
+
*/
|
|
777
1068
|
getTransforms( /* shaderStage */ ) {
|
|
778
1069
|
|
|
779
1070
|
const transforms = this.transforms;
|
|
@@ -794,6 +1085,14 @@ ${ flowData.code }
|
|
|
794
1085
|
|
|
795
1086
|
}
|
|
796
1087
|
|
|
1088
|
+
/**
|
|
1089
|
+
* Returns a GLSL struct based on the given name and variables.
|
|
1090
|
+
*
|
|
1091
|
+
* @private
|
|
1092
|
+
* @param {String} name - The struct name.
|
|
1093
|
+
* @param {String} vars - The struct variables.
|
|
1094
|
+
* @return {String} The GLSL snippet representing a struct.
|
|
1095
|
+
*/
|
|
797
1096
|
_getGLSLUniformStruct( name, vars ) {
|
|
798
1097
|
|
|
799
1098
|
return `
|
|
@@ -803,6 +1102,13 @@ ${vars}
|
|
|
803
1102
|
|
|
804
1103
|
}
|
|
805
1104
|
|
|
1105
|
+
/**
|
|
1106
|
+
* Returns a GLSL vertex shader based on the given shader data.
|
|
1107
|
+
*
|
|
1108
|
+
* @private
|
|
1109
|
+
* @param {Object} shaderData - The shader data.
|
|
1110
|
+
* @return {String} The vertex shader.
|
|
1111
|
+
*/
|
|
806
1112
|
_getGLSLVertexCode( shaderData ) {
|
|
807
1113
|
|
|
808
1114
|
return `#version 300 es
|
|
@@ -845,6 +1151,13 @@ void main() {
|
|
|
845
1151
|
|
|
846
1152
|
}
|
|
847
1153
|
|
|
1154
|
+
/**
|
|
1155
|
+
* Returns a GLSL fragment shader based on the given shader data.
|
|
1156
|
+
*
|
|
1157
|
+
* @private
|
|
1158
|
+
* @param {Object} shaderData - The shader data.
|
|
1159
|
+
* @return {String} The vertex shader.
|
|
1160
|
+
*/
|
|
848
1161
|
_getGLSLFragmentCode( shaderData ) {
|
|
849
1162
|
|
|
850
1163
|
return `#version 300 es
|
|
@@ -863,6 +1176,7 @@ ${shaderData.varyings}
|
|
|
863
1176
|
// codes
|
|
864
1177
|
${shaderData.codes}
|
|
865
1178
|
|
|
1179
|
+
// structs
|
|
866
1180
|
${shaderData.structs}
|
|
867
1181
|
|
|
868
1182
|
void main() {
|
|
@@ -878,6 +1192,9 @@ void main() {
|
|
|
878
1192
|
|
|
879
1193
|
}
|
|
880
1194
|
|
|
1195
|
+
/**
|
|
1196
|
+
* Controls the code build of the shader stages.
|
|
1197
|
+
*/
|
|
881
1198
|
buildCode() {
|
|
882
1199
|
|
|
883
1200
|
const shadersData = this.material !== null ? { fragment: {}, vertex: {} } : { compute: {} };
|
|
@@ -958,6 +1275,19 @@ void main() {
|
|
|
958
1275
|
|
|
959
1276
|
}
|
|
960
1277
|
|
|
1278
|
+
/**
|
|
1279
|
+
* This method is one of the more important ones since it's responsible
|
|
1280
|
+
* for generating a matching binding instance for the given uniform node.
|
|
1281
|
+
*
|
|
1282
|
+
* These bindings are later used in the renderer to create bind groups
|
|
1283
|
+
* and layouts.
|
|
1284
|
+
*
|
|
1285
|
+
* @param {UniformNode} node - The uniform node.
|
|
1286
|
+
* @param {String} type - The node data type.
|
|
1287
|
+
* @param {String} shaderStage - The shader stage.
|
|
1288
|
+
* @param {String?} [name=null] - An optional uniform name.
|
|
1289
|
+
* @return {NodeUniform} The node uniform object.
|
|
1290
|
+
*/
|
|
961
1291
|
getUniformFromNode( node, type, shaderStage, name = null ) {
|
|
962
1292
|
|
|
963
1293
|
const uniformNode = super.getUniformFromNode( node, type, shaderStage, name );
|