@plastic-software/three 0.183.4 → 0.184.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 +773 -286
- package/build/three.core.js +372 -110
- package/build/three.core.min.js +1 -1
- package/build/three.module.js +426 -180
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +7 -1
- package/build/three.tsl.min.js +1 -1
- package/build/three.webgpu.js +2979 -1281
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +2942 -1281
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +11 -0
- package/examples/jsm/animation/CCDIKSolver.js +5 -1
- package/examples/jsm/controls/ArcballControls.js +4 -1
- package/examples/jsm/controls/DragControls.js +2 -2
- package/examples/jsm/controls/FirstPersonControls.js +58 -54
- package/examples/jsm/controls/FlyControls.js +4 -0
- package/examples/jsm/controls/OrbitControls.js +2 -2
- package/examples/jsm/controls/TrackballControls.js +2 -2
- package/examples/jsm/controls/TransformControls.js +34 -2
- package/examples/jsm/csm/CSMShadowNode.js +6 -2
- package/examples/jsm/exporters/GLTFExporter.js +21 -5
- package/examples/jsm/geometries/TextGeometry.js +18 -0
- package/examples/jsm/helpers/LightProbeGridHelper.js +221 -0
- package/examples/jsm/inspector/Extension.js +13 -0
- package/examples/jsm/inspector/Inspector.js +169 -114
- package/examples/jsm/inspector/RendererInspector.js +2 -2
- package/examples/jsm/inspector/extensions/extensions.json +6 -0
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +916 -0
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +281 -0
- package/examples/jsm/inspector/tabs/Memory.js +128 -0
- package/examples/jsm/inspector/tabs/Parameters.js +34 -2
- package/examples/jsm/inspector/tabs/Performance.js +2 -2
- package/examples/jsm/inspector/tabs/Settings.js +264 -0
- package/examples/jsm/inspector/tabs/Timeline.js +1611 -0
- package/examples/jsm/inspector/tabs/Viewer.js +105 -3
- package/examples/jsm/inspector/ui/Graph.js +2 -2
- package/examples/jsm/inspector/ui/List.js +1 -1
- package/examples/jsm/inspector/ui/Profiler.js +273 -176
- package/examples/jsm/inspector/ui/Style.js +64 -10
- package/examples/jsm/inspector/ui/Tab.js +39 -7
- package/examples/jsm/inspector/ui/Values.js +39 -2
- package/examples/jsm/inspector/ui/utils.js +13 -0
- package/examples/jsm/interaction/InteractionManager.js +226 -0
- package/examples/jsm/libs/meshopt_decoder.module.js +8 -8
- package/examples/jsm/lighting/DynamicLighting.js +82 -0
- package/examples/jsm/lighting/LightProbeGrid.js +651 -0
- package/examples/jsm/lines/LineMaterial.js +1 -1
- package/examples/jsm/loaders/EXRLoader.js +682 -43
- package/examples/jsm/loaders/FBXLoader.js +233 -33
- package/examples/jsm/loaders/GLTFLoader.js +24 -7
- package/examples/jsm/loaders/HDRLoader.js +1 -1
- package/examples/jsm/loaders/KTX2Loader.js +8 -2
- package/examples/jsm/loaders/LDrawLoader.js +39 -47
- package/examples/jsm/loaders/SVGLoader.js +1 -1
- package/examples/jsm/loaders/VTKLoader.js +5 -1
- package/examples/jsm/loaders/collada/ColladaComposer.js +101 -7
- package/examples/jsm/loaders/collada/ColladaParser.js +19 -4
- package/examples/jsm/loaders/usd/USDAParser.js +6 -0
- package/examples/jsm/loaders/usd/USDCParser.js +26 -0
- package/examples/jsm/loaders/usd/USDComposer.js +656 -103
- package/examples/jsm/misc/GPUComputationRenderer.js +2 -0
- package/examples/jsm/misc/RollerCoaster.js +42 -4
- package/examples/jsm/modifiers/TessellateModifier.js +1 -1
- package/examples/jsm/objects/Reflector.js +73 -25
- package/examples/jsm/objects/Sky.js +14 -2
- package/examples/jsm/objects/SkyMesh.js +23 -6
- package/examples/jsm/renderers/Projector.js +18 -38
- package/examples/jsm/renderers/SVGRenderer.js +6 -25
- package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
- package/examples/jsm/tsl/WebGLNodesHandler.js +605 -0
- package/examples/jsm/tsl/display/AfterImageNode.js +10 -0
- package/examples/jsm/tsl/display/AnamorphicNode.js +11 -0
- package/examples/jsm/tsl/display/BilateralBlurNode.js +10 -0
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +3 -36
- package/examples/jsm/tsl/display/FSR1Node.js +477 -0
- package/examples/jsm/tsl/display/GTAONode.js +2 -1
- package/examples/jsm/tsl/display/GaussianBlurNode.js +10 -0
- package/examples/jsm/tsl/display/GodraysNode.js +2 -11
- package/examples/jsm/tsl/display/OutlineNode.js +66 -16
- package/examples/jsm/tsl/display/SSGINode.js +0 -4
- package/examples/jsm/tsl/display/SharpenNode.js +283 -0
- package/examples/jsm/tsl/display/TAAUNode.js +835 -0
- package/examples/jsm/tsl/display/TRAANode.js +48 -7
- package/examples/jsm/tsl/lighting/DynamicLightsNode.js +300 -0
- package/examples/jsm/tsl/lighting/data/AmbientLightDataNode.js +61 -0
- package/examples/jsm/tsl/lighting/data/DirectionalLightDataNode.js +111 -0
- package/examples/jsm/tsl/lighting/data/HemisphereLightDataNode.js +99 -0
- package/examples/jsm/tsl/lighting/data/PointLightDataNode.js +134 -0
- package/examples/jsm/tsl/lighting/data/SpotLightDataNode.js +161 -0
- package/examples/jsm/tsl/math/Bayer.js +13 -2
- package/examples/jsm/utils/BufferGeometryUtils.js +2 -3
- package/examples/jsm/utils/ColorUtils.js +76 -0
- package/examples/jsm/utils/SkeletonUtils.js +14 -8
- package/examples/jsm/webxr/XRHandMeshModel.js +36 -10
- package/examples/jsm/webxr/XRHandModelFactory.js +2 -1
- package/package.json +4 -4
- package/src/Three.Core.js +1 -0
- package/src/Three.TSL.js +6 -0
- package/src/Three.WebGPU.Nodes.js +3 -0
- package/src/Three.WebGPU.js +6 -0
- package/src/animation/AnimationAction.js +11 -1
- package/src/audio/AudioContext.js +2 -2
- package/src/constants.js +1 -1
- package/src/core/BufferAttribute.js +13 -1
- package/src/core/Clock.js +1 -1
- package/src/core/Object3D.js +1 -5
- package/src/core/RenderTarget.js +1 -0
- package/src/extras/curves/CatmullRomCurve3.js +3 -2
- package/src/loaders/AudioLoader.js +11 -1
- package/src/loaders/DataTextureLoader.js +6 -4
- package/src/loaders/FileLoader.js +1 -2
- package/src/loaders/ImageBitmapLoader.js +4 -6
- package/src/loaders/MaterialLoader.js +1 -1
- package/src/loaders/ObjectLoader.js +25 -4
- package/src/loaders/nodes/NodeObjectLoader.js +18 -0
- package/src/materials/MeshToonMaterial.js +1 -1
- package/src/materials/nodes/Line2NodeMaterial.js +27 -0
- package/src/materials/nodes/NodeMaterial.js +0 -27
- package/src/materials/nodes/manager/NodeMaterialObserver.js +188 -89
- package/src/math/Line3.js +3 -0
- package/src/math/Matrix2.js +13 -9
- package/src/math/Matrix3.js +13 -9
- package/src/math/Matrix4.js +13 -9
- package/src/math/Plane.js +4 -3
- package/src/math/Triangle.js +1 -1
- package/src/math/Vector2.js +11 -7
- package/src/math/Vector3.js +12 -8
- package/src/math/Vector4.js +13 -9
- package/src/nodes/Nodes.js +0 -1
- package/src/nodes/TSL.js +1 -1
- package/src/nodes/accessors/BufferAttributeNode.js +9 -3
- package/src/nodes/accessors/CubeTextureNode.js +7 -1
- package/src/nodes/accessors/MaterialProperties.js +2 -5
- package/src/nodes/accessors/Object3DNode.js +1 -1
- package/src/nodes/accessors/ReferenceBaseNode.js +2 -2
- package/src/nodes/accessors/ReferenceNode.js +4 -4
- package/src/nodes/accessors/SceneProperties.js +2 -8
- package/src/nodes/accessors/StorageBufferNode.js +10 -4
- package/src/nodes/accessors/StorageTextureNode.js +4 -9
- package/src/nodes/accessors/TextureNode.js +10 -2
- package/src/nodes/accessors/UniformArrayNode.js +2 -2
- package/src/nodes/code/FunctionCallNode.js +1 -1
- package/src/nodes/code/FunctionNode.js +1 -1
- package/src/nodes/core/ArrayNode.js +1 -1
- package/src/nodes/core/AssignNode.js +1 -1
- package/src/nodes/core/AttributeNode.js +1 -1
- package/src/nodes/core/BypassNode.js +1 -1
- package/src/nodes/core/ContextNode.js +1 -1
- package/src/nodes/core/IndexNode.js +2 -1
- package/src/nodes/core/InputNode.js +1 -1
- package/src/nodes/core/InspectorNode.js +1 -1
- package/src/nodes/core/IsolateNode.js +1 -1
- package/src/nodes/core/Node.js +83 -12
- package/src/nodes/core/NodeBuilder.js +117 -16
- package/src/nodes/core/NodeUtils.js +1 -1
- package/src/nodes/core/OutputStructNode.js +1 -1
- package/src/nodes/core/ParameterNode.js +1 -1
- package/src/nodes/core/StackNode.js +1 -1
- package/src/nodes/core/StructNode.js +1 -1
- package/src/nodes/core/StructTypeNode.js +1 -1
- package/src/nodes/core/SubBuildNode.js +1 -1
- package/src/nodes/core/UniformGroupNode.js +36 -6
- package/src/nodes/core/VarNode.js +1 -1
- package/src/nodes/core/VaryingNode.js +1 -1
- package/src/nodes/display/NormalMapNode.js +2 -2
- package/src/nodes/display/PassNode.js +27 -7
- package/src/nodes/display/RenderOutputNode.js +4 -4
- package/src/nodes/display/ScreenNode.js +1 -1
- package/src/nodes/display/ViewportDepthTextureNode.js +11 -15
- package/src/nodes/display/ViewportTextureNode.js +18 -7
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
- package/src/nodes/geometry/RangeNode.js +1 -1
- package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
- package/src/nodes/gpgpu/BarrierNode.js +9 -0
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -1
- package/src/nodes/gpgpu/ComputeNode.js +69 -44
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +1 -1
- package/src/nodes/lighting/LightsNode.js +6 -27
- package/src/nodes/lighting/ShadowNode.js +24 -2
- package/src/nodes/math/BitcastNode.js +1 -1
- package/src/nodes/math/ConditionalNode.js +1 -1
- package/src/nodes/math/MathNode.js +73 -1
- package/src/nodes/math/OperatorNode.js +1 -1
- package/src/nodes/math/PackFloatNode.js +1 -1
- package/src/nodes/math/UnpackFloatNode.js +1 -1
- package/src/nodes/tsl/TSLBase.js +1 -1
- package/src/nodes/tsl/TSLCore.js +21 -3
- package/src/nodes/utils/ArrayElementNode.js +1 -1
- package/src/nodes/utils/ConvertNode.js +1 -1
- package/src/nodes/utils/DebugNode.js +1 -1
- package/src/nodes/utils/EventNode.js +30 -0
- package/src/nodes/utils/FlipNode.js +1 -1
- package/src/nodes/utils/FunctionOverloadingNode.js +1 -1
- package/src/nodes/utils/JoinNode.js +1 -1
- package/src/nodes/utils/MemberNode.js +1 -1
- package/src/nodes/utils/Remap.js +48 -0
- package/src/nodes/utils/RotateNode.js +1 -1
- package/src/nodes/utils/SetNode.js +1 -1
- package/src/nodes/utils/SplitNode.js +1 -1
- package/src/objects/BatchedMesh.js +17 -2
- package/src/objects/InstancedMesh.js +19 -3
- package/src/objects/SkinnedMesh.js +26 -9
- package/src/renderers/WebGLRenderer.js +147 -48
- package/src/renderers/common/Animation.js +3 -3
- package/src/renderers/common/Attributes.js +15 -1
- package/src/renderers/common/Backend.js +0 -8
- package/src/renderers/common/Background.js +2 -2
- package/src/renderers/common/BindGroup.js +1 -8
- package/src/renderers/common/Bindings.js +2 -2
- package/src/renderers/common/ComputePipeline.js +1 -1
- package/src/renderers/common/CubeRenderTarget.js +1 -1
- package/src/renderers/common/Info.js +333 -4
- package/src/renderers/common/InspectorBase.js +6 -1
- package/src/renderers/common/Pipelines.js +36 -3
- package/src/renderers/common/ReadbackBuffer.js +78 -0
- package/src/renderers/common/RenderBundle.js +3 -1
- package/src/renderers/common/RenderBundles.js +5 -2
- package/src/renderers/common/RenderObject.js +2 -2
- package/src/renderers/common/RenderObjects.js +3 -3
- package/src/renderers/common/RenderPipeline.js +35 -6
- package/src/renderers/common/Renderer.js +232 -53
- package/src/renderers/common/Textures.js +72 -3
- package/src/renderers/common/UniformsGroup.js +1 -1
- package/src/renderers/common/XRManager.js +34 -27
- package/src/renderers/common/extras/PMREMGenerator.js +23 -15
- package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
- package/src/renderers/common/nodes/NodeManager.js +230 -99
- package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +0 -1
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lightprobes_pars_fragment.glsl.js +80 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +2 -0
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +1 -3
- package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +7 -0
- package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +0 -1
- package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +12 -2
- package/src/renderers/shaders/ShaderChunk.js +2 -0
- package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib.js +0 -1
- package/src/renderers/shaders/UniformsLib.js +7 -2
- package/src/renderers/shaders/UniformsUtils.js +27 -5
- package/src/renderers/webgl/WebGLAnimation.js +2 -1
- package/src/renderers/webgl/WebGLBackground.js +13 -13
- package/src/renderers/webgl/WebGLBufferRenderer.js +0 -32
- package/src/renderers/webgl/WebGLCapabilities.js +6 -0
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +0 -32
- package/src/renderers/webgl/WebGLMaterials.js +12 -13
- package/src/renderers/webgl/WebGLOutput.js +4 -1
- package/src/renderers/webgl/WebGLProgram.js +4 -0
- package/src/renderers/webgl/WebGLPrograms.js +19 -3
- package/src/renderers/webgl/WebGLRenderStates.js +13 -2
- package/src/renderers/webgl/WebGLState.js +43 -0
- package/src/renderers/webgl/WebGLTextures.js +129 -26
- package/src/renderers/webgl/WebGLUniformsGroups.js +19 -0
- package/src/renderers/webgl-fallback/WebGLBackend.js +106 -65
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +0 -41
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +29 -51
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +53 -19
- package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +25 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +42 -1
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +63 -50
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +1 -1
- package/src/renderers/webgpu/WebGPUBackend.js +160 -146
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +55 -33
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +103 -17
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +1 -1
- package/src/renderers/webgpu/utils/WebGPUCapabilities.js +48 -0
- package/src/renderers/webgpu/utils/WebGPUConstants.js +8 -0
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +91 -17
- package/src/renderers/webgpu/utils/WebGPUUtils.js +18 -2
- package/src/renderers/webxr/WebXRController.js +12 -0
- package/src/textures/HTMLTexture.js +74 -0
- package/src/textures/Source.js +1 -1
- package/src/textures/Texture.js +13 -2
- package/src/utils.js +23 -1
- package/src/nodes/utils/RemapNode.js +0 -125
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DepthTexture, FloatType, RenderTarget, Vector2, TempNode, QuadMesh, NodeMaterial, RendererUtils, NodeUpdateType } from 'three/webgpu';
|
|
2
|
-
import { Loop, int, exp, min, float, mul, uv, vec2, vec3, Fn, textureSize, orthographicDepthToViewZ, screenUV, nodeObject, uniform, vec4, passTexture, texture, perspectiveDepthToViewZ, positionView, reference } from 'three/tsl';
|
|
1
|
+
import { DepthTexture, FloatType, RenderTarget, Vector2, TempNode, QuadMesh, NodeMaterial, SpriteNodeMaterial, RendererUtils, NodeUpdateType } from 'three/webgpu';
|
|
2
|
+
import { Loop, int, exp, min, float, mul, uv, vec2, vec3, Fn, textureSize, orthographicDepthToViewZ, screenUV, nodeObject, uniform, vec4, passTexture, texture, perspectiveDepthToViewZ, positionView, reference, color } from 'three/tsl';
|
|
3
3
|
|
|
4
4
|
const _quadMesh = /*@__PURE__*/ new QuadMesh();
|
|
5
5
|
const _size = /*@__PURE__*/ new Vector2();
|
|
@@ -293,9 +293,13 @@ class OutlineNode extends TempNode {
|
|
|
293
293
|
* @type {NodeMaterial}
|
|
294
294
|
*/
|
|
295
295
|
this._depthMaterial = new NodeMaterial();
|
|
296
|
-
this._depthMaterial.
|
|
296
|
+
this._depthMaterial.colorNode = color( 0, 0, 0 );
|
|
297
297
|
this._depthMaterial.name = 'OutlineNode.depth';
|
|
298
298
|
|
|
299
|
+
this._depthSpriteMaterial = new SpriteNodeMaterial();
|
|
300
|
+
this._depthSpriteMaterial.colorNode = color( 0, 0, 0 );
|
|
301
|
+
this._depthSpriteMaterial.name = 'OutlineNode.depthSprite';
|
|
302
|
+
|
|
299
303
|
/**
|
|
300
304
|
* The material for preparing the mask.
|
|
301
305
|
*
|
|
@@ -305,6 +309,9 @@ class OutlineNode extends TempNode {
|
|
|
305
309
|
this._prepareMaskMaterial = new NodeMaterial();
|
|
306
310
|
this._prepareMaskMaterial.name = 'OutlineNode.prepareMask';
|
|
307
311
|
|
|
312
|
+
this._prepareMaskSpriteMaterial = new SpriteNodeMaterial();
|
|
313
|
+
this._prepareMaskSpriteMaterial.name = 'OutlineNode.prepareMaskSprite';
|
|
314
|
+
|
|
308
315
|
/**
|
|
309
316
|
* The copy material
|
|
310
317
|
*
|
|
@@ -358,6 +365,17 @@ class OutlineNode extends TempNode {
|
|
|
358
365
|
*/
|
|
359
366
|
this._selectionCache = new Set();
|
|
360
367
|
|
|
368
|
+
/**
|
|
369
|
+
* The number of selected objects from the previous frame. Used to detect
|
|
370
|
+
* the transition to an empty selection so the composite render target can
|
|
371
|
+
* be cleared once and avoid leaving a stale outline on screen.
|
|
372
|
+
*
|
|
373
|
+
* @private
|
|
374
|
+
* @type {number}
|
|
375
|
+
* @default 0
|
|
376
|
+
*/
|
|
377
|
+
this._lastSelectionCount = 0;
|
|
378
|
+
|
|
361
379
|
/**
|
|
362
380
|
* The result of the effect is represented as a separate texture node.
|
|
363
381
|
*
|
|
@@ -442,6 +460,35 @@ class OutlineNode extends TempNode {
|
|
|
442
460
|
const { renderer } = frame;
|
|
443
461
|
const { camera, scene } = this;
|
|
444
462
|
|
|
463
|
+
this._updateSelectionCache();
|
|
464
|
+
|
|
465
|
+
// If no objects are selected, all subsequent passes can be skipped since
|
|
466
|
+
// the outline would be empty anyway. The composite render target is cleared
|
|
467
|
+
// once when transitioning to an empty selection so a previously rendered
|
|
468
|
+
// outline does not linger on screen.
|
|
469
|
+
|
|
470
|
+
if ( this._selectionCache.size === 0 ) {
|
|
471
|
+
|
|
472
|
+
if ( this._lastSelectionCount > 0 ) {
|
|
473
|
+
|
|
474
|
+
_rendererState = RendererUtils.resetRendererState( renderer, _rendererState );
|
|
475
|
+
|
|
476
|
+
renderer.setRenderTarget( this._renderTargetComposite );
|
|
477
|
+
renderer.setClearColor( 0x000000, 0 );
|
|
478
|
+
renderer.clear();
|
|
479
|
+
|
|
480
|
+
RendererUtils.restoreRendererState( renderer, _rendererState );
|
|
481
|
+
|
|
482
|
+
this._lastSelectionCount = 0;
|
|
483
|
+
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return;
|
|
487
|
+
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
this._lastSelectionCount = this._selectionCache.size;
|
|
491
|
+
|
|
445
492
|
_rendererState = RendererUtils.resetRendererAndSceneState( renderer, scene, _rendererState );
|
|
446
493
|
|
|
447
494
|
//
|
|
@@ -453,20 +500,18 @@ class OutlineNode extends TempNode {
|
|
|
453
500
|
|
|
454
501
|
renderer.setClearColor( 0xffffff, 1 );
|
|
455
502
|
|
|
456
|
-
this._updateSelectionCache();
|
|
457
|
-
|
|
458
503
|
const currentSceneName = scene.name;
|
|
459
504
|
|
|
460
505
|
// 1. Draw non-selected objects in the depth buffer
|
|
461
506
|
|
|
462
|
-
scene.overrideMaterial = this._depthMaterial;
|
|
463
|
-
|
|
464
507
|
renderer.setRenderTarget( this._renderTargetDepthBuffer );
|
|
465
|
-
renderer.setRenderObjectFunction( ( object,
|
|
508
|
+
renderer.setRenderObjectFunction( ( object, scene, camera, geometry, material, group, lightsNode, clippingContext ) => {
|
|
466
509
|
|
|
467
510
|
if ( this._selectionCache.has( object ) === false ) {
|
|
468
511
|
|
|
469
|
-
|
|
512
|
+
const overrideMaterial = object.isSprite ? this._depthSpriteMaterial : this._depthMaterial;
|
|
513
|
+
|
|
514
|
+
renderer.renderObject( object, scene, camera, geometry, overrideMaterial, group, lightsNode, clippingContext );
|
|
470
515
|
|
|
471
516
|
}
|
|
472
517
|
|
|
@@ -477,14 +522,14 @@ class OutlineNode extends TempNode {
|
|
|
477
522
|
|
|
478
523
|
// 2. Draw only the selected objects by comparing the depth buffer of non-selected objects
|
|
479
524
|
|
|
480
|
-
scene.overrideMaterial = this._prepareMaskMaterial;
|
|
481
|
-
|
|
482
525
|
renderer.setRenderTarget( this._renderTargetMaskBuffer );
|
|
483
|
-
renderer.setRenderObjectFunction( ( object,
|
|
526
|
+
renderer.setRenderObjectFunction( ( object, scene, camera, geometry, material, group, lightsNode, clippingContext ) => {
|
|
484
527
|
|
|
485
528
|
if ( this._selectionCache.has( object ) === true ) {
|
|
486
529
|
|
|
487
|
-
|
|
530
|
+
const overrideMaterial = object.isSprite ? this._prepareMaskSpriteMaterial : this._prepareMaskMaterial;
|
|
531
|
+
|
|
532
|
+
renderer.renderObject( object, scene, camera, geometry, overrideMaterial, group, lightsNode, clippingContext );
|
|
488
533
|
|
|
489
534
|
}
|
|
490
535
|
|
|
@@ -587,13 +632,16 @@ class OutlineNode extends TempNode {
|
|
|
587
632
|
}
|
|
588
633
|
|
|
589
634
|
const depthTest = positionView.z.lessThanEqual( viewZNode ).select( 1, 0 );
|
|
590
|
-
return
|
|
635
|
+
return vec3( 0.0, depthTest, 1.0 );
|
|
591
636
|
|
|
592
637
|
};
|
|
593
638
|
|
|
594
|
-
this._prepareMaskMaterial.
|
|
639
|
+
this._prepareMaskMaterial.colorNode = prepareMask();
|
|
595
640
|
this._prepareMaskMaterial.needsUpdate = true;
|
|
596
641
|
|
|
642
|
+
this._prepareMaskSpriteMaterial.colorNode = prepareMask();
|
|
643
|
+
this._prepareMaskSpriteMaterial.needsUpdate = true;
|
|
644
|
+
|
|
597
645
|
// copy material
|
|
598
646
|
|
|
599
647
|
this._materialCopy.fragmentNode = this._maskTextureUniform;
|
|
@@ -712,7 +760,9 @@ class OutlineNode extends TempNode {
|
|
|
712
760
|
this._renderTargetComposite.dispose();
|
|
713
761
|
|
|
714
762
|
this._depthMaterial.dispose();
|
|
763
|
+
this._depthSpriteMaterial.dispose();
|
|
715
764
|
this._prepareMaskMaterial.dispose();
|
|
765
|
+
this._prepareMaskSpriteMaterial.dispose();
|
|
716
766
|
this._materialCopy.dispose();
|
|
717
767
|
this._edgeDetectionMaterial.dispose();
|
|
718
768
|
this._separableBlurMaterial.dispose();
|
|
@@ -733,7 +783,7 @@ class OutlineNode extends TempNode {
|
|
|
733
783
|
const selectedObject = this.selectedObjects[ i ];
|
|
734
784
|
selectedObject.traverse( ( object ) => {
|
|
735
785
|
|
|
736
|
-
if ( object.isMesh ) this._selectionCache.add( object );
|
|
786
|
+
if ( object.isMesh || object.isSprite ) this._selectionCache.add( object );
|
|
737
787
|
|
|
738
788
|
} );
|
|
739
789
|
|
|
@@ -461,8 +461,6 @@ class SSGINode extends TempNode {
|
|
|
461
461
|
|
|
462
462
|
const color = vec3( 0 );
|
|
463
463
|
|
|
464
|
-
const lastSampleViewPosition = vec3( viewPosition ).toVar();
|
|
465
|
-
|
|
466
464
|
Loop( { start: uint( 0 ), end: STEP_COUNT, type: 'uint', condition: '<' }, ( { i } ) => {
|
|
467
465
|
|
|
468
466
|
const offset = pow( abs( mul( stepRadius, float( i ).add( initialRayStep ) ).div( radiusVS ) ), EXP_FACTOR ).mul( radiusVS ).toConst();
|
|
@@ -529,8 +527,6 @@ class SSGINode extends TempNode {
|
|
|
529
527
|
|
|
530
528
|
} );
|
|
531
529
|
|
|
532
|
-
lastSampleViewPosition.assign( sampleViewPosition );
|
|
533
|
-
|
|
534
530
|
} );
|
|
535
531
|
|
|
536
532
|
return vec3( color );
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { HalfFloatType, RenderTarget, Vector2, NodeMaterial, RendererUtils, QuadMesh, TempNode, NodeUpdateType } from 'three/webgpu';
|
|
2
|
+
import { Fn, float, vec3, vec4, ivec2, int, uv, floor, abs, max, min, exp2, nodeObject, passTexture, textureSize, textureLoad, convertToTexture } from 'three/tsl';
|
|
3
|
+
|
|
4
|
+
const _quadMesh = /*@__PURE__*/ new QuadMesh();
|
|
5
|
+
const _size = /*@__PURE__*/ new Vector2();
|
|
6
|
+
|
|
7
|
+
let _rendererState;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Post processing node for contrast-adaptive sharpening (RCAS).
|
|
11
|
+
*
|
|
12
|
+
* Reference: {@link https://gpuopen.com/fidelityfx-superresolution/}.
|
|
13
|
+
*
|
|
14
|
+
* @augments TempNode
|
|
15
|
+
* @three_import import { sharpen } from 'three/addons/tsl/display/SharpenNode.js';
|
|
16
|
+
*/
|
|
17
|
+
class SharpenNode extends TempNode {
|
|
18
|
+
|
|
19
|
+
static get type() {
|
|
20
|
+
|
|
21
|
+
return 'SharpenNode';
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Constructs a new sharpen node.
|
|
27
|
+
*
|
|
28
|
+
* @param {TextureNode} textureNode - The texture node that represents the input of the effect.
|
|
29
|
+
* @param {Node<float>} [sharpness=0.2] - Sharpening strength. 0 = maximum sharpening, 2 = no sharpening.
|
|
30
|
+
* @param {Node<bool>} [denoise=false] - Whether to attenuate sharpening in noisy areas.
|
|
31
|
+
*/
|
|
32
|
+
constructor( textureNode, sharpness = 0.2, denoise = false ) {
|
|
33
|
+
|
|
34
|
+
super( 'vec4' );
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* This flag can be used for type testing.
|
|
38
|
+
*
|
|
39
|
+
* @type {boolean}
|
|
40
|
+
* @readonly
|
|
41
|
+
* @default true
|
|
42
|
+
*/
|
|
43
|
+
this.isSharpenNode = true;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The texture node that represents the input of the effect.
|
|
47
|
+
*
|
|
48
|
+
* @type {TextureNode}
|
|
49
|
+
*/
|
|
50
|
+
this.textureNode = textureNode;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Sharpening strength. 0 = maximum, 2 = none.
|
|
54
|
+
*
|
|
55
|
+
* @type {Node<float>}
|
|
56
|
+
* @default 0.2
|
|
57
|
+
*/
|
|
58
|
+
this.sharpness = nodeObject( sharpness );
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Whether to attenuate sharpening in noisy areas.
|
|
62
|
+
*
|
|
63
|
+
* @type {Node<bool>}
|
|
64
|
+
* @default false
|
|
65
|
+
*/
|
|
66
|
+
this.denoise = nodeObject( denoise );
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The render target for the sharpening pass.
|
|
70
|
+
*
|
|
71
|
+
* @private
|
|
72
|
+
* @type {RenderTarget}
|
|
73
|
+
*/
|
|
74
|
+
this._renderTarget = new RenderTarget( 1, 1, { depthBuffer: false, type: HalfFloatType } );
|
|
75
|
+
this._renderTarget.texture.name = 'SharpenNode.output';
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The result of the effect as a texture node.
|
|
79
|
+
*
|
|
80
|
+
* @private
|
|
81
|
+
* @type {PassTextureNode}
|
|
82
|
+
*/
|
|
83
|
+
this._textureNode = passTexture( this, this._renderTarget.texture );
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The material for the sharpening pass.
|
|
87
|
+
*
|
|
88
|
+
* @private
|
|
89
|
+
* @type {?NodeMaterial}
|
|
90
|
+
*/
|
|
91
|
+
this._material = null;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The `updateBeforeType` is set to `NodeUpdateType.FRAME` since the node renders
|
|
95
|
+
* its effect once per frame in `updateBefore()`.
|
|
96
|
+
*
|
|
97
|
+
* @type {string}
|
|
98
|
+
* @default 'frame'
|
|
99
|
+
*/
|
|
100
|
+
this.updateBeforeType = NodeUpdateType.FRAME;
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Sets the output size of the effect.
|
|
106
|
+
*
|
|
107
|
+
* @param {number} width - The width in pixels.
|
|
108
|
+
* @param {number} height - The height in pixels.
|
|
109
|
+
*/
|
|
110
|
+
setSize( width, height ) {
|
|
111
|
+
|
|
112
|
+
this._renderTarget.setSize( width, height );
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* This method is used to render the effect once per frame.
|
|
118
|
+
*
|
|
119
|
+
* @param {NodeFrame} frame - The current node frame.
|
|
120
|
+
*/
|
|
121
|
+
updateBefore( frame ) {
|
|
122
|
+
|
|
123
|
+
const { renderer } = frame;
|
|
124
|
+
|
|
125
|
+
_rendererState = RendererUtils.resetRendererState( renderer, _rendererState );
|
|
126
|
+
|
|
127
|
+
//
|
|
128
|
+
|
|
129
|
+
renderer.getDrawingBufferSize( _size );
|
|
130
|
+
this.setSize( _size.x, _size.y );
|
|
131
|
+
|
|
132
|
+
renderer.setRenderTarget( this._renderTarget );
|
|
133
|
+
|
|
134
|
+
_quadMesh.material = this._material;
|
|
135
|
+
_quadMesh.name = 'Sharpen [ RCAS ]';
|
|
136
|
+
_quadMesh.render( renderer );
|
|
137
|
+
|
|
138
|
+
//
|
|
139
|
+
|
|
140
|
+
RendererUtils.restoreRendererState( renderer, _rendererState );
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Returns the result of the effect as a texture node.
|
|
146
|
+
*
|
|
147
|
+
* @return {PassTextureNode} A texture node that represents the result of the effect.
|
|
148
|
+
*/
|
|
149
|
+
getTextureNode() {
|
|
150
|
+
|
|
151
|
+
return this._textureNode;
|
|
152
|
+
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* This method is used to setup the effect's TSL code.
|
|
157
|
+
*
|
|
158
|
+
* @param {NodeBuilder} builder - The current node builder.
|
|
159
|
+
* @return {PassTextureNode}
|
|
160
|
+
*/
|
|
161
|
+
setup( builder ) {
|
|
162
|
+
|
|
163
|
+
const textureNode = this.textureNode;
|
|
164
|
+
const inputTex = textureNode.value;
|
|
165
|
+
|
|
166
|
+
// RCAS: Robust Contrast-Adaptive Sharpening.
|
|
167
|
+
//
|
|
168
|
+
// Ported from AMD FidelityFX FSR 1 (ffx_fsr1.h). Uses a 5-tap
|
|
169
|
+
// cross pattern (center + up/down/left/right) to compute a
|
|
170
|
+
// per-pixel sharpening weight that is automatically limited by
|
|
171
|
+
// local contrast to avoid ringing. An optional noise-attenuation
|
|
172
|
+
// factor reduces sharpening in noisy areas.
|
|
173
|
+
|
|
174
|
+
const rcas = Fn( () => {
|
|
175
|
+
|
|
176
|
+
const targetUV = uv();
|
|
177
|
+
const texSize = textureSize( textureLoad( inputTex ) );
|
|
178
|
+
|
|
179
|
+
const p = ivec2( int( floor( targetUV.x.mul( texSize.x ) ) ), int( floor( targetUV.y.mul( texSize.y ) ) ) ).toConst();
|
|
180
|
+
|
|
181
|
+
const e = textureLoad( inputTex, p );
|
|
182
|
+
const b = textureLoad( inputTex, p.add( ivec2( 0, - 1 ) ) );
|
|
183
|
+
const d = textureLoad( inputTex, p.add( ivec2( - 1, 0 ) ) );
|
|
184
|
+
const f = textureLoad( inputTex, p.add( ivec2( 1, 0 ) ) );
|
|
185
|
+
const h = textureLoad( inputTex, p.add( ivec2( 0, 1 ) ) );
|
|
186
|
+
|
|
187
|
+
// Approximate luminance (luma times 2).
|
|
188
|
+
|
|
189
|
+
const luma = ( s ) => s.g.add( s.b.add( s.r ).mul( 0.5 ) );
|
|
190
|
+
|
|
191
|
+
const bL = luma( b );
|
|
192
|
+
const dL = luma( d );
|
|
193
|
+
const eL = luma( e );
|
|
194
|
+
const fL = luma( f );
|
|
195
|
+
const hL = luma( h );
|
|
196
|
+
|
|
197
|
+
// Sharpening amount from user parameter.
|
|
198
|
+
|
|
199
|
+
const con = exp2( this.sharpness.negate() ).toConst();
|
|
200
|
+
|
|
201
|
+
// Min and max of ring.
|
|
202
|
+
|
|
203
|
+
const mn4 = min( min( b.rgb, d.rgb ), min( f.rgb, h.rgb ) ).toConst();
|
|
204
|
+
const mx4 = max( max( b.rgb, d.rgb ), max( f.rgb, h.rgb ) ).toConst();
|
|
205
|
+
|
|
206
|
+
// Compute adaptive lobe weight.
|
|
207
|
+
// Limiters based on how much sharpening the local contrast can tolerate.
|
|
208
|
+
|
|
209
|
+
const RCAS_LIMIT = float( 0.25 - 1.0 / 16.0 ).toConst();
|
|
210
|
+
|
|
211
|
+
const hitMin = min( mn4, e.rgb ).div( mx4.mul( 4.0 ) ).toConst();
|
|
212
|
+
const hitMax = vec3( 1.0 ).sub( max( mx4, e.rgb ) ).div( mn4.mul( 4.0 ).sub( 4.0 ) ).toConst();
|
|
213
|
+
const lobeRGB = max( hitMin.negate(), hitMax ).toConst();
|
|
214
|
+
|
|
215
|
+
const lobe = max(
|
|
216
|
+
RCAS_LIMIT.negate(),
|
|
217
|
+
min( max( lobeRGB.r, max( lobeRGB.g, lobeRGB.b ) ), float( 0.0 ) )
|
|
218
|
+
).mul( con ).toConst();
|
|
219
|
+
|
|
220
|
+
// Noise attenuation.
|
|
221
|
+
|
|
222
|
+
const nz = bL.add( dL ).add( fL ).add( hL ).mul( 0.25 ).sub( eL ).toConst();
|
|
223
|
+
const nzRange = max( max( bL, dL ), max( eL, max( fL, hL ) ) ).sub( min( min( bL, dL ), min( eL, min( fL, hL ) ) ) ).toConst();
|
|
224
|
+
const nzFactor = float( 1.0 ).sub( abs( nz ).div( max( nzRange, float( 1.0 / 65536.0 ) ) ).saturate().mul( 0.5 ) ).toConst();
|
|
225
|
+
|
|
226
|
+
const effectiveLobe = this.denoise.equal( true ).select( lobe.mul( nzFactor ), lobe ).toConst();
|
|
227
|
+
|
|
228
|
+
// Resolve: weighted blend of cross neighbors and center.
|
|
229
|
+
|
|
230
|
+
const result = b.rgb.add( d.rgb ).add( f.rgb ).add( h.rgb ).mul( effectiveLobe ).add( e.rgb )
|
|
231
|
+
.div( effectiveLobe.mul( 4.0 ).add( 1.0 ) ).toConst();
|
|
232
|
+
|
|
233
|
+
return vec4( result, e.a );
|
|
234
|
+
|
|
235
|
+
} );
|
|
236
|
+
|
|
237
|
+
//
|
|
238
|
+
|
|
239
|
+
const context = builder.getSharedContext();
|
|
240
|
+
|
|
241
|
+
const material = this._material || ( this._material = new NodeMaterial() );
|
|
242
|
+
material.fragmentNode = rcas().context( context );
|
|
243
|
+
material.name = 'Sharpen_RCAS';
|
|
244
|
+
material.needsUpdate = true;
|
|
245
|
+
|
|
246
|
+
//
|
|
247
|
+
|
|
248
|
+
const properties = builder.getNodeProperties( this );
|
|
249
|
+
properties.textureNode = textureNode;
|
|
250
|
+
|
|
251
|
+
//
|
|
252
|
+
|
|
253
|
+
return this._textureNode;
|
|
254
|
+
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Frees internal resources. This method should be called
|
|
259
|
+
* when the effect is no longer required.
|
|
260
|
+
*/
|
|
261
|
+
dispose() {
|
|
262
|
+
|
|
263
|
+
this._renderTarget.dispose();
|
|
264
|
+
|
|
265
|
+
if ( this._material !== null ) this._material.dispose();
|
|
266
|
+
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export default SharpenNode;
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* TSL function for creating a sharpen node for post processing.
|
|
275
|
+
*
|
|
276
|
+
* @tsl
|
|
277
|
+
* @function
|
|
278
|
+
* @param {Node<vec4>} node - The node that represents the input of the effect.
|
|
279
|
+
* @param {(number|Node<float>)} [sharpness=0.2] - Sharpening strength. 0 = maximum, 2 = none.
|
|
280
|
+
* @param {(boolean|Node<bool>)} [denoise=false] - Whether to attenuate sharpening in noisy areas.
|
|
281
|
+
* @returns {SharpenNode}
|
|
282
|
+
*/
|
|
283
|
+
export const sharpen = ( node, sharpness, denoise ) => new SharpenNode( convertToTexture( node ), sharpness, denoise );
|