super-three 0.158.0 → 0.160.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 +1719 -379
- package/build/three.js +1719 -379
- package/build/three.min.js +1 -1
- package/build/three.module.js +1718 -380
- package/build/three.module.min.js +1 -1
- package/examples/jsm/Addons.js +2 -1
- package/examples/jsm/controls/OrbitControls.js +50 -40
- package/examples/jsm/csm/CSMShader.js +52 -47
- package/examples/jsm/exporters/GLTFExporter.js +79 -1
- package/examples/jsm/exporters/USDZExporter.js +27 -19
- package/examples/jsm/helpers/TextureHelper.js +237 -0
- package/examples/jsm/interactive/HTMLMesh.js +9 -2
- package/examples/jsm/lines/LineMaterial.js +16 -33
- package/examples/jsm/loaders/ColladaLoader.js +0 -6
- package/examples/jsm/loaders/DRACOLoader.js +4 -3
- package/examples/jsm/loaders/FBXLoader.js +294 -124
- package/examples/jsm/loaders/GLTFLoader.js +71 -3
- package/examples/jsm/loaders/MaterialXLoader.js +73 -54
- package/examples/jsm/loaders/NRRDLoader.js +0 -13
- package/examples/jsm/loaders/SVGLoader.js +4 -4
- package/examples/jsm/loaders/USDZLoader.js +3 -17
- package/examples/jsm/math/Octree.js +15 -4
- package/examples/jsm/misc/Timer.js +119 -0
- package/examples/jsm/misc/TubePainter.js +3 -6
- package/examples/jsm/modifiers/CurveModifier.js +20 -2
- package/examples/jsm/nodes/Nodes.js +11 -7
- package/examples/jsm/nodes/accessors/CameraNode.js +18 -2
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +5 -73
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +11 -2
- package/examples/jsm/nodes/accessors/ModelNode.js +1 -1
- package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +12 -3
- package/examples/jsm/nodes/accessors/MorphNode.js +191 -16
- package/examples/jsm/nodes/accessors/ReferenceNode.js +25 -1
- package/examples/jsm/nodes/accessors/TextureNode.js +122 -36
- package/examples/jsm/nodes/code/CodeNode.js +3 -3
- package/examples/jsm/nodes/core/AttributeNode.js +7 -1
- package/examples/jsm/nodes/core/CacheNode.js +4 -1
- package/examples/jsm/nodes/core/ConstNode.js +1 -1
- package/examples/jsm/nodes/core/Node.js +6 -3
- package/examples/jsm/nodes/core/NodeBuilder.js +84 -27
- package/examples/jsm/nodes/core/NodeFrame.js +10 -8
- package/examples/jsm/nodes/core/NodeUniform.js +12 -0
- package/examples/jsm/nodes/core/NodeUtils.js +3 -7
- package/examples/jsm/nodes/core/OutputStructNode.js +3 -3
- package/examples/jsm/nodes/core/PropertyNode.js +17 -2
- package/examples/jsm/nodes/core/StructTypeNode.js +4 -4
- package/examples/jsm/nodes/core/UniformGroup.js +13 -0
- package/examples/jsm/nodes/core/UniformGroupNode.js +36 -0
- package/examples/jsm/nodes/core/UniformNode.js +17 -0
- package/examples/jsm/nodes/core/VarNode.js +2 -0
- package/examples/jsm/nodes/core/VaryingNode.js +1 -7
- package/examples/jsm/nodes/display/BumpMapNode.js +1 -1
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +6 -10
- package/examples/jsm/nodes/display/GaussianBlurNode.js +170 -0
- package/examples/jsm/nodes/display/PassNode.js +182 -0
- package/examples/jsm/nodes/display/ViewportDepthNode.js +31 -3
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +2 -2
- package/examples/jsm/nodes/display/ViewportNode.js +5 -8
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +1 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +52 -17
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +8 -12
- package/examples/jsm/nodes/lighting/LightsNode.js +34 -32
- package/examples/jsm/nodes/materials/InstancedPointsNodeMaterial.js +1 -1
- package/examples/jsm/nodes/materials/Line2NodeMaterial.js +12 -12
- package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +1 -0
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +1 -1
- package/examples/jsm/nodes/materials/NodeMaterial.js +66 -41
- package/examples/jsm/nodes/materials/PointsNodeMaterial.js +0 -10
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +0 -7
- package/examples/jsm/nodes/materialx/MaterialXNodes.js +10 -10
- package/examples/jsm/nodes/materialx/lib/mx_hsv.js +128 -54
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +1430 -618
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +24 -14
- package/examples/jsm/nodes/math/MathNode.js +2 -0
- package/examples/jsm/nodes/math/OperatorNode.js +19 -6
- package/examples/jsm/nodes/shadernode/ShaderNode.js +32 -3
- package/examples/jsm/nodes/utils/FunctionOverloadingNode.js +95 -0
- package/examples/jsm/nodes/utils/RemapNode.js +2 -2
- package/examples/jsm/nodes/utils/SplitNode.js +8 -2
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +3 -3
- package/examples/jsm/objects/QuadMesh.js +60 -0
- package/examples/jsm/postprocessing/GTAOPass.js +572 -0
- package/examples/jsm/postprocessing/OutputPass.js +2 -0
- package/examples/jsm/renderers/common/Animation.js +10 -21
- package/examples/jsm/renderers/common/Backend.js +19 -3
- package/examples/jsm/renderers/common/Background.js +20 -22
- package/examples/jsm/renderers/common/Bindings.js +30 -21
- package/examples/jsm/renderers/common/ChainMap.js +3 -3
- package/examples/jsm/renderers/common/Color4.js +37 -0
- package/examples/jsm/renderers/common/Geometries.js +4 -4
- package/examples/jsm/renderers/common/Info.js +12 -2
- package/examples/jsm/renderers/common/Pipelines.js +3 -51
- package/examples/jsm/renderers/common/PostProcessing.js +25 -0
- package/examples/jsm/renderers/common/RenderContext.js +1 -1
- package/examples/jsm/renderers/common/RenderContexts.js +1 -1
- package/examples/jsm/renderers/common/RenderObject.js +13 -1
- package/examples/jsm/renderers/common/RenderObjects.js +4 -2
- package/examples/jsm/renderers/common/Renderer.js +137 -37
- package/examples/jsm/renderers/common/StorageTexture.js +1 -0
- package/examples/jsm/renderers/common/Textures.js +4 -1
- package/examples/jsm/renderers/common/nodes/NodeBuilderState.js +10 -2
- package/examples/jsm/renderers/common/nodes/NodeUniformsGroup.js +44 -0
- package/examples/jsm/renderers/common/nodes/Nodes.js +74 -7
- package/examples/jsm/renderers/webgl/WebGLBackend.js +91 -33
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +100 -31
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +57 -5
- package/examples/jsm/renderers/webgl/utils/WebGLCapabilities.js +36 -0
- package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +11 -1
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +71 -2
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +42 -0
- package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +1 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +33 -3
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +4 -14
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +186 -137
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +1 -1
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +209 -90
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -10
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +11 -3
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +2 -3
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +88 -6
- package/examples/jsm/shaders/FXAAShader.js +133 -133
- package/examples/jsm/shaders/GTAOShader.js +424 -0
- package/examples/jsm/shaders/OutputShader.js +4 -0
- package/examples/jsm/shaders/PoissonDenoiseShader.js +226 -0
- package/examples/jsm/shaders/SAOShader.js +2 -3
- package/examples/jsm/shaders/SSAOShader.js +2 -3
- package/examples/jsm/transpiler/AST.js +40 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +50 -8
- package/examples/jsm/transpiler/ShaderToyDecoder.js +4 -4
- package/examples/jsm/transpiler/TSLEncoder.js +124 -20
- package/examples/jsm/utils/SortUtils.js +158 -0
- package/examples/jsm/utils/TextureUtils.js +33 -21
- package/examples/jsm/webxr/ARButton.js +14 -0
- package/examples/jsm/webxr/VRButton.js +23 -8
- package/examples/jsm/webxr/XRButton.js +25 -11
- package/package.json +5 -6
- package/src/Three.js +1 -0
- package/src/constants.js +2 -1
- package/src/core/BufferAttribute.js +21 -2
- package/src/core/InterleavedBuffer.js +21 -1
- package/src/core/Object3D.js +60 -12
- package/src/core/UniformsGroup.js +7 -1
- package/src/extras/curves/LineCurve3.js +4 -0
- package/src/loaders/AudioLoader.js +1 -1
- package/src/loaders/BufferGeometryLoader.js +0 -7
- package/src/loaders/ImageBitmapLoader.js +25 -1
- package/src/loaders/ObjectLoader.js +49 -0
- package/src/materials/ShaderMaterial.js +2 -1
- package/src/math/ColorManagement.js +0 -16
- package/src/math/Quaternion.js +5 -4
- package/src/math/Sphere.js +2 -0
- package/src/math/Triangle.js +17 -5
- package/src/objects/BatchedMesh.js +1020 -0
- package/src/objects/Skeleton.js +1 -3
- package/src/renderers/WebGL3DRenderTarget.js +2 -2
- package/src/renderers/WebGLArrayRenderTarget.js +2 -2
- package/src/renderers/WebGLRenderer.js +23 -18
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +19 -0
- package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +5 -0
- package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +0 -5
- package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +31 -4
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +9 -4
- package/src/renderers/shaders/ShaderChunk/project_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl.js +9 -17
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +84 -0
- package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk.js +4 -0
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +3 -0
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +3 -0
- package/src/renderers/webgl/WebGLAttributes.js +39 -5
- package/src/renderers/webgl/WebGLBufferRenderer.js +31 -0
- package/src/renderers/webgl/WebGLCubeMaps.js +1 -1
- package/src/renderers/webgl/WebGLExtensions.js +1 -0
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +31 -0
- package/src/renderers/webgl/WebGLLights.js +11 -2
- package/src/renderers/webgl/WebGLProgram.js +20 -1
- package/src/renderers/webgl/WebGLPrograms.js +5 -0
- package/src/renderers/webgl/WebGLShadowMap.js +35 -0
- package/src/renderers/webgl/WebGLTextures.js +7 -11
- package/src/renderers/webgl/WebGLUniforms.js +11 -1
- package/src/renderers/webgl/WebGLUniformsGroups.js +72 -93
- package/src/renderers/webxr/WebXRManager.js +16 -0
- package/examples/jsm/objects/BatchedMesh.js +0 -586
|
@@ -85,13 +85,17 @@ class WebGPUBindingUtils {
|
|
|
85
85
|
|
|
86
86
|
texture.viewDimension = GPUTextureViewDimension.Cube;
|
|
87
87
|
|
|
88
|
+
} else if ( binding.texture.isDataArrayTexture ) {
|
|
89
|
+
|
|
90
|
+
texture.viewDimension = GPUTextureViewDimension.TwoDArray;
|
|
91
|
+
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
bindingGPU.texture = texture;
|
|
91
95
|
|
|
92
96
|
} else {
|
|
93
97
|
|
|
94
|
-
console.error(
|
|
98
|
+
console.error( `WebGPUBindingUtils: Unsupported binding "${ binding }".` );
|
|
95
99
|
|
|
96
100
|
}
|
|
97
101
|
|
|
@@ -152,7 +156,7 @@ class WebGPUBindingUtils {
|
|
|
152
156
|
const usage = GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST;
|
|
153
157
|
|
|
154
158
|
const bufferGPU = device.createBuffer( {
|
|
155
|
-
label: '
|
|
159
|
+
label: 'bindingBuffer_' + binding.name,
|
|
156
160
|
size: byteLength,
|
|
157
161
|
usage: usage
|
|
158
162
|
} );
|
|
@@ -196,6 +200,10 @@ class WebGPUBindingUtils {
|
|
|
196
200
|
|
|
197
201
|
dimensionViewGPU = GPUTextureViewDimension.Cube;
|
|
198
202
|
|
|
203
|
+
} else if ( binding.texture.isDataArrayTexture ) {
|
|
204
|
+
|
|
205
|
+
dimensionViewGPU = GPUTextureViewDimension.TwoDArray;
|
|
206
|
+
|
|
199
207
|
} else {
|
|
200
208
|
|
|
201
209
|
dimensionViewGPU = GPUTextureViewDimension.TwoD;
|
|
@@ -212,7 +220,7 @@ class WebGPUBindingUtils {
|
|
|
212
220
|
|
|
213
221
|
const aspectGPU = GPUTextureAspect.All;
|
|
214
222
|
|
|
215
|
-
resourceGPU = textureData.texture.createView( { aspect: aspectGPU, dimension: dimensionViewGPU } );
|
|
223
|
+
resourceGPU = textureData.texture.createView( { aspect: aspectGPU, dimension: dimensionViewGPU, mipLevelCount: binding.store ? 1 : textureData.mipLevelCount } );
|
|
216
224
|
|
|
217
225
|
}
|
|
218
226
|
|
|
@@ -456,10 +456,9 @@ class WebGPUPipelineUtils {
|
|
|
456
456
|
|
|
457
457
|
descriptor.topology = utils.getPrimitiveTopology( object, material );
|
|
458
458
|
|
|
459
|
-
if ( object.isLine === true && object.isLineSegments !== true ) {
|
|
459
|
+
if ( geometry.index !== null && object.isLine === true && object.isLineSegments !== true ) {
|
|
460
460
|
|
|
461
|
-
|
|
462
|
-
descriptor.stripIndexFormat = ( count > 65535 ) ? GPUIndexFormat.Uint32 : GPUIndexFormat.Uint16; // define data type for primitive restart value
|
|
461
|
+
descriptor.stripIndexFormat = ( geometry.index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32;
|
|
463
462
|
|
|
464
463
|
}
|
|
465
464
|
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare
|
|
14
14
|
} from 'three';
|
|
15
15
|
|
|
16
|
-
import { CubeReflectionMapping, CubeRefractionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping } from 'three';
|
|
16
|
+
import { CubeReflectionMapping, CubeRefractionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping, DepthTexture } from 'three';
|
|
17
17
|
|
|
18
18
|
import WebGPUTexturePassUtils from './WebGPUTexturePassUtils.js';
|
|
19
19
|
|
|
@@ -41,6 +41,11 @@ class WebGPUTextureUtils {
|
|
|
41
41
|
this.defaultTexture = null;
|
|
42
42
|
this.defaultCubeTexture = null;
|
|
43
43
|
|
|
44
|
+
this.colorBuffer = null;
|
|
45
|
+
|
|
46
|
+
this.depthTexture = new DepthTexture();
|
|
47
|
+
this.depthTexture.name = 'depthBuffer';
|
|
48
|
+
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
createSampler( texture ) {
|
|
@@ -106,7 +111,7 @@ class WebGPUTextureUtils {
|
|
|
106
111
|
const { width, height, depth, levels } = options;
|
|
107
112
|
|
|
108
113
|
const dimension = this._getDimension( texture );
|
|
109
|
-
const format = texture.internalFormat || getFormat( texture,
|
|
114
|
+
const format = texture.internalFormat || getFormat( texture, backend.device );
|
|
110
115
|
|
|
111
116
|
const sampleCount = options.sampleCount !== undefined ? options.sampleCount : 1;
|
|
112
117
|
const primarySampleCount = texture.isRenderTargetTexture ? 1 : sampleCount;
|
|
@@ -226,6 +231,75 @@ class WebGPUTextureUtils {
|
|
|
226
231
|
|
|
227
232
|
}
|
|
228
233
|
|
|
234
|
+
getColorBuffer() {
|
|
235
|
+
|
|
236
|
+
if ( this.colorBuffer ) this.colorBuffer.destroy();
|
|
237
|
+
|
|
238
|
+
const backend = this.backend;
|
|
239
|
+
const { width, height } = backend.getDrawingBufferSize();
|
|
240
|
+
|
|
241
|
+
this.colorBuffer = backend.device.createTexture( {
|
|
242
|
+
label: 'colorBuffer',
|
|
243
|
+
size: {
|
|
244
|
+
width: width,
|
|
245
|
+
height: height,
|
|
246
|
+
depthOrArrayLayers: 1
|
|
247
|
+
},
|
|
248
|
+
sampleCount: backend.parameters.sampleCount,
|
|
249
|
+
format: GPUTextureFormat.BGRA8Unorm,
|
|
250
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC
|
|
251
|
+
} );
|
|
252
|
+
|
|
253
|
+
return this.colorBuffer;
|
|
254
|
+
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
getDepthBuffer( depth = true, stencil = true ) {
|
|
258
|
+
|
|
259
|
+
const backend = this.backend;
|
|
260
|
+
const { width, height } = backend.getDrawingBufferSize();
|
|
261
|
+
|
|
262
|
+
const depthTexture = this.depthTexture;
|
|
263
|
+
const depthTextureGPU = backend.get( depthTexture ).texture;
|
|
264
|
+
|
|
265
|
+
let format, type;
|
|
266
|
+
|
|
267
|
+
if ( stencil ) {
|
|
268
|
+
|
|
269
|
+
format = DepthStencilFormat;
|
|
270
|
+
type = UnsignedInt248Type;
|
|
271
|
+
|
|
272
|
+
} else if ( depth ) {
|
|
273
|
+
|
|
274
|
+
format = DepthFormat;
|
|
275
|
+
type = UnsignedIntType;
|
|
276
|
+
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if ( depthTextureGPU !== undefined ) {
|
|
280
|
+
|
|
281
|
+
if ( depthTexture.image.width === width && depthTexture.image.height === height && depthTexture.format === format && depthTexture.type === type ) {
|
|
282
|
+
|
|
283
|
+
return depthTextureGPU;
|
|
284
|
+
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
this.destroyTexture( depthTexture );
|
|
288
|
+
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
depthTexture.name = 'depthBuffer';
|
|
292
|
+
depthTexture.format = format;
|
|
293
|
+
depthTexture.type = type;
|
|
294
|
+
depthTexture.image.width = width;
|
|
295
|
+
depthTexture.image.height = height;
|
|
296
|
+
|
|
297
|
+
this.createTexture( depthTexture, { sampleCount: backend.parameters.sampleCount, width, height } );
|
|
298
|
+
|
|
299
|
+
return backend.get( depthTexture ).texture;
|
|
300
|
+
|
|
301
|
+
}
|
|
302
|
+
|
|
229
303
|
updateTexture( texture, options ) {
|
|
230
304
|
|
|
231
305
|
const textureData = this.backend.get( texture );
|
|
@@ -237,10 +311,18 @@ class WebGPUTextureUtils {
|
|
|
237
311
|
|
|
238
312
|
// transfer texture data
|
|
239
313
|
|
|
240
|
-
if ( texture.isDataTexture || texture.
|
|
314
|
+
if ( texture.isDataTexture || texture.isData3DTexture ) {
|
|
241
315
|
|
|
242
316
|
this._copyBufferToTexture( options.image, textureData.texture, textureDescriptorGPU, 0, false );
|
|
243
317
|
|
|
318
|
+
} else if ( texture.isDataArrayTexture ) {
|
|
319
|
+
|
|
320
|
+
for ( let i = 0; i < options.image.depth; i ++ ) {
|
|
321
|
+
|
|
322
|
+
this._copyBufferToTexture( options.image, textureData.texture, textureDescriptorGPU, i, false, i );
|
|
323
|
+
|
|
324
|
+
}
|
|
325
|
+
|
|
244
326
|
} else if ( texture.isCompressedTexture ) {
|
|
245
327
|
|
|
246
328
|
this._copyCompressedBufferToTexture( texture.mipmaps, textureData.texture, textureDescriptorGPU );
|
|
@@ -437,7 +519,7 @@ class WebGPUTextureUtils {
|
|
|
437
519
|
|
|
438
520
|
}
|
|
439
521
|
|
|
440
|
-
_copyBufferToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY ) {
|
|
522
|
+
_copyBufferToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY, depth = 0 ) {
|
|
441
523
|
|
|
442
524
|
// @TODO: Consider to use GPUCommandEncoder.copyBufferToTexture()
|
|
443
525
|
// @TODO: Consider to support valid buffer layouts with other formats like RGB
|
|
@@ -457,13 +539,13 @@ class WebGPUTextureUtils {
|
|
|
457
539
|
},
|
|
458
540
|
data,
|
|
459
541
|
{
|
|
460
|
-
offset:
|
|
542
|
+
offset: image.width * image.height * bytesPerTexel * depth,
|
|
461
543
|
bytesPerRow
|
|
462
544
|
},
|
|
463
545
|
{
|
|
464
546
|
width: image.width,
|
|
465
547
|
height: image.height,
|
|
466
|
-
depthOrArrayLayers:
|
|
548
|
+
depthOrArrayLayers: 1
|
|
467
549
|
} );
|
|
468
550
|
|
|
469
551
|
if ( flipY === true ) {
|
|
@@ -32,52 +32,52 @@ const FXAAShader = {
|
|
|
32
32
|
|
|
33
33
|
}`,
|
|
34
34
|
|
|
35
|
-
fragmentShader:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
35
|
+
fragmentShader: /* glsl */`
|
|
36
|
+
precision highp float;
|
|
37
|
+
|
|
38
|
+
uniform sampler2D tDiffuse;
|
|
39
|
+
|
|
40
|
+
uniform vec2 resolution;
|
|
41
|
+
|
|
42
|
+
varying vec2 vUv;
|
|
43
|
+
|
|
44
|
+
// FXAA 3.11 implementation by NVIDIA, ported to WebGL by Agost Biro (biro@archilogic.com)
|
|
45
|
+
|
|
46
|
+
//----------------------------------------------------------------------------------
|
|
47
|
+
// File: es3-kepler\FXAA\assets\shaders/FXAA_DefaultES.frag
|
|
48
|
+
// SDK Version: v3.00
|
|
49
|
+
// Email: gameworks@nvidia.com
|
|
50
|
+
// Site: http://developer.nvidia.com/
|
|
51
|
+
//
|
|
52
|
+
// Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
|
|
53
|
+
//
|
|
54
|
+
// Redistribution and use in source and binary forms, with or without
|
|
55
|
+
// modification, are permitted provided that the following conditions
|
|
56
|
+
// are met:
|
|
57
|
+
// * Redistributions of source code must retain the above copyright
|
|
58
|
+
// notice, this list of conditions and the following disclaimer.
|
|
59
|
+
// * Redistributions in binary form must reproduce the above copyright
|
|
60
|
+
// notice, this list of conditions and the following disclaimer in the
|
|
61
|
+
// documentation and/or other materials provided with the distribution.
|
|
62
|
+
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
|
63
|
+
// contributors may be used to endorse or promote products derived
|
|
64
|
+
// from this software without specific prior written permission.
|
|
65
|
+
//
|
|
66
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
|
67
|
+
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
68
|
+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
69
|
+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
70
|
+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
71
|
+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
72
|
+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
73
|
+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
74
|
+
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
75
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
76
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
77
|
+
//
|
|
78
|
+
//----------------------------------------------------------------------------------
|
|
79
|
+
|
|
80
|
+
#ifndef FXAA_DISCARD
|
|
81
81
|
//
|
|
82
82
|
// Only valid for PC OpenGL currently.
|
|
83
83
|
// Probably will not work when FXAA_GREEN_AS_LUMA = 1.
|
|
@@ -87,35 +87,35 @@ const FXAAShader = {
|
|
|
87
87
|
// 0 = Return unchanged color on pixels which don't need AA.
|
|
88
88
|
//
|
|
89
89
|
#define FXAA_DISCARD 0
|
|
90
|
-
|
|
90
|
+
#endif
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
/*--------------------------------------------------------------------------*/
|
|
93
|
+
#define FxaaTexTop(t, p) texture2D(t, p, -100.0)
|
|
94
|
+
#define FxaaTexOff(t, p, o, r) texture2D(t, p + (o * r), -100.0)
|
|
95
|
+
/*--------------------------------------------------------------------------*/
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
#define NUM_SAMPLES 5
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
// assumes colors have premultipliedAlpha, so that the calculated color contrast is scaled by alpha
|
|
100
|
+
float contrast( vec4 a, vec4 b ) {
|
|
101
101
|
vec4 diff = abs( a - b );
|
|
102
102
|
return max( max( max( diff.r, diff.g ), diff.b ), diff.a );
|
|
103
|
-
|
|
103
|
+
}
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
/*============================================================================
|
|
106
106
|
|
|
107
107
|
FXAA3 QUALITY - PC
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
============================================================================*/
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
/*--------------------------------------------------------------------------*/
|
|
112
|
+
vec4 FxaaPixelShader(
|
|
113
113
|
vec2 posM,
|
|
114
114
|
sampler2D tex,
|
|
115
115
|
vec2 fxaaQualityRcpFrame,
|
|
116
116
|
float fxaaQualityEdgeThreshold,
|
|
117
117
|
float fxaaQualityinvEdgeThreshold
|
|
118
|
-
|
|
118
|
+
) {
|
|
119
119
|
vec4 rgbaM = FxaaTexTop(tex, posM);
|
|
120
120
|
vec4 rgbaS = FxaaTexOff(tex, posM, vec2( 0.0, 1.0), fxaaQualityRcpFrame.xy);
|
|
121
121
|
vec4 rgbaE = FxaaTexOff(tex, posM, vec2( 1.0, 0.0), fxaaQualityRcpFrame.xy);
|
|
@@ -136,9 +136,9 @@ const FXAAShader = {
|
|
|
136
136
|
// . 0 .
|
|
137
137
|
|
|
138
138
|
#if (FXAA_DISCARD == 1)
|
|
139
|
-
|
|
139
|
+
if(earlyExit) FxaaDiscard;
|
|
140
140
|
#else
|
|
141
|
-
|
|
141
|
+
if(earlyExit) return rgbaM;
|
|
142
142
|
#endif
|
|
143
143
|
|
|
144
144
|
float contrastN = contrast( rgbaM, rgbaN );
|
|
@@ -156,46 +156,46 @@ const FXAAShader = {
|
|
|
156
156
|
|
|
157
157
|
// 45 deg edge detection and corners of objects, aka V/H contrast is too similar
|
|
158
158
|
if( abs( relativeVContrast ) < .3 ) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
159
|
+
// locate the edge
|
|
160
|
+
vec2 dirToEdge;
|
|
161
|
+
dirToEdge.x = contrastE > contrastW ? 1. : -1.;
|
|
162
|
+
dirToEdge.y = contrastS > contrastN ? 1. : -1.;
|
|
163
|
+
// . 2 . . 1 .
|
|
164
|
+
// 1 0 2 ~= 0 0 1
|
|
165
|
+
// . 1 . . 0 .
|
|
166
|
+
|
|
167
|
+
// tap 2 pixels and see which ones are "outside" the edge, to
|
|
168
|
+
// determine if the edge is vertical or horizontal
|
|
169
|
+
|
|
170
|
+
vec4 rgbaAlongH = FxaaTexOff(tex, posM, vec2( dirToEdge.x, -dirToEdge.y ), fxaaQualityRcpFrame.xy);
|
|
171
|
+
float matchAlongH = contrast( rgbaM, rgbaAlongH );
|
|
172
|
+
// . 1 .
|
|
173
|
+
// 0 0 1
|
|
174
|
+
// . 0 H
|
|
175
|
+
|
|
176
|
+
vec4 rgbaAlongV = FxaaTexOff(tex, posM, vec2( -dirToEdge.x, dirToEdge.y ), fxaaQualityRcpFrame.xy);
|
|
177
|
+
float matchAlongV = contrast( rgbaM, rgbaAlongV );
|
|
178
|
+
// V 1 .
|
|
179
|
+
// 0 0 1
|
|
180
|
+
// . 0 .
|
|
181
|
+
|
|
182
|
+
relativeVContrast = matchAlongV - matchAlongH;
|
|
183
|
+
relativeVContrast *= fxaaQualityinvEdgeThreshold;
|
|
184
|
+
|
|
185
|
+
if( abs( relativeVContrast ) < .3 ) { // 45 deg edge
|
|
186
|
+
// 1 1 .
|
|
173
187
|
// 0 0 1
|
|
174
|
-
// . 0
|
|
188
|
+
// . 0 1
|
|
175
189
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
relativeVContrast *= fxaaQualityinvEdgeThreshold;
|
|
184
|
-
|
|
185
|
-
if( abs( relativeVContrast ) < .3 ) { // 45 deg edge
|
|
186
|
-
// 1 1 .
|
|
187
|
-
// 0 0 1
|
|
188
|
-
// . 0 1
|
|
190
|
+
// do a simple blur
|
|
191
|
+
return mix(
|
|
192
|
+
rgbaM,
|
|
193
|
+
(rgbaN + rgbaS + rgbaE + rgbaW) * .25,
|
|
194
|
+
.4
|
|
195
|
+
);
|
|
196
|
+
}
|
|
189
197
|
|
|
190
|
-
|
|
191
|
-
return mix(
|
|
192
|
-
rgbaM,
|
|
193
|
-
(rgbaN + rgbaS + rgbaE + rgbaW) * .25,
|
|
194
|
-
.4
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
horzSpan = relativeVContrast > 0.;
|
|
198
|
+
horzSpan = relativeVContrast > 0.;
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
if(!horzSpan) rgbaN = rgbaW;
|
|
@@ -224,35 +224,35 @@ const FXAAShader = {
|
|
|
224
224
|
int iterationsUsedN = 0;
|
|
225
225
|
int iterationsUsedP = 0;
|
|
226
226
|
for( int i = 0; i < NUM_SAMPLES; i++ ) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
227
|
+
iterationsUsed = i;
|
|
228
|
+
|
|
229
|
+
float increment = float(i + 1);
|
|
230
|
+
|
|
231
|
+
if(!doneN) {
|
|
232
|
+
nDist += increment;
|
|
233
|
+
posN = posM + offNP * nDist;
|
|
234
|
+
vec4 rgbaEndN = FxaaTexTop(tex, posN.xy);
|
|
235
|
+
doneN = contrast( rgbaEndN, rgbaM ) > contrast( rgbaEndN, rgbaN );
|
|
236
|
+
iterationsUsedN = i;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if(!doneP) {
|
|
240
|
+
pDist += increment;
|
|
241
|
+
posP = posM - offNP * pDist;
|
|
242
|
+
vec4 rgbaEndP = FxaaTexTop(tex, posP.xy);
|
|
243
|
+
doneP = contrast( rgbaEndP, rgbaM ) > contrast( rgbaEndP, rgbaN );
|
|
244
|
+
iterationsUsedP = i;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if(doneN || doneP) break;
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
|
|
251
251
|
if ( !doneP && !doneN ) return rgbaM; // failed to find end of edge
|
|
252
252
|
|
|
253
253
|
float dist = min(
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
doneN ? float( iterationsUsedN ) / float( NUM_SAMPLES - 1 ) : 1.,
|
|
255
|
+
doneP ? float( iterationsUsedP ) / float( NUM_SAMPLES - 1 ) : 1.
|
|
256
256
|
);
|
|
257
257
|
|
|
258
258
|
// hacky way of reduces blurriness of mostly diagonal edges
|
|
@@ -262,25 +262,25 @@ const FXAAShader = {
|
|
|
262
262
|
dist = 1. - dist;
|
|
263
263
|
|
|
264
264
|
return mix(
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
265
|
+
rgbaM,
|
|
266
|
+
rgbaN,
|
|
267
|
+
dist * .5
|
|
268
268
|
);
|
|
269
|
-
|
|
269
|
+
}
|
|
270
270
|
|
|
271
|
-
|
|
271
|
+
void main() {
|
|
272
272
|
const float edgeDetectionQuality = .2;
|
|
273
273
|
const float invEdgeDetectionQuality = 1. / edgeDetectionQuality;
|
|
274
274
|
|
|
275
275
|
gl_FragColor = FxaaPixelShader(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
276
|
+
vUv,
|
|
277
|
+
tDiffuse,
|
|
278
|
+
resolution,
|
|
279
|
+
edgeDetectionQuality, // [0,1] contrast needed, otherwise early discard
|
|
280
|
+
invEdgeDetectionQuality
|
|
281
281
|
);
|
|
282
282
|
|
|
283
|
-
|
|
283
|
+
}
|
|
284
284
|
`
|
|
285
285
|
|
|
286
286
|
};
|