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.
- package/build/three.cjs +360 -160
- package/build/three.js +360 -160
- package/build/three.min.js +1 -1
- package/build/three.module.js +355 -161
- package/build/three.module.min.js +1 -1
- package/examples/jsm/controls/OrbitControls.js +155 -25
- package/examples/jsm/csm/CSMShader.js +35 -1
- package/examples/jsm/environments/RoomEnvironment.js +1 -1
- package/examples/jsm/exporters/USDZExporter.js +1 -0
- package/examples/jsm/interactive/SelectionHelper.js +7 -0
- package/examples/jsm/libs/tween.module.js +790 -735
- package/examples/jsm/libs/utif.module.js +1644 -1558
- package/examples/jsm/loaders/DDSLoader.js +46 -3
- package/examples/jsm/loaders/EXRLoader.js +4 -4
- package/examples/jsm/loaders/FBXLoader.js +3 -1
- package/examples/jsm/loaders/GLTFLoader.js +25 -10
- package/examples/jsm/loaders/KTX2Loader.js +128 -79
- package/examples/jsm/loaders/LDrawLoader.js +1 -1
- package/examples/jsm/loaders/LogLuvLoader.js +2 -2
- package/examples/jsm/loaders/MMDLoader.js +10 -7
- package/examples/jsm/loaders/NRRDLoader.js +3 -3
- package/examples/jsm/loaders/PLYLoader.js +1 -1
- package/examples/jsm/loaders/RGBELoader.js +48 -66
- package/examples/jsm/loaders/STLLoader.js +7 -0
- package/examples/jsm/loaders/TGALoader.js +10 -10
- package/examples/jsm/loaders/VRMLLoader.js +1 -1
- package/examples/jsm/misc/GPUComputationRenderer.js +0 -9
- package/examples/jsm/misc/Volume.js +4 -6
- package/examples/jsm/nodes/Nodes.js +8 -6
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +29 -3
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +20 -3
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +15 -4
- package/examples/jsm/nodes/accessors/InstanceNode.js +8 -8
- package/examples/jsm/nodes/accessors/LineMaterialNode.js +31 -0
- package/examples/jsm/nodes/accessors/MaterialNode.js +73 -61
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +3 -0
- package/examples/jsm/nodes/accessors/Object3DNode.js +2 -2
- package/examples/jsm/nodes/accessors/SceneNode.js +6 -0
- package/examples/jsm/nodes/accessors/TextureNode.js +54 -9
- package/examples/jsm/nodes/accessors/TextureStoreNode.js +29 -0
- package/examples/jsm/nodes/core/AttributeNode.js +2 -2
- package/examples/jsm/nodes/core/LightingModel.js +7 -9
- package/examples/jsm/nodes/core/Node.js +28 -3
- package/examples/jsm/nodes/core/NodeBuilder.js +94 -12
- package/examples/jsm/nodes/core/NodeUniform.js +1 -1
- package/examples/jsm/nodes/core/OutputStructNode.js +58 -0
- package/examples/jsm/nodes/core/PropertyNode.js +6 -0
- package/examples/jsm/nodes/core/StackNode.js +4 -4
- package/examples/jsm/nodes/core/StructTypeNode.js +24 -0
- package/examples/jsm/nodes/display/BumpMapNode.js +77 -0
- package/examples/jsm/nodes/display/NormalMapNode.js +2 -2
- package/examples/jsm/nodes/display/ViewportNode.js +19 -5
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +10 -2
- package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +13 -0
- package/examples/jsm/nodes/functions/PhongLightingModel.js +53 -14
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +236 -97
- package/examples/jsm/nodes/geometry/RangeNode.js +2 -2
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +13 -0
- package/examples/jsm/nodes/lighting/AONode.js +1 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +58 -20
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +7 -10
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +22 -12
- package/examples/jsm/nodes/lighting/HemisphereLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/LightingContextNode.js +12 -9
- package/examples/jsm/nodes/lighting/PointLightNode.js +7 -10
- package/examples/jsm/nodes/lighting/SpotLightNode.js +7 -10
- package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +54 -0
- package/examples/jsm/nodes/materials/Materials.js +2 -0
- package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +34 -0
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +2 -0
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +2 -2
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +19 -2
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +2 -2
- package/examples/jsm/nodes/materials/NodeMaterial.js +61 -26
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +2 -2
- package/examples/jsm/nodes/math/HashNode.js +35 -0
- package/examples/jsm/nodes/shadernode/ShaderNode.js +6 -2
- package/examples/jsm/nodes/utils/SplitNode.js +1 -1
- package/examples/jsm/objects/Reflector.js +1 -9
- package/examples/jsm/objects/Refractor.js +0 -8
- package/examples/jsm/offscreen/scene.js +0 -1
- package/examples/jsm/postprocessing/FilmPass.js +3 -5
- package/examples/jsm/postprocessing/MaskPass.js +4 -1
- package/examples/jsm/postprocessing/OutputPass.js +33 -14
- package/examples/jsm/postprocessing/RenderPass.js +30 -12
- package/examples/jsm/postprocessing/SAOPass.js +23 -98
- package/examples/jsm/postprocessing/SSAOPass.js +10 -30
- package/examples/jsm/postprocessing/UnrealBloomPass.js +21 -17
- package/examples/jsm/renderers/common/Backend.js +11 -8
- package/examples/jsm/renderers/common/Background.js +22 -20
- package/examples/jsm/renderers/common/Binding.js +14 -0
- package/examples/jsm/renderers/common/Bindings.js +7 -10
- package/examples/jsm/renderers/common/Geometries.js +1 -1
- package/examples/jsm/renderers/common/Pipelines.js +96 -47
- package/examples/jsm/renderers/common/RenderContext.js +1 -0
- package/examples/jsm/renderers/common/RenderContexts.js +41 -5
- package/examples/jsm/renderers/common/RenderList.js +12 -4
- package/examples/jsm/renderers/common/RenderObject.js +26 -6
- package/examples/jsm/renderers/common/RenderObjects.js +10 -7
- package/examples/jsm/renderers/common/Renderer.js +82 -42
- package/examples/jsm/renderers/common/SampledTexture.js +2 -1
- package/examples/jsm/renderers/common/Sampler.js +1 -1
- package/examples/jsm/renderers/common/StorageBuffer.js +1 -1
- package/examples/jsm/renderers/common/Textures.js +172 -20
- package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +2 -2
- package/examples/jsm/renderers/common/nodes/NodeSampler.js +1 -1
- package/examples/jsm/renderers/common/nodes/Nodes.js +58 -13
- package/examples/jsm/renderers/webgl/WebGLBackend.js +607 -0
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +118 -17
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +84 -0
- package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +26 -0
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +529 -0
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +199 -0
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +242 -0
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +340 -0
- package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodeBuilder.js +1 -1
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +320 -84
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +18 -2
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +120 -66
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +2 -2
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +55 -36
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +96 -5
- package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +24 -22
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +117 -139
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +60 -142
- package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +7 -6
- package/examples/jsm/shaders/FilmShader.js +11 -54
- package/examples/jsm/shaders/OutputShader.js +19 -2
- package/examples/jsm/shaders/SAOShader.js +0 -13
- package/examples/jsm/shaders/SSAOShader.js +33 -26
- package/examples/jsm/utils/BufferGeometryUtils.js +13 -4
- package/examples/jsm/webxr/OculusHandPointerModel.js +2 -2
- package/package.json +2 -2
- package/src/Three.js +3 -0
- package/src/animation/PropertyBinding.js +1 -1
- package/src/audio/Audio.js +6 -0
- package/src/cameras/CubeCamera.js +1 -4
- package/src/constants.js +4 -1
- package/src/core/BufferAttribute.js +20 -0
- package/src/core/Object3D.js +2 -15
- package/src/core/RenderTarget.js +122 -0
- package/src/core/UniformsGroup.js +2 -2
- package/src/geometries/CapsuleGeometry.js +1 -1
- package/src/loaders/DataTextureLoader.js +19 -2
- package/src/materials/Material.js +2 -2
- package/src/math/Vector2.js +2 -2
- package/src/math/Vector3.js +3 -3
- package/src/math/Vector4.js +4 -4
- package/src/objects/Line.js +1 -1
- package/src/objects/Mesh.js +1 -1
- package/src/objects/Points.js +1 -1
- package/src/renderers/WebGLMultipleRenderTargets.js +0 -2
- package/src/renderers/WebGLRenderTarget.js +3 -110
- package/src/renderers/WebGLRenderer.js +83 -57
- package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +1 -2
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +11 -1
- package/src/renderers/shaders/ShaderLib/background.glsl.js +8 -0
- package/src/renderers/webgl/WebGLBackground.js +5 -14
- package/src/renderers/webgl/WebGLGeometries.js +5 -1
- package/src/renderers/webgl/WebGLMaterials.js +1 -1
- package/src/renderers/webgl/WebGLProgram.js +2 -0
- package/src/renderers/webgl/WebGLPrograms.js +19 -3
- package/src/renderers/webgl/WebGLTextures.js +101 -16
- package/src/renderers/webgl/WebGLUtils.js +27 -20
- package/src/textures/CompressedCubeTexture.js +19 -0
- package/src/textures/Texture.js +2 -2
- package/src/utils.js +9 -1
- package/examples/jsm/nodes/functions/BSDF/BRDF_BlinnPhong.js +0 -30
- package/examples/jsm/renderers/common/RenderTarget.js +0 -15
- package/examples/jsm/renderers/common/nodes/NodeRender.js +0 -302
- /package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/SlotNode.js +0 -0
- /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,
|
|
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
|
-
[
|
|
23
|
-
[
|
|
22
|
+
[ LessCompare ]: 'less',
|
|
23
|
+
[ EqualCompare ]: 'equal',
|
|
24
24
|
[ LessEqualCompare ]: 'less-equal',
|
|
25
|
-
[
|
|
26
|
-
[ GreaterEqualCompare ]: '
|
|
27
|
-
[
|
|
28
|
-
[ NotEqualCompare ]: '
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
125
|
-
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 {
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
372
|
+
this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, i );
|
|
377
373
|
|
|
378
374
|
} else {
|
|
379
375
|
|
|
380
|
-
this._copyImageToTexture( image,
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
60
|
+
if ( renderContext.textures !== null ) {
|
|
60
61
|
|
|
61
|
-
return renderContext.
|
|
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.
|
|
81
|
+
if ( renderContext.textures !== null ) {
|
|
81
82
|
|
|
82
|
-
return
|
|
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
|
-
'
|
|
30
|
-
'
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
81
|
-
vec2 sc = vec2( sin( vUv.y * sCount ), cos( vUv.y * sCount ) );
|
|
41
|
+
float noise = rand( vUv + time );
|
|
82
42
|
|
|
83
|
-
|
|
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
|
-
|
|
87
|
-
cResult = cTextureScreen.rgb + clamp( nIntensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb );
|
|
45
|
+
color = mix( base.rgb, color, intensity );
|
|
88
46
|
|
|
89
|
-
|
|
90
|
-
if( grayscale ) {
|
|
47
|
+
if ( grayscale ) {
|
|
91
48
|
|
|
92
|
-
|
|
49
|
+
color = vec3( luminance( color ) ); // assuming linear-srgb
|
|
93
50
|
|
|
94
51
|
}
|
|
95
52
|
|
|
96
|
-
gl_FragColor =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
134
|
-
|
|
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
|
-
|
|
137
|
-
|
|
141
|
+
vec2 noiseScale = vec2( resolution.x / 4.0, resolution.y / 4.0 );
|
|
142
|
+
vec3 random = vec3( texture2D( tNoise, vUv * noiseScale ).r );
|
|
138
143
|
|
|
139
|
-
|
|
144
|
+
// compute matrix used to reorient a kernel vector
|
|
140
145
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
150
|
+
float occlusion = 0.0;
|
|
146
151
|
|
|
147
|
-
|
|
152
|
+
for ( int i = 0; i < KERNEL_SIZE; i ++ ) {
|
|
148
153
|
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
vec3 sampleVector = kernelMatrix * kernel[ i ]; // reorient sample vector in view space
|
|
155
|
+
vec3 samplePoint = viewPosition + ( sampleVector * kernelRadius ); // calculate sample point
|
|
151
156
|
|
|
152
|
-
|
|
153
|
-
|
|
157
|
+
vec4 samplePointNDC = cameraProjectionMatrix * vec4( samplePoint, 1.0 ); // project point and calculate NDC
|
|
158
|
+
samplePointNDC /= samplePointNDC.w;
|
|
154
159
|
|
|
155
|
-
|
|
160
|
+
vec2 samplePointUv = samplePointNDC.xy * 0.5 + 0.5; // compute uv coordinates
|
|
156
161
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
166
|
+
if ( delta > minDistance && delta < maxDistance ) { // if fragment is before sample point, increase occlusion
|
|
162
167
|
|
|
163
|
-
|
|
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
|
-
|
|
176
|
+
gl_FragColor = vec4( vec3( 1.0 - occlusion ), 1.0 );
|
|
170
177
|
|
|
171
|
-
|
|
178
|
+
}
|
|
172
179
|
|
|
173
180
|
}`
|
|
174
181
|
|