super-three 0.177.0 → 0.179.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/README.md +1 -1
- package/build/three.cjs +959 -231
- package/build/three.core.js +751 -170
- package/build/three.core.min.js +1 -1
- package/build/three.module.js +210 -64
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +78 -29
- package/build/three.tsl.min.js +1 -1
- package/build/three.webgpu.js +3269 -1545
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +3093 -1545
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +1 -2
- package/examples/jsm/capabilities/WebGL.js +0 -27
- package/examples/jsm/capabilities/WebGPU.js +1 -1
- package/examples/jsm/controls/ArcballControls.js +1 -1
- package/examples/jsm/controls/TransformControls.js +61 -14
- package/examples/jsm/csm/CSMShadowNode.js +4 -4
- package/examples/jsm/environments/RoomEnvironment.js +8 -3
- package/examples/jsm/exporters/USDZExporter.js +676 -299
- package/examples/jsm/geometries/RoundedBoxGeometry.js +47 -8
- package/examples/jsm/interactive/HTMLMesh.js +5 -3
- package/examples/jsm/libs/meshopt_decoder.module.js +75 -58
- package/examples/jsm/lights/LightProbeGenerator.js +14 -3
- package/examples/jsm/loaders/ColladaLoader.js +1 -1
- package/examples/jsm/loaders/EXRLoader.js +210 -22
- package/examples/jsm/loaders/FBXLoader.js +2 -2
- package/examples/jsm/loaders/MaterialXLoader.js +212 -30
- package/examples/jsm/loaders/TTFLoader.js +13 -1
- package/examples/jsm/loaders/USDLoader.js +219 -0
- package/examples/jsm/loaders/USDZLoader.js +4 -892
- package/examples/jsm/loaders/usd/USDAParser.js +741 -0
- package/examples/jsm/loaders/usd/USDCParser.js +17 -0
- package/examples/jsm/objects/LensflareMesh.js +3 -3
- package/examples/jsm/objects/SkyMesh.js +2 -2
- package/examples/jsm/physics/RapierPhysics.js +95 -16
- package/examples/jsm/postprocessing/GTAOPass.js +10 -9
- package/examples/jsm/postprocessing/OutlinePass.js +17 -17
- package/examples/jsm/postprocessing/SSAOPass.js +10 -9
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +11 -2
- package/examples/jsm/transpiler/AST.js +381 -30
- package/examples/jsm/transpiler/GLSLDecoder.js +226 -86
- package/examples/jsm/transpiler/Linker.js +327 -0
- package/examples/jsm/transpiler/TSLEncoder.js +197 -92
- package/examples/jsm/transpiler/Transpiler.js +17 -1
- package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
- package/examples/jsm/transpiler/WGSLEncoder.js +788 -0
- package/examples/jsm/tsl/display/BloomNode.js +8 -7
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +206 -0
- package/examples/jsm/tsl/display/GaussianBlurNode.js +8 -10
- package/examples/jsm/tsl/display/SSAAPassNode.js +2 -2
- package/examples/jsm/tsl/display/{TRAAPassNode.js → TRAANode.js} +181 -172
- package/examples/jsm/tsl/display/hashBlur.js +3 -3
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +1 -1
- package/package.json +1 -1
- package/src/Three.Core.js +1 -0
- package/src/Three.TSL.js +77 -28
- package/src/Three.WebGPU.js +2 -0
- package/src/animation/KeyframeTrack.js +1 -1
- package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
- package/src/animation/tracks/StringKeyframeTrack.js +1 -1
- package/src/cameras/Camera.js +14 -0
- package/src/cameras/OrthographicCamera.js +1 -1
- package/src/cameras/PerspectiveCamera.js +1 -1
- package/src/constants.js +3 -3
- package/src/core/BufferAttribute.js +3 -3
- package/src/core/Clock.js +2 -8
- package/src/core/GLBufferAttribute.js +13 -1
- package/src/core/Object3D.js +1 -1
- package/{examples/jsm/misc → src/core}/Timer.js +4 -42
- package/src/extras/PMREMGenerator.js +11 -0
- package/src/extras/core/Path.js +22 -22
- package/src/helpers/CameraHelper.js +41 -11
- package/src/helpers/SkeletonHelper.js +35 -6
- package/src/lights/LightShadow.js +21 -8
- package/src/lights/PointLightShadow.js +1 -1
- package/src/loaders/FileLoader.js +27 -4
- package/src/loaders/ImageBitmapLoader.js +27 -4
- package/src/loaders/ImageLoader.js +55 -8
- package/src/loaders/Loader.js +14 -0
- package/src/loaders/LoadingManager.js +23 -0
- package/src/materials/MeshBasicMaterial.js +1 -1
- package/src/materials/nodes/Line2NodeMaterial.js +0 -8
- package/src/materials/nodes/MeshBasicNodeMaterial.js +4 -3
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +1 -1
- package/src/materials/nodes/MeshNormalNodeMaterial.js +2 -2
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +2 -1
- package/src/materials/nodes/MeshSSSNodeMaterial.js +2 -2
- package/src/materials/nodes/NodeMaterial.js +28 -5
- package/src/materials/nodes/PointsNodeMaterial.js +5 -0
- package/src/materials/nodes/manager/NodeMaterialObserver.js +87 -2
- package/src/math/Frustum.js +25 -9
- package/src/math/FrustumArray.js +10 -5
- package/src/math/Line3.js +129 -2
- package/src/math/Matrix4.js +48 -27
- package/src/math/Quaternion.js +1 -1
- package/src/math/Spherical.js +2 -2
- package/src/nodes/Nodes.js +2 -3
- package/src/nodes/TSL.js +5 -3
- package/src/nodes/accessors/AccessorsUtils.js +7 -8
- package/src/nodes/accessors/Bitangent.js +31 -25
- package/src/nodes/accessors/Camera.js +12 -12
- package/src/nodes/accessors/Normal.js +95 -29
- package/src/nodes/accessors/Object3DNode.js +1 -1
- package/src/nodes/accessors/Position.js +7 -7
- package/src/nodes/accessors/ReferenceNode.js +18 -3
- package/src/nodes/accessors/ReflectVector.js +3 -3
- package/src/nodes/accessors/SceneNode.js +1 -1
- package/src/nodes/accessors/StorageTextureNode.js +1 -1
- package/src/nodes/accessors/Tangent.js +25 -17
- package/src/nodes/accessors/TangentUtils.js +46 -0
- package/src/nodes/accessors/TextureBicubic.js +21 -3
- package/src/nodes/accessors/TextureNode.js +12 -0
- package/src/nodes/accessors/UniformArrayNode.js +0 -16
- package/src/nodes/core/ArrayNode.js +12 -0
- package/src/nodes/core/AssignNode.js +3 -0
- package/src/nodes/core/CacheNode.js +0 -14
- package/src/nodes/core/ContextNode.js +20 -1
- package/src/nodes/core/Node.js +15 -3
- package/src/nodes/core/NodeBuilder.js +228 -92
- package/src/nodes/core/NodeUtils.js +4 -1
- package/src/nodes/core/StackNode.js +49 -29
- package/src/nodes/core/SubBuildNode.js +89 -0
- package/src/nodes/core/UniformNode.js +63 -5
- package/src/nodes/core/VarNode.js +91 -2
- package/src/nodes/core/VaryingNode.js +6 -4
- package/src/nodes/display/BlendModes.js +2 -2
- package/src/nodes/display/FrontFacingNode.js +34 -2
- package/src/nodes/display/NormalMapNode.js +19 -50
- package/src/nodes/display/PassNode.js +157 -9
- package/src/nodes/display/ScreenNode.js +0 -26
- package/src/nodes/display/ViewportTextureNode.js +67 -7
- package/src/nodes/functions/BSDF/BRDF_GGX.js +2 -6
- package/src/nodes/functions/BSDF/BRDF_Sheen.js +4 -4
- package/src/nodes/functions/PhongLightingModel.js +3 -3
- package/src/nodes/functions/PhysicalLightingModel.js +16 -16
- package/src/nodes/functions/material/getGeometryRoughness.js +2 -2
- package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
- package/src/nodes/gpgpu/ComputeNode.js +67 -23
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +28 -3
- package/src/nodes/lighting/EnvironmentNode.js +5 -5
- package/src/nodes/lighting/LightsNode.js +4 -4
- package/src/nodes/lighting/ProjectorLightNode.js +19 -6
- package/src/nodes/lighting/ShadowFilterNode.js +1 -1
- package/src/nodes/lighting/ShadowNode.js +2 -2
- package/src/nodes/materialx/MaterialXNodes.js +131 -2
- package/src/nodes/materialx/lib/mx_noise.js +165 -1
- package/src/nodes/math/ConditionalNode.js +1 -20
- package/src/nodes/math/MathNode.js +90 -55
- package/src/nodes/math/OperatorNode.js +22 -39
- package/src/nodes/tsl/TSLBase.js +1 -0
- package/src/nodes/tsl/TSLCore.js +114 -55
- package/src/nodes/utils/DebugNode.js +1 -1
- package/src/nodes/utils/EquirectUV.js +27 -0
- package/src/nodes/utils/EventNode.js +83 -0
- package/src/nodes/utils/LoopNode.js +0 -17
- package/src/nodes/utils/MatcapUV.js +22 -0
- package/src/nodes/utils/RTTNode.js +22 -5
- package/src/nodes/utils/ReflectorNode.js +11 -4
- package/src/nodes/utils/SampleNode.js +81 -0
- package/src/nodes/utils/TriplanarTextures.js +65 -0
- package/src/objects/BatchedMesh.js +4 -2
- package/src/renderers/WebGLRenderer.js +26 -24
- package/src/renderers/common/Background.js +2 -2
- package/src/renderers/common/Bindings.js +19 -18
- package/src/renderers/common/Color4.js +2 -2
- package/src/renderers/common/CubeRenderTarget.js +1 -1
- package/src/renderers/common/PostProcessing.js +60 -5
- package/src/renderers/common/RenderObject.js +68 -3
- package/src/renderers/common/Renderer.js +19 -16
- package/src/renderers/common/SampledTexture.js +3 -71
- package/src/renderers/common/Sampler.js +79 -0
- package/src/renderers/common/Storage3DTexture.js +100 -0
- package/src/renderers/common/StorageArrayTexture.js +84 -0
- package/src/renderers/common/StorageTexture.js +19 -0
- package/src/renderers/common/Textures.js +19 -3
- package/src/renderers/common/XRManager.js +31 -12
- package/src/renderers/common/XRRenderTarget.js +21 -4
- package/src/renderers/common/extras/PMREMGenerator.js +1 -1
- package/src/renderers/common/nodes/NodeSampledTexture.js +0 -12
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +20 -2
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +11 -2
- package/src/renderers/webgl/WebGLAttributes.js +4 -0
- package/src/renderers/webgl/WebGLCapabilities.js +2 -2
- package/src/renderers/webgl/WebGLProgram.js +12 -6
- package/src/renderers/webgl/WebGLPrograms.js +6 -4
- package/src/renderers/webgl/WebGLShadowMap.js +11 -1
- package/src/renderers/webgl/WebGLState.js +4 -4
- package/src/renderers/webgl/WebGLTextures.js +19 -7
- package/src/renderers/webgl-fallback/WebGLBackend.js +103 -72
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +3 -5
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +4 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +4 -4
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +2 -0
- package/src/renderers/webgpu/WebGPUBackend.js +63 -16
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +64 -79
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +6 -0
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +45 -31
- package/src/renderers/webgpu/utils/WebGPUConstants.js +7 -1
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +5 -5
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +12 -65
- package/src/renderers/webgpu/utils/WebGPUUtils.js +2 -17
- package/src/renderers/webxr/WebXRDepthSensing.js +6 -10
- package/src/renderers/webxr/WebXRManager.js +68 -6
- package/src/textures/ExternalTexture.js +45 -0
- package/src/textures/FramebufferTexture.js +2 -2
- package/src/textures/Source.js +11 -1
- package/src/textures/VideoTexture.js +30 -2
- package/src/nodes/utils/EquirectUVNode.js +0 -65
- package/src/nodes/utils/MatcapUVNode.js +0 -49
- package/src/nodes/utils/TriplanarTexturesNode.js +0 -148
|
@@ -364,7 +364,9 @@ class BloomNode extends TempNode {
|
|
|
364
364
|
|
|
365
365
|
// gaussian blur materials
|
|
366
366
|
|
|
367
|
-
|
|
367
|
+
// These sizes have been changed to account for the altered coefficents-calculation to avoid blockiness,
|
|
368
|
+
// while retaining the same blur-strength. For details see https://github.com/mrdoob/three.js/pull/31528
|
|
369
|
+
const kernelSizeArray = [ 6, 10, 14, 18, 22 ];
|
|
368
370
|
|
|
369
371
|
for ( let i = 0; i < this._nMips; i ++ ) {
|
|
370
372
|
|
|
@@ -449,10 +451,11 @@ class BloomNode extends TempNode {
|
|
|
449
451
|
_getSeparableBlurMaterial( builder, kernelRadius ) {
|
|
450
452
|
|
|
451
453
|
const coefficients = [];
|
|
454
|
+
const sigma = kernelRadius / 3;
|
|
452
455
|
|
|
453
456
|
for ( let i = 0; i < kernelRadius; i ++ ) {
|
|
454
457
|
|
|
455
|
-
coefficients.push( 0.39894 * Math.exp( - 0.5 * i * i / (
|
|
458
|
+
coefficients.push( 0.39894 * Math.exp( - 0.5 * i * i / ( sigma * sigma ) ) / sigma );
|
|
456
459
|
|
|
457
460
|
}
|
|
458
461
|
|
|
@@ -468,8 +471,7 @@ class BloomNode extends TempNode {
|
|
|
468
471
|
|
|
469
472
|
const separableBlurPass = Fn( () => {
|
|
470
473
|
|
|
471
|
-
const
|
|
472
|
-
const diffuseSum = sampleTexel( uvNode ).rgb.mul( weightSum ).toVar();
|
|
474
|
+
const diffuseSum = sampleTexel( uvNode ).rgb.mul( gaussianCoefficients.element( 0 ) ).toVar();
|
|
473
475
|
|
|
474
476
|
Loop( { start: int( 1 ), end: int( kernelRadius ), type: 'int', condition: '<' }, ( { i } ) => {
|
|
475
477
|
|
|
@@ -478,12 +480,11 @@ class BloomNode extends TempNode {
|
|
|
478
480
|
const uvOffset = direction.mul( invSize ).mul( x );
|
|
479
481
|
const sample1 = sampleTexel( uvNode.add( uvOffset ) ).rgb;
|
|
480
482
|
const sample2 = sampleTexel( uvNode.sub( uvOffset ) ).rgb;
|
|
481
|
-
diffuseSum.addAssign( add( sample1, sample2 ).mul( w ) );
|
|
482
|
-
weightSum.addAssign( float( 2.0 ).mul( w ) );
|
|
483
|
+
diffuseSum.addAssign( add( sample1, sample2 ).mul( w ) );
|
|
483
484
|
|
|
484
485
|
} );
|
|
485
486
|
|
|
486
|
-
return vec4( diffuseSum
|
|
487
|
+
return vec4( diffuseSum, 1.0 );
|
|
487
488
|
|
|
488
489
|
} );
|
|
489
490
|
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { Vector2, TempNode } from 'three/webgpu';
|
|
2
|
+
import {
|
|
3
|
+
nodeObject,
|
|
4
|
+
Fn,
|
|
5
|
+
uniform,
|
|
6
|
+
convertToTexture,
|
|
7
|
+
float,
|
|
8
|
+
vec4,
|
|
9
|
+
uv,
|
|
10
|
+
NodeUpdateType,
|
|
11
|
+
} from 'three/tsl';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Post processing node for applying chromatic aberration effect.
|
|
15
|
+
* This effect simulates the color fringing that occurs in real camera lenses
|
|
16
|
+
* by separating and offsetting the red, green, and blue channels.
|
|
17
|
+
*
|
|
18
|
+
* @augments TempNode
|
|
19
|
+
* @three_import import { chromaticAberration } from 'three/addons/tsl/display/ChromaticAberrationNode.js';
|
|
20
|
+
*/
|
|
21
|
+
class ChromaticAberrationNode extends TempNode {
|
|
22
|
+
|
|
23
|
+
static get type() {
|
|
24
|
+
|
|
25
|
+
return 'ChromaticAberrationNode';
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Constructs a new chromatic aberration node.
|
|
31
|
+
*
|
|
32
|
+
* @param {TextureNode} textureNode - The texture node that represents the input of the effect.
|
|
33
|
+
* @param {Node} strengthNode - The strength of the chromatic aberration effect as a node.
|
|
34
|
+
* @param {Node} centerNode - The center point of the effect as a node.
|
|
35
|
+
* @param {Node} scaleNode - The scale factor for stepped scaling from center as a node.
|
|
36
|
+
*/
|
|
37
|
+
constructor( textureNode, strengthNode, centerNode, scaleNode ) {
|
|
38
|
+
|
|
39
|
+
super( 'vec4' );
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The texture node that represents the input of the effect.
|
|
43
|
+
*
|
|
44
|
+
* @type {texture}
|
|
45
|
+
*/
|
|
46
|
+
this.textureNode = textureNode;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The `updateBeforeType` is set to `NodeUpdateType.FRAME` since the node updates
|
|
50
|
+
* its internal uniforms once per frame in `updateBefore()`.
|
|
51
|
+
*
|
|
52
|
+
* @type {string}
|
|
53
|
+
* @default 'frame'
|
|
54
|
+
*/
|
|
55
|
+
this.updateBeforeType = NodeUpdateType.FRAME;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A node holding the strength of the effect.
|
|
59
|
+
*
|
|
60
|
+
* @type {Node}
|
|
61
|
+
*/
|
|
62
|
+
this.strengthNode = strengthNode;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A node holding the center point of the effect.
|
|
66
|
+
*
|
|
67
|
+
* @type {Node}
|
|
68
|
+
*/
|
|
69
|
+
this.centerNode = centerNode;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A node holding the scale factor for stepped scaling.
|
|
73
|
+
*
|
|
74
|
+
* @type {Node}
|
|
75
|
+
*/
|
|
76
|
+
this.scaleNode = scaleNode;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A uniform node holding the inverse resolution value.
|
|
80
|
+
*
|
|
81
|
+
* @private
|
|
82
|
+
* @type {UniformNode<vec2>}
|
|
83
|
+
*/
|
|
84
|
+
this._invSize = uniform( new Vector2() );
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* This method is used to update the effect's uniforms once per frame.
|
|
90
|
+
*
|
|
91
|
+
* @param {NodeFrame} frame - The current node frame.
|
|
92
|
+
*/
|
|
93
|
+
updateBefore( /* frame */ ) {
|
|
94
|
+
|
|
95
|
+
const map = this.textureNode.value;
|
|
96
|
+
this._invSize.value.set( 1 / map.image.width, 1 / map.image.height );
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* This method is used to setup the effect's TSL code.
|
|
102
|
+
*
|
|
103
|
+
* @param {NodeBuilder} builder - The current node builder.
|
|
104
|
+
* @return {ShaderCallNodeInternal}
|
|
105
|
+
*/
|
|
106
|
+
setup( /* builder */ ) {
|
|
107
|
+
|
|
108
|
+
const textureNode = this.textureNode;
|
|
109
|
+
const uvNode = textureNode.uvNode || uv();
|
|
110
|
+
|
|
111
|
+
const ApplyChromaticAberration = Fn( ( [ uv, strength, center, scale ] ) => {
|
|
112
|
+
|
|
113
|
+
// Calculate distance from center
|
|
114
|
+
const offset = uv.sub( center );
|
|
115
|
+
const distance = offset.length();
|
|
116
|
+
|
|
117
|
+
// Create stepped scaling zones based on distance
|
|
118
|
+
// Each channel gets different scaling steps
|
|
119
|
+
const redScale = float( 1.0 ).add( scale.mul( 0.02 ).mul( strength ) ); // Red channel scaled outward
|
|
120
|
+
const greenScale = float( 1.0 ); // Green stays at original scale
|
|
121
|
+
const blueScale = float( 1.0 ).sub( scale.mul( 0.02 ).mul( strength ) ); // Blue channel scaled inward
|
|
122
|
+
|
|
123
|
+
// Create radial distortion based on distance from center
|
|
124
|
+
const aberrationStrength = strength.mul( distance );
|
|
125
|
+
|
|
126
|
+
// Calculate scaled UV coordinates for each channel
|
|
127
|
+
const redUV = center.add( offset.mul( redScale ) );
|
|
128
|
+
const greenUV = center.add( offset.mul( greenScale ) );
|
|
129
|
+
const blueUV = center.add( offset.mul( blueScale ) );
|
|
130
|
+
|
|
131
|
+
// Apply additional chromatic offset based on aberration strength
|
|
132
|
+
const rOffset = offset.mul( aberrationStrength ).mul( float( 0.01 ) );
|
|
133
|
+
const gOffset = offset.mul( aberrationStrength ).mul( float( 0.0 ) );
|
|
134
|
+
const bOffset = offset.mul( aberrationStrength ).mul( float( - 0.01 ) );
|
|
135
|
+
|
|
136
|
+
// Final UV coordinates combining scale and chromatic aberration
|
|
137
|
+
const finalRedUV = redUV.add( rOffset );
|
|
138
|
+
const finalGreenUV = greenUV.add( gOffset );
|
|
139
|
+
const finalBlueUV = blueUV.add( bOffset );
|
|
140
|
+
|
|
141
|
+
// Sample texture for each channel
|
|
142
|
+
const r = textureNode.sample( finalRedUV ).r;
|
|
143
|
+
const g = textureNode.sample( finalGreenUV ).g;
|
|
144
|
+
const b = textureNode.sample( finalBlueUV ).b;
|
|
145
|
+
|
|
146
|
+
// Get original alpha
|
|
147
|
+
const a = textureNode.sample( uv ).a;
|
|
148
|
+
|
|
149
|
+
return vec4( r, g, b, a );
|
|
150
|
+
|
|
151
|
+
} ).setLayout( {
|
|
152
|
+
name: 'ChromaticAberrationShader',
|
|
153
|
+
type: 'vec4',
|
|
154
|
+
inputs: [
|
|
155
|
+
{ name: 'uv', type: 'vec2' },
|
|
156
|
+
{ name: 'strength', type: 'float' },
|
|
157
|
+
{ name: 'center', type: 'vec2' },
|
|
158
|
+
{ name: 'scale', type: 'float' },
|
|
159
|
+
{ name: 'invSize', type: 'vec2' }
|
|
160
|
+
]
|
|
161
|
+
} );
|
|
162
|
+
|
|
163
|
+
const chromaticAberrationFn = Fn( () => {
|
|
164
|
+
|
|
165
|
+
return ApplyChromaticAberration(
|
|
166
|
+
uvNode,
|
|
167
|
+
this.strengthNode,
|
|
168
|
+
this.centerNode,
|
|
169
|
+
this.scaleNode,
|
|
170
|
+
this._invSize
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
} );
|
|
174
|
+
|
|
175
|
+
const outputNode = chromaticAberrationFn();
|
|
176
|
+
|
|
177
|
+
return outputNode;
|
|
178
|
+
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export default ChromaticAberrationNode;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* TSL function for creating a chromatic aberration node for post processing.
|
|
187
|
+
*
|
|
188
|
+
* @tsl
|
|
189
|
+
* @function
|
|
190
|
+
* @param {Node<vec4>} node - The node that represents the input of the effect.
|
|
191
|
+
* @param {Node|number} [strength=1.0] - The strength of the chromatic aberration effect as a node or value.
|
|
192
|
+
* @param {Node|Vector2} [center=null] - The center point of the effect as a node or value. If null, uses screen center (0.5, 0.5).
|
|
193
|
+
* @param {Node|number} [scale=1.1] - The scale factor for stepped scaling from center as a node or value.
|
|
194
|
+
* @returns {ChromaticAberrationNode}
|
|
195
|
+
*/
|
|
196
|
+
export const chromaticAberration = ( node, strength = 1.0, center = null, scale = 1.1 ) => {
|
|
197
|
+
|
|
198
|
+
return nodeObject(
|
|
199
|
+
new ChromaticAberrationNode(
|
|
200
|
+
convertToTexture( node ),
|
|
201
|
+
nodeObject( strength ),
|
|
202
|
+
nodeObject( center ),
|
|
203
|
+
nodeObject( scale )
|
|
204
|
+
)
|
|
205
|
+
);
|
|
206
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RenderTarget, Vector2, NodeMaterial, RendererUtils, QuadMesh, TempNode, NodeUpdateType } from 'three/webgpu';
|
|
2
|
-
import { nodeObject, Fn, float, uv, uniform, convertToTexture, vec2, vec4, passTexture,
|
|
2
|
+
import { nodeObject, Fn, float, uv, uniform, convertToTexture, vec2, vec4, passTexture, premultiplyAlpha, unpremultiplyAlpha } from 'three/tsl';
|
|
3
3
|
|
|
4
4
|
const _quadMesh = /*@__PURE__*/ new QuadMesh();
|
|
5
5
|
|
|
@@ -26,7 +26,7 @@ class GaussianBlurNode extends TempNode {
|
|
|
26
26
|
* @param {Node<vec2|float>} directionNode - Defines the direction and radius of the blur.
|
|
27
27
|
* @param {number} sigma - Controls the kernel of the blur filter. Higher values mean a wider blur radius.
|
|
28
28
|
*/
|
|
29
|
-
constructor( textureNode, directionNode = null, sigma =
|
|
29
|
+
constructor( textureNode, directionNode = null, sigma = 4 ) {
|
|
30
30
|
|
|
31
31
|
super( 'vec4' );
|
|
32
32
|
|
|
@@ -249,8 +249,8 @@ class GaussianBlurNode extends TempNode {
|
|
|
249
249
|
|
|
250
250
|
// https://lisyarus.github.io/blog/posts/blur-coefficients-generator.html
|
|
251
251
|
|
|
252
|
-
sampleTexture = ( uv ) =>
|
|
253
|
-
output = ( color ) =>
|
|
252
|
+
sampleTexture = ( uv ) => premultiplyAlpha( textureNode.sample( uv ) );
|
|
253
|
+
output = ( color ) => unpremultiplyAlpha( color );
|
|
254
254
|
|
|
255
255
|
} else {
|
|
256
256
|
|
|
@@ -267,8 +267,7 @@ class GaussianBlurNode extends TempNode {
|
|
|
267
267
|
const invSize = this._invSize;
|
|
268
268
|
const direction = directionNode.mul( this._passDirection );
|
|
269
269
|
|
|
270
|
-
const
|
|
271
|
-
const diffuseSum = vec4( sampleTexture( uvNode ).mul( weightSum ) ).toVar();
|
|
270
|
+
const diffuseSum = vec4( sampleTexture( uvNode ).mul( gaussianCoefficients[ 0 ] ) ).toVar();
|
|
272
271
|
|
|
273
272
|
for ( let i = 1; i < kernelSize; i ++ ) {
|
|
274
273
|
|
|
@@ -281,11 +280,9 @@ class GaussianBlurNode extends TempNode {
|
|
|
281
280
|
const sample2 = sampleTexture( uvNode.sub( uvOffset ) );
|
|
282
281
|
|
|
283
282
|
diffuseSum.addAssign( sample1.add( sample2 ).mul( w ) );
|
|
284
|
-
weightSum.addAssign( mul( 2.0, w ) );
|
|
285
|
-
|
|
286
283
|
}
|
|
287
284
|
|
|
288
|
-
return output( diffuseSum
|
|
285
|
+
return output( diffuseSum );
|
|
289
286
|
|
|
290
287
|
} );
|
|
291
288
|
|
|
@@ -328,10 +325,11 @@ class GaussianBlurNode extends TempNode {
|
|
|
328
325
|
_getCoefficients( kernelRadius ) {
|
|
329
326
|
|
|
330
327
|
const coefficients = [];
|
|
328
|
+
const sigma = kernelRadius / 3;
|
|
331
329
|
|
|
332
330
|
for ( let i = 0; i < kernelRadius; i ++ ) {
|
|
333
331
|
|
|
334
|
-
coefficients.push( 0.39894 * Math.exp( - 0.5 * i * i / (
|
|
332
|
+
coefficients.push( 0.39894 * Math.exp( - 0.5 * i * i / ( sigma * sigma ) ) / sigma );
|
|
335
333
|
|
|
336
334
|
}
|
|
337
335
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AdditiveBlending, Color, Vector2, RendererUtils, PassNode, QuadMesh, NodeMaterial } from 'three/webgpu';
|
|
2
|
-
import { nodeObject, uniform, mrt, texture, getTextureIndex } from 'three/tsl';
|
|
2
|
+
import { nodeObject, uniform, mrt, texture, getTextureIndex, unpremultiplyAlpha } from 'three/tsl';
|
|
3
3
|
|
|
4
4
|
const _size = /*@__PURE__*/ new Vector2();
|
|
5
5
|
|
|
@@ -277,7 +277,7 @@ class SSAAPassNode extends PassNode {
|
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
this._quadMesh.material = new NodeMaterial();
|
|
280
|
-
this._quadMesh.material.fragmentNode = sampleTexture;
|
|
280
|
+
this._quadMesh.material.fragmentNode = unpremultiplyAlpha( sampleTexture );
|
|
281
281
|
this._quadMesh.material.transparent = true;
|
|
282
282
|
this._quadMesh.material.depthTest = false;
|
|
283
283
|
this._quadMesh.material.depthWrite = false;
|