super-three 0.154.1 → 0.156.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 (172) hide show
  1. package/build/three.cjs +360 -160
  2. package/build/three.js +360 -160
  3. package/build/three.min.js +1 -1
  4. package/build/three.module.js +355 -161
  5. package/build/three.module.min.js +1 -1
  6. package/examples/jsm/controls/OrbitControls.js +155 -25
  7. package/examples/jsm/csm/CSMShader.js +35 -1
  8. package/examples/jsm/environments/RoomEnvironment.js +1 -1
  9. package/examples/jsm/exporters/USDZExporter.js +1 -0
  10. package/examples/jsm/interactive/SelectionHelper.js +7 -0
  11. package/examples/jsm/libs/tween.module.js +790 -735
  12. package/examples/jsm/libs/utif.module.js +1644 -1558
  13. package/examples/jsm/loaders/DDSLoader.js +46 -3
  14. package/examples/jsm/loaders/EXRLoader.js +4 -4
  15. package/examples/jsm/loaders/FBXLoader.js +3 -1
  16. package/examples/jsm/loaders/GLTFLoader.js +25 -10
  17. package/examples/jsm/loaders/KTX2Loader.js +128 -79
  18. package/examples/jsm/loaders/LDrawLoader.js +1 -1
  19. package/examples/jsm/loaders/LogLuvLoader.js +2 -2
  20. package/examples/jsm/loaders/MMDLoader.js +10 -7
  21. package/examples/jsm/loaders/NRRDLoader.js +3 -3
  22. package/examples/jsm/loaders/PLYLoader.js +1 -1
  23. package/examples/jsm/loaders/RGBELoader.js +48 -66
  24. package/examples/jsm/loaders/STLLoader.js +7 -0
  25. package/examples/jsm/loaders/TGALoader.js +10 -10
  26. package/examples/jsm/loaders/VRMLLoader.js +1 -1
  27. package/examples/jsm/misc/GPUComputationRenderer.js +0 -9
  28. package/examples/jsm/misc/Volume.js +4 -6
  29. package/examples/jsm/nodes/Nodes.js +8 -6
  30. package/examples/jsm/nodes/accessors/BufferAttributeNode.js +29 -3
  31. package/examples/jsm/nodes/accessors/CubeTextureNode.js +20 -3
  32. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +15 -4
  33. package/examples/jsm/nodes/accessors/InstanceNode.js +8 -8
  34. package/examples/jsm/nodes/accessors/LineMaterialNode.js +31 -0
  35. package/examples/jsm/nodes/accessors/MaterialNode.js +73 -61
  36. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +3 -0
  37. package/examples/jsm/nodes/accessors/Object3DNode.js +2 -2
  38. package/examples/jsm/nodes/accessors/SceneNode.js +6 -0
  39. package/examples/jsm/nodes/accessors/TextureNode.js +54 -9
  40. package/examples/jsm/nodes/accessors/TextureStoreNode.js +29 -0
  41. package/examples/jsm/nodes/core/AttributeNode.js +2 -2
  42. package/examples/jsm/nodes/core/LightingModel.js +7 -9
  43. package/examples/jsm/nodes/core/Node.js +28 -3
  44. package/examples/jsm/nodes/core/NodeBuilder.js +94 -12
  45. package/examples/jsm/nodes/core/NodeUniform.js +1 -1
  46. package/examples/jsm/nodes/core/OutputStructNode.js +58 -0
  47. package/examples/jsm/nodes/core/PropertyNode.js +6 -0
  48. package/examples/jsm/nodes/core/StackNode.js +4 -4
  49. package/examples/jsm/nodes/core/StructTypeNode.js +24 -0
  50. package/examples/jsm/nodes/display/BumpMapNode.js +77 -0
  51. package/examples/jsm/nodes/display/NormalMapNode.js +2 -2
  52. package/examples/jsm/nodes/display/ViewportNode.js +19 -5
  53. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +10 -2
  54. package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +13 -0
  55. package/examples/jsm/nodes/functions/PhongLightingModel.js +53 -14
  56. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +236 -97
  57. package/examples/jsm/nodes/geometry/RangeNode.js +2 -2
  58. package/examples/jsm/nodes/gpgpu/ComputeNode.js +13 -0
  59. package/examples/jsm/nodes/lighting/AONode.js +1 -1
  60. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +58 -20
  61. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +7 -10
  62. package/examples/jsm/nodes/lighting/EnvironmentNode.js +22 -12
  63. package/examples/jsm/nodes/lighting/HemisphereLightNode.js +1 -1
  64. package/examples/jsm/nodes/lighting/LightingContextNode.js +12 -9
  65. package/examples/jsm/nodes/lighting/PointLightNode.js +7 -10
  66. package/examples/jsm/nodes/lighting/SpotLightNode.js +7 -10
  67. package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +54 -0
  68. package/examples/jsm/nodes/materials/Materials.js +2 -0
  69. package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +34 -0
  70. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +2 -0
  71. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +2 -2
  72. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +19 -2
  73. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +2 -2
  74. package/examples/jsm/nodes/materials/NodeMaterial.js +61 -26
  75. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +2 -2
  76. package/examples/jsm/nodes/math/HashNode.js +35 -0
  77. package/examples/jsm/nodes/shadernode/ShaderNode.js +6 -2
  78. package/examples/jsm/nodes/utils/SplitNode.js +1 -1
  79. package/examples/jsm/objects/Reflector.js +1 -9
  80. package/examples/jsm/objects/Refractor.js +0 -8
  81. package/examples/jsm/offscreen/scene.js +0 -1
  82. package/examples/jsm/postprocessing/FilmPass.js +3 -5
  83. package/examples/jsm/postprocessing/MaskPass.js +4 -1
  84. package/examples/jsm/postprocessing/OutputPass.js +33 -14
  85. package/examples/jsm/postprocessing/RenderPass.js +30 -12
  86. package/examples/jsm/postprocessing/SAOPass.js +23 -98
  87. package/examples/jsm/postprocessing/SSAOPass.js +10 -30
  88. package/examples/jsm/postprocessing/UnrealBloomPass.js +21 -17
  89. package/examples/jsm/renderers/common/Backend.js +11 -8
  90. package/examples/jsm/renderers/common/Background.js +22 -20
  91. package/examples/jsm/renderers/common/Binding.js +14 -0
  92. package/examples/jsm/renderers/common/Bindings.js +7 -10
  93. package/examples/jsm/renderers/common/Geometries.js +1 -1
  94. package/examples/jsm/renderers/common/Pipelines.js +96 -47
  95. package/examples/jsm/renderers/common/RenderContext.js +1 -0
  96. package/examples/jsm/renderers/common/RenderContexts.js +41 -5
  97. package/examples/jsm/renderers/common/RenderList.js +12 -4
  98. package/examples/jsm/renderers/common/RenderObject.js +26 -6
  99. package/examples/jsm/renderers/common/RenderObjects.js +10 -7
  100. package/examples/jsm/renderers/common/Renderer.js +82 -42
  101. package/examples/jsm/renderers/common/SampledTexture.js +2 -1
  102. package/examples/jsm/renderers/common/Sampler.js +1 -1
  103. package/examples/jsm/renderers/common/StorageBuffer.js +1 -1
  104. package/examples/jsm/renderers/common/Textures.js +172 -20
  105. package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +2 -2
  106. package/examples/jsm/renderers/common/nodes/NodeSampler.js +1 -1
  107. package/examples/jsm/renderers/common/nodes/Nodes.js +58 -13
  108. package/examples/jsm/renderers/webgl/WebGLBackend.js +607 -0
  109. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +118 -17
  110. package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +84 -0
  111. package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +26 -0
  112. package/examples/jsm/renderers/webgl/utils/WebGLState.js +529 -0
  113. package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +199 -0
  114. package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +242 -0
  115. package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +340 -0
  116. package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodeBuilder.js +1 -1
  117. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +320 -84
  118. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +18 -2
  119. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +120 -66
  120. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +2 -2
  121. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +55 -36
  122. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +96 -5
  123. package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +24 -22
  124. package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +117 -139
  125. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +60 -142
  126. package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +7 -6
  127. package/examples/jsm/shaders/FilmShader.js +11 -54
  128. package/examples/jsm/shaders/OutputShader.js +19 -2
  129. package/examples/jsm/shaders/SAOShader.js +0 -13
  130. package/examples/jsm/shaders/SSAOShader.js +33 -26
  131. package/examples/jsm/utils/BufferGeometryUtils.js +13 -4
  132. package/examples/jsm/webxr/OculusHandPointerModel.js +2 -2
  133. package/package.json +2 -2
  134. package/src/Three.js +3 -0
  135. package/src/animation/PropertyBinding.js +1 -1
  136. package/src/audio/Audio.js +6 -0
  137. package/src/cameras/CubeCamera.js +1 -4
  138. package/src/constants.js +4 -1
  139. package/src/core/BufferAttribute.js +20 -0
  140. package/src/core/Object3D.js +2 -15
  141. package/src/core/RenderTarget.js +122 -0
  142. package/src/core/UniformsGroup.js +2 -2
  143. package/src/geometries/CapsuleGeometry.js +1 -1
  144. package/src/loaders/DataTextureLoader.js +19 -2
  145. package/src/materials/Material.js +2 -2
  146. package/src/math/Vector2.js +2 -2
  147. package/src/math/Vector3.js +3 -3
  148. package/src/math/Vector4.js +4 -4
  149. package/src/objects/Line.js +1 -1
  150. package/src/objects/Mesh.js +1 -1
  151. package/src/objects/Points.js +1 -1
  152. package/src/renderers/WebGLMultipleRenderTargets.js +0 -2
  153. package/src/renderers/WebGLRenderTarget.js +3 -110
  154. package/src/renderers/WebGLRenderer.js +83 -57
  155. package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +1 -2
  156. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +11 -1
  157. package/src/renderers/shaders/ShaderLib/background.glsl.js +8 -0
  158. package/src/renderers/webgl/WebGLBackground.js +5 -14
  159. package/src/renderers/webgl/WebGLGeometries.js +5 -1
  160. package/src/renderers/webgl/WebGLMaterials.js +1 -1
  161. package/src/renderers/webgl/WebGLProgram.js +2 -0
  162. package/src/renderers/webgl/WebGLPrograms.js +19 -3
  163. package/src/renderers/webgl/WebGLTextures.js +101 -16
  164. package/src/renderers/webgl/WebGLUtils.js +27 -20
  165. package/src/textures/CompressedCubeTexture.js +19 -0
  166. package/src/textures/Texture.js +2 -2
  167. package/src/utils.js +9 -1
  168. package/examples/jsm/nodes/functions/BSDF/BRDF_BlinnPhong.js +0 -30
  169. package/examples/jsm/renderers/common/RenderTarget.js +0 -15
  170. package/examples/jsm/renderers/common/nodes/NodeRender.js +0 -302
  171. /package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/SlotNode.js +0 -0
  172. /package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodes.js +0 -0
@@ -4,7 +4,7 @@ import {
4
4
 
5
5
  import {
6
6
  CubeTexture, Texture,
7
- NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter,
7
+ NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter,
8
8
  RepeatWrapping, MirroredRepeatWrapping,
9
9
  RGB_ETC2_Format, RGBA_ETC2_EAC_Format,
10
10
  RGBAFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, SRGBColorSpace, DepthFormat, DepthStencilFormat,
@@ -19,13 +19,13 @@ import WebGPUTextureMipmapUtils from './WebGPUTextureMipmapUtils.js';
19
19
 
20
20
  const _compareToWebGPU = {
21
21
  [ NeverCompare ]: 'never',
22
- [ AlwaysCompare ]: 'less',
23
- [ LessCompare ]: 'equal',
22
+ [ LessCompare ]: 'less',
23
+ [ EqualCompare ]: 'equal',
24
24
  [ LessEqualCompare ]: 'less-equal',
25
- [ EqualCompare ]: 'greater',
26
- [ GreaterEqualCompare ]: 'not-equal',
27
- [ GreaterCompare ]: 'greater-equal',
28
- [ NotEqualCompare ]: 'always'
25
+ [ GreaterCompare ]: 'greater',
26
+ [ GreaterEqualCompare ]: 'greater-equal',
27
+ [ AlwaysCompare ]: 'always',
28
+ [ NotEqualCompare ]: 'not-equal'
29
29
  };
30
30
 
31
31
  class WebGPUTextureUtils {
@@ -97,17 +97,26 @@ class WebGPUTextureUtils {
97
97
 
98
98
  }
99
99
 
100
- const { width, height, depth } = this._getSize( texture );
100
+ if ( options.needsMipmaps === undefined ) options.needsMipmaps = false;
101
+ if ( options.levels === undefined ) options.levels = 1;
102
+ if ( options.depth === undefined ) options.depth = 1;
103
+
104
+ const { width, height, depth, levels } = options;
101
105
 
102
- const needsMipmaps = this._needsMipmaps( texture );
103
106
  const dimension = this._getDimension( texture );
104
- const mipLevelCount = this._getMipLevelCount( texture, width, height, needsMipmaps );
105
107
  const format = texture.internalFormat || this._getFormat( texture );
106
- //const sampleCount = texture.isRenderTargetTexture || texture.isDepthTexture ? backend.utils.getSampleCount( renderContext ) : 1;
108
+
107
109
  const sampleCount = options.sampleCount !== undefined ? options.sampleCount : 1;
110
+ const primarySampleCount = texture.isRenderTargetTexture ? 1 : sampleCount;
108
111
 
109
112
  let usage = GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC;
110
113
 
114
+ if ( options.store === true ) {
115
+
116
+ usage |= GPUTextureUsage.STORAGE_BINDING;
117
+
118
+ }
119
+
111
120
  if ( texture.isCompressedTexture !== true ) {
112
121
 
113
122
  usage |= GPUTextureUsage.RENDER_ATTACHMENT;
@@ -121,8 +130,8 @@ class WebGPUTextureUtils {
121
130
  height: height,
122
131
  depthOrArrayLayers: depth,
123
132
  },
124
- mipLevelCount: mipLevelCount,
125
- sampleCount: sampleCount,
133
+ mipLevelCount: levels,
134
+ sampleCount: primarySampleCount,
126
135
  dimension: dimension,
127
136
  format: format,
128
137
  usage: usage
@@ -144,13 +153,31 @@ class WebGPUTextureUtils {
144
153
 
145
154
  } else {
146
155
 
156
+ if ( format === undefined ) {
157
+
158
+ console.warn( 'WebGPURenderer: Texture format not supported.' );
159
+
160
+ return this.createDefaultTexture( texture );
161
+
162
+ }
163
+
147
164
  textureData.texture = backend.device.createTexture( textureDescriptorGPU );
148
165
 
149
166
  }
150
167
 
168
+ if ( texture.isRenderTargetTexture && sampleCount > 1 ) {
169
+
170
+ const msaaTextureDescriptorGPU = Object.assign( {}, textureDescriptorGPU );
171
+
172
+ msaaTextureDescriptorGPU.label = msaaTextureDescriptorGPU.label + '-msaa';
173
+ msaaTextureDescriptorGPU.sampleCount = sampleCount;
174
+
175
+ textureData.msaaTexture = backend.device.createTexture( msaaTextureDescriptorGPU );
176
+
177
+ }
178
+
151
179
  textureData.initialized = true;
152
180
 
153
- textureData.needsMipmaps = needsMipmaps;
154
181
  textureData.textureDescriptorGPU = textureDescriptorGPU;
155
182
 
156
183
  }
@@ -162,6 +189,8 @@ class WebGPUTextureUtils {
162
189
 
163
190
  textureData.texture.destroy();
164
191
 
192
+ if ( textureData.msaaTexture !== undefined ) textureData.msaaTexture.destroy();
193
+
165
194
  backend.delete( texture );
166
195
 
167
196
  }
@@ -195,17 +224,20 @@ class WebGPUTextureUtils {
195
224
 
196
225
  }
197
226
 
198
- updateTexture( texture ) {
227
+ updateTexture( texture, options ) {
199
228
 
200
229
  const textureData = this.backend.get( texture );
201
230
 
202
- const { needsMipmaps, textureDescriptorGPU } = textureData;
231
+ const { textureDescriptorGPU } = textureData;
232
+
233
+ if ( texture.isRenderTargetTexture || ( textureDescriptorGPU === undefined /* unsupported texture format */ ) )
234
+ return;
203
235
 
204
236
  // transfer texture data
205
237
 
206
238
  if ( texture.isDataTexture || texture.isDataArrayTexture || texture.isData3DTexture ) {
207
239
 
208
- this._copyBufferToTexture( texture.image, textureData.texture, textureDescriptorGPU, needsMipmaps );
240
+ this._copyBufferToTexture( options.image, textureData.texture, textureDescriptorGPU );
209
241
 
210
242
  } else if ( texture.isCompressedTexture ) {
211
243
 
@@ -213,15 +245,7 @@ class WebGPUTextureUtils {
213
245
 
214
246
  } else if ( texture.isCubeTexture ) {
215
247
 
216
- if ( texture.image.length === 6 ) {
217
-
218
- this._copyCubeMapToTexture( texture.image, texture, textureData.texture, textureDescriptorGPU, needsMipmaps );
219
-
220
- }
221
-
222
- } else if ( texture.isRenderTargetTexture ) {
223
-
224
- if ( needsMipmaps === true ) this._generateMipmaps( textureData.texture, textureDescriptorGPU );
248
+ this._copyCubeMapToTexture( options.images, texture, textureData.texture, textureDescriptorGPU );
225
249
 
226
250
  } else if ( texture.isVideoTexture ) {
227
251
 
@@ -229,13 +253,9 @@ class WebGPUTextureUtils {
229
253
 
230
254
  textureData.externalTexture = video;
231
255
 
232
- } else if ( texture.image !== null ) {
233
-
234
- this._copyImageToTexture( texture.image, texture, textureData.texture, textureDescriptorGPU, needsMipmaps );
235
-
236
256
  } else {
237
257
 
238
- console.warn( 'WebGPUTextureUtils: Unable to update texture.' );
258
+ this._copyImageToTexture( options.image, textureData.texture );
239
259
 
240
260
  }
241
261
 
@@ -243,6 +263,8 @@ class WebGPUTextureUtils {
243
263
 
244
264
  textureData.version = texture.version;
245
265
 
266
+ if ( texture.onUpdate ) texture.onUpdate( texture );
267
+
246
268
  }
247
269
 
248
270
  async copyTextureToBuffer( texture, x, y, width, height ) {
@@ -309,7 +331,7 @@ class WebGPUTextureUtils {
309
331
  texture.minFilter = NearestFilter;
310
332
  texture.magFilter = NearestFilter;
311
333
 
312
- this.createTexture( texture );
334
+ this.createTexture( texture, { width: 1, height: 1 } );
313
335
 
314
336
  this.defaultTexture = defaultTexture = texture;
315
337
 
@@ -329,7 +351,7 @@ class WebGPUTextureUtils {
329
351
  texture.minFilter = NearestFilter;
330
352
  texture.magFilter = NearestFilter;
331
353
 
332
- this.createTexture( texture );
354
+ this.createTexture( texture, { width: 1, height: 1, depth: 6 } );
333
355
 
334
356
  this.defaultCubeTexture = defaultCubeTexture = texture;
335
357
 
@@ -339,33 +361,7 @@ class WebGPUTextureUtils {
339
361
 
340
362
  }
341
363
 
342
- _copyImageToTexture( image, texture, textureGPU, textureDescriptorGPU, needsMipmaps, originDepth ) {
343
-
344
- if ( this._isHTMLImage( image ) ) {
345
-
346
- this._getImageBitmapFromHTML( image, texture ).then( imageBitmap => {
347
-
348
- this._copyExternalImageToTexture( imageBitmap, textureGPU, textureDescriptorGPU, needsMipmaps, originDepth );
349
-
350
- } );
351
-
352
- } else {
353
-
354
- // assume ImageBitmap
355
-
356
- this._copyExternalImageToTexture( image, textureGPU, textureDescriptorGPU, needsMipmaps, originDepth );
357
-
358
- }
359
-
360
- }
361
-
362
- _isHTMLImage( image ) {
363
-
364
- return ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) || ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement );
365
-
366
- }
367
-
368
- _copyCubeMapToTexture( images, texture, textureGPU, textureDescriptorGPU, needsMipmaps ) {
364
+ _copyCubeMapToTexture( images, texture, textureGPU, textureDescriptorGPU ) {
369
365
 
370
366
  for ( let i = 0; i < 6; i ++ ) {
371
367
 
@@ -373,11 +369,11 @@ class WebGPUTextureUtils {
373
369
 
374
370
  if ( image.isDataTexture ) {
375
371
 
376
- this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, needsMipmaps, i );
372
+ this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, i );
377
373
 
378
374
  } else {
379
375
 
380
- this._copyImageToTexture( image, texture, textureGPU, textureDescriptorGPU, needsMipmaps, i );
376
+ this._copyImageToTexture( image, textureGPU, i );
381
377
 
382
378
  }
383
379
 
@@ -385,7 +381,7 @@ class WebGPUTextureUtils {
385
381
 
386
382
  }
387
383
 
388
- _copyExternalImageToTexture( image, textureGPU, textureDescriptorGPU, needsMipmaps, originDepth = 0 ) {
384
+ _copyImageToTexture( image, textureGPU, originDepth = 0 ) {
389
385
 
390
386
  const device = this.backend.device;
391
387
 
@@ -403,8 +399,6 @@ class WebGPUTextureUtils {
403
399
  }
404
400
  );
405
401
 
406
- if ( needsMipmaps ) this._generateMipmaps( textureGPU, textureDescriptorGPU, originDepth );
407
-
408
402
  }
409
403
 
410
404
  _generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer = 0 ) {
@@ -419,21 +413,7 @@ class WebGPUTextureUtils {
419
413
 
420
414
  }
421
415
 
422
- _getImageBitmapFromHTML( image, texture ) {
423
-
424
- const width = image.width;
425
- const height = image.height;
426
-
427
- const options = {};
428
-
429
- options.imageOrientation = ( texture.flipY === true ) ? 'flipY' : 'none';
430
- options.premultiplyAlpha = ( texture.premultiplyAlpha === true ) ? 'premultiply' : 'default';
431
-
432
- return createImageBitmap( image, 0, 0, width, height, options );
433
-
434
- }
435
-
436
- _copyBufferToTexture( image, textureGPU, textureDescriptorGPU, needsMipmaps, originDepth = 0 ) {
416
+ _copyBufferToTexture( image, textureGPU, textureDescriptorGPU, originDepth = 0 ) {
437
417
 
438
418
  // @TODO: Consider to use GPUCommandEncoder.copyBufferToTexture()
439
419
  // @TODO: Consider to support valid buffer layouts with other formats like RGB
@@ -462,8 +442,6 @@ class WebGPUTextureUtils {
462
442
  depthOrArrayLayers: ( image.depth !== undefined ) ? image.depth : 1
463
443
  } );
464
444
 
465
- if ( needsMipmaps === true ) this._generateMipmaps( textureGPU, textureDescriptorGPU, originDepth );
466
-
467
445
  }
468
446
 
469
447
  _copyCompressedBufferToTexture( mipmaps, textureGPU, textureDescriptorGPU ) {
@@ -573,44 +551,6 @@ class WebGPUTextureUtils {
573
551
 
574
552
  }
575
553
 
576
- _getSize( texture ) {
577
-
578
- const image = texture.image;
579
-
580
- let width, height, depth;
581
-
582
- if ( texture.isCubeTexture ) {
583
-
584
- const faceImage = image.length > 0 ? image[ 0 ].image || image[ 0 ] : null;
585
-
586
- width = faceImage ? faceImage.width : 1;
587
- height = faceImage ? faceImage.height : 1;
588
- depth = 6; // one image for each side of the cube map
589
-
590
- } else if ( image !== null ) {
591
-
592
- width = image.width;
593
- height = image.height;
594
- depth = ( image.depth !== undefined ) ? image.depth : 1;
595
-
596
- } else {
597
-
598
- width = height = depth = 1;
599
-
600
- }
601
-
602
- return { width, height, depth };
603
-
604
- }
605
-
606
- _needsMipmaps( texture ) {
607
-
608
- if ( this._isEnvironmentTexture( texture ) ) return true;
609
-
610
- return ( texture.isCompressedTexture !== true ) /*&& ( texture.generateMipmaps === true )*/ && ( texture.minFilter !== NearestFilter ) && ( texture.minFilter !== LinearFilter );
611
-
612
- }
613
-
614
554
  _getBytesPerTexel( format ) {
615
555
 
616
556
  if ( format === GPUTextureFormat.R8Unorm ) return 1;
@@ -679,28 +619,6 @@ class WebGPUTextureUtils {
679
619
 
680
620
  }
681
621
 
682
- _getMipLevelCount( texture, width, height, needsMipmaps ) {
683
-
684
- let mipLevelCount;
685
-
686
- if ( texture.isCompressedTexture ) {
687
-
688
- mipLevelCount = texture.mipmaps.length;
689
-
690
- } else if ( needsMipmaps ) {
691
-
692
- mipLevelCount = Math.floor( Math.log2( Math.max( width, height ) ) ) + 1;
693
-
694
- } else {
695
-
696
- mipLevelCount = 1; // a texture without mipmaps has a base mip (mipLevel 0)
697
-
698
- }
699
-
700
- return mipLevelCount;
701
-
702
- }
703
-
704
622
  _getFormat( texture ) {
705
623
 
706
624
  const format = texture.format;
@@ -40,9 +40,10 @@ class WebGPUUtils {
40
40
 
41
41
  let format;
42
42
 
43
- if ( renderContext.texture !== null ) {
43
+ if ( renderContext.textures !== null ) {
44
+
45
+ format = this.getTextureFormatGPU( renderContext.textures[ 0 ] );
44
46
 
45
- format = this.getTextureFormatGPU( renderContext.texture );
46
47
 
47
48
  } else {
48
49
 
@@ -56,9 +57,9 @@ class WebGPUUtils {
56
57
 
57
58
  getCurrentColorSpace( renderContext ) {
58
59
 
59
- if ( renderContext.texture !== null ) {
60
+ if ( renderContext.textures !== null ) {
60
61
 
61
- return renderContext.texture.colorSpace;
62
+ return renderContext.textures[ 0 ].colorSpace;
62
63
 
63
64
  }
64
65
 
@@ -77,9 +78,9 @@ class WebGPUUtils {
77
78
 
78
79
  getSampleCount( renderContext ) {
79
80
 
80
- if ( renderContext.texture !== null ) {
81
+ if ( renderContext.textures !== null ) {
81
82
 
82
- return 1;
83
+ return renderContext.sampleCount;
83
84
 
84
85
  }
85
86
 
@@ -1,23 +1,3 @@
1
- /**
2
- * Film grain & scanlines shader
3
- *
4
- * - ported from HLSL to WebGL / GLSL
5
- * https://web.archive.org/web/20210226214859/http://www.truevision3d.com/forums/showcase/staticnoise_colorblackwhite_scanline_shaders-t18698.0.html
6
- *
7
- * Screen Space Static Postprocessor
8
- *
9
- * Produces an analogue noise overlay similar to a film grain / TV static
10
- *
11
- * Original implementation and noise algorithm
12
- * Pat 'Hawthorne' Shearon
13
- *
14
- * Optimized scanlines + noise version with intensity scaling
15
- * Georg 'Leviathan' Steinrohder
16
- *
17
- * This version is provided under a Creative Commons Attribution 3.0 License
18
- * http://creativecommons.org/licenses/by/3.0/
19
- */
20
-
21
1
  const FilmShader = {
22
2
 
23
3
  name: 'FilmShader',
@@ -26,10 +6,8 @@ const FilmShader = {
26
6
 
27
7
  'tDiffuse': { value: null },
28
8
  'time': { value: 0.0 },
29
- 'nIntensity': { value: 0.5 },
30
- 'sIntensity': { value: 0.05 },
31
- 'sCount': { value: 4096 },
32
- 'grayscale': { value: 1 }
9
+ 'intensity': { value: 0.5 },
10
+ 'grayscale': { value: false }
33
11
 
34
12
  },
35
13
 
@@ -48,19 +26,9 @@ const FilmShader = {
48
26
 
49
27
  #include <common>
50
28
 
51
- // control parameter
52
- uniform float time;
53
-
29
+ uniform float intensity;
54
30
  uniform bool grayscale;
55
-
56
- // noise effect intensity value (0 = no effect, 1 = full effect)
57
- uniform float nIntensity;
58
-
59
- // scanlines effect intensity value (0 = no effect, 1 = full effect)
60
- uniform float sIntensity;
61
-
62
- // scanlines effect count value (0 = no effect, 4096 = full effect)
63
- uniform float sCount;
31
+ uniform float time;
64
32
 
65
33
  uniform sampler2D tDiffuse;
66
34
 
@@ -68,32 +36,21 @@ const FilmShader = {
68
36
 
69
37
  void main() {
70
38
 
71
- // sample the source
72
- vec4 cTextureScreen = texture2D( tDiffuse, vUv );
73
-
74
- // make some noise
75
- float dx = rand( vUv + time );
76
-
77
- // add noise
78
- vec3 cResult = cTextureScreen.rgb + cTextureScreen.rgb * clamp( 0.1 + dx, 0.0, 1.0 );
39
+ vec4 base = texture2D( tDiffuse, vUv );
79
40
 
80
- // get us a sine and cosine
81
- vec2 sc = vec2( sin( vUv.y * sCount ), cos( vUv.y * sCount ) );
41
+ float noise = rand( vUv + time );
82
42
 
83
- // add scanlines
84
- cResult += cTextureScreen.rgb * vec3( sc.x, sc.y, sc.x ) * sIntensity;
43
+ vec3 color = base.rgb + base.rgb * clamp( 0.1 + noise, 0.0, 1.0 );
85
44
 
86
- // interpolate between source and result by intensity
87
- cResult = cTextureScreen.rgb + clamp( nIntensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb );
45
+ color = mix( base.rgb, color, intensity );
88
46
 
89
- // convert to grayscale if desired
90
- if( grayscale ) {
47
+ if ( grayscale ) {
91
48
 
92
- cResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );
49
+ color = vec3( luminance( color ) ); // assuming linear-srgb
93
50
 
94
51
  }
95
52
 
96
- gl_FragColor = vec4( cResult, cTextureScreen.a );
53
+ gl_FragColor = vec4( color, base.a );
97
54
 
98
55
  }`,
99
56
 
@@ -1,3 +1,7 @@
1
+ import {
2
+ ShaderChunk
3
+ } from 'three';
4
+
1
5
  const OutputShader = {
2
6
 
3
7
  uniforms: {
@@ -8,6 +12,13 @@ const OutputShader = {
8
12
  },
9
13
 
10
14
  vertexShader: /* glsl */`
15
+ precision highp float;
16
+
17
+ uniform mat4 modelViewMatrix;
18
+ uniform mat4 projectionMatrix;
19
+
20
+ attribute vec3 position;
21
+ attribute vec2 uv;
11
22
 
12
23
  varying vec2 vUv;
13
24
 
@@ -19,10 +30,12 @@ const OutputShader = {
19
30
  }`,
20
31
 
21
32
  fragmentShader: /* glsl */`
33
+
34
+ precision highp float;
22
35
 
23
36
  uniform sampler2D tDiffuse;
24
37
 
25
- #include <tonemapping_pars_fragment>
38
+ ` + ShaderChunk[ 'tonemapping_pars_fragment' ] + ShaderChunk[ 'colorspace_pars_fragment' ] + `
26
39
 
27
40
  varying vec2 vUv;
28
41
 
@@ -52,7 +65,11 @@ const OutputShader = {
52
65
 
53
66
  // color space
54
67
 
55
- gl_FragColor = LinearTosRGB( gl_FragColor );
68
+ #ifdef SRGB_COLOR_SPACE
69
+
70
+ gl_FragColor = LinearTosRGB( gl_FragColor );
71
+
72
+ #endif
56
73
 
57
74
  }`
58
75
 
@@ -11,9 +11,7 @@ const SAOShader = {
11
11
  defines: {
12
12
  'NUM_SAMPLES': 7,
13
13
  'NUM_RINGS': 4,
14
- 'NORMAL_TEXTURE': 0,
15
14
  'DIFFUSE_TEXTURE': 0,
16
- 'DEPTH_PACKING': 1,
17
15
  'PERSPECTIVE_CAMERA': 1
18
16
  },
19
17
  uniforms: {
@@ -56,10 +54,7 @@ const SAOShader = {
56
54
  #endif
57
55
 
58
56
  uniform sampler2D tDepth;
59
-
60
- #if NORMAL_TEXTURE == 1
61
57
  uniform sampler2D tNormal;
62
- #endif
63
58
 
64
59
  uniform float cameraNear;
65
60
  uniform float cameraFar;
@@ -87,11 +82,7 @@ const SAOShader = {
87
82
  }
88
83
 
89
84
  float getDepth( const in vec2 screenPosition ) {
90
- #if DEPTH_PACKING == 1
91
- return unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );
92
- #else
93
85
  return texture2D( tDepth, screenPosition ).x;
94
- #endif
95
86
  }
96
87
 
97
88
  float getViewZ( const in float depth ) {
@@ -111,11 +102,7 @@ const SAOShader = {
111
102
  }
112
103
 
113
104
  vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPosition ) {
114
- #if NORMAL_TEXTURE == 1
115
105
  return unpackRGBToNormal( texture2D( tNormal, screenPosition ).xyz );
116
- #else
117
- return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );
118
- #endif
119
106
  }
120
107
 
121
108
  float scaleDividedByCameraFar;
@@ -19,7 +19,6 @@ const SSAOShader = {
19
19
 
20
20
  uniforms: {
21
21
 
22
- 'tDiffuse': { value: null },
23
22
  'tNormal': { value: null },
24
23
  'tDepth': { value: null },
25
24
  'tNoise': { value: null },
@@ -49,7 +48,6 @@ const SSAOShader = {
49
48
 
50
49
  fragmentShader: /* glsl */`
51
50
 
52
- uniform sampler2D tDiffuse;
53
51
  uniform sampler2D tNormal;
54
52
  uniform sampler2D tDepth;
55
53
  uniform sampler2D tNoise;
@@ -128,47 +126,56 @@ const SSAOShader = {
128
126
  void main() {
129
127
 
130
128
  float depth = getDepth( vUv );
131
- float viewZ = getViewZ( depth );
132
129
 
133
- vec3 viewPosition = getViewPosition( vUv, depth, viewZ );
134
- vec3 viewNormal = getViewNormal( vUv );
130
+ if ( depth == 1.0 ) {
131
+
132
+ gl_FragColor = vec4( 1.0 ); // don't influence background
133
+
134
+ } else {
135
+
136
+ float viewZ = getViewZ( depth );
137
+
138
+ vec3 viewPosition = getViewPosition( vUv, depth, viewZ );
139
+ vec3 viewNormal = getViewNormal( vUv );
135
140
 
136
- vec2 noiseScale = vec2( resolution.x / 4.0, resolution.y / 4.0 );
137
- vec3 random = vec3( texture2D( tNoise, vUv * noiseScale ).r );
141
+ vec2 noiseScale = vec2( resolution.x / 4.0, resolution.y / 4.0 );
142
+ vec3 random = vec3( texture2D( tNoise, vUv * noiseScale ).r );
138
143
 
139
- // compute matrix used to reorient a kernel vector
144
+ // compute matrix used to reorient a kernel vector
140
145
 
141
- vec3 tangent = normalize( random - viewNormal * dot( random, viewNormal ) );
142
- vec3 bitangent = cross( viewNormal, tangent );
143
- mat3 kernelMatrix = mat3( tangent, bitangent, viewNormal );
146
+ vec3 tangent = normalize( random - viewNormal * dot( random, viewNormal ) );
147
+ vec3 bitangent = cross( viewNormal, tangent );
148
+ mat3 kernelMatrix = mat3( tangent, bitangent, viewNormal );
144
149
 
145
- float occlusion = 0.0;
150
+ float occlusion = 0.0;
146
151
 
147
- for ( int i = 0; i < KERNEL_SIZE; i ++ ) {
152
+ for ( int i = 0; i < KERNEL_SIZE; i ++ ) {
148
153
 
149
- vec3 sampleVector = kernelMatrix * kernel[ i ]; // reorient sample vector in view space
150
- vec3 samplePoint = viewPosition + ( sampleVector * kernelRadius ); // calculate sample point
154
+ vec3 sampleVector = kernelMatrix * kernel[ i ]; // reorient sample vector in view space
155
+ vec3 samplePoint = viewPosition + ( sampleVector * kernelRadius ); // calculate sample point
151
156
 
152
- vec4 samplePointNDC = cameraProjectionMatrix * vec4( samplePoint, 1.0 ); // project point and calculate NDC
153
- samplePointNDC /= samplePointNDC.w;
157
+ vec4 samplePointNDC = cameraProjectionMatrix * vec4( samplePoint, 1.0 ); // project point and calculate NDC
158
+ samplePointNDC /= samplePointNDC.w;
154
159
 
155
- vec2 samplePointUv = samplePointNDC.xy * 0.5 + 0.5; // compute uv coordinates
160
+ vec2 samplePointUv = samplePointNDC.xy * 0.5 + 0.5; // compute uv coordinates
156
161
 
157
- float realDepth = getLinearDepth( samplePointUv ); // get linear depth from depth texture
158
- float sampleDepth = viewZToOrthographicDepth( samplePoint.z, cameraNear, cameraFar ); // compute linear depth of the sample view Z value
159
- float delta = sampleDepth - realDepth;
162
+ float realDepth = getLinearDepth( samplePointUv ); // get linear depth from depth texture
163
+ float sampleDepth = viewZToOrthographicDepth( samplePoint.z, cameraNear, cameraFar ); // compute linear depth of the sample view Z value
164
+ float delta = sampleDepth - realDepth;
160
165
 
161
- if ( delta > minDistance && delta < maxDistance ) { // if fragment is before sample point, increase occlusion
166
+ if ( delta > minDistance && delta < maxDistance ) { // if fragment is before sample point, increase occlusion
162
167
 
163
- occlusion += 1.0;
168
+ occlusion += 1.0;
169
+
170
+ }
164
171
 
165
172
  }
166
173
 
167
- }
174
+ occlusion = clamp( occlusion / float( KERNEL_SIZE ), 0.0, 1.0 );
168
175
 
169
- occlusion = clamp( occlusion / float( KERNEL_SIZE ), 0.0, 1.0 );
176
+ gl_FragColor = vec4( vec3( 1.0 - occlusion ), 1.0 );
170
177
 
171
- gl_FragColor = vec4( vec3( 1.0 - occlusion ), 1.0 );
178
+ }
172
179
 
173
180
  }`
174
181