super-three 0.158.0 → 0.160.1
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 +1720 -380
- package/build/three.js +1720 -380
- package/build/three.min.js +1 -1
- package/build/three.module.js +1719 -381
- 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 +24 -19
- 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
|
@@ -6,17 +6,13 @@ export function getCacheKey( object ) {
|
|
|
6
6
|
|
|
7
7
|
if ( object.isNode === true ) {
|
|
8
8
|
|
|
9
|
-
cacheKey +=
|
|
9
|
+
cacheKey += object.id;
|
|
10
10
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
for ( const { property,
|
|
13
|
+
for ( const { property, childNode } of getNodeChildren( object ) ) {
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let childCacheKey = getCacheKey( childNode );
|
|
18
|
-
if ( ! childCacheKey.includes( ',' ) ) childCacheKey = childCacheKey.slice( childCacheKey.indexOf( '"' ), childCacheKey.indexOf( '}' ) );
|
|
19
|
-
cacheKey += `,${ property }${ index !== undefined ? '/' + index : '' }:${ childCacheKey }`;
|
|
15
|
+
cacheKey += ',' + property.slice( 0, - 4 ) + ':' + childNode.getCacheKey();
|
|
20
16
|
|
|
21
17
|
}
|
|
22
18
|
|
|
@@ -20,7 +20,7 @@ class OutputStructNode extends Node {
|
|
|
20
20
|
const members = this.members;
|
|
21
21
|
const types = [];
|
|
22
22
|
|
|
23
|
-
for ( let i = 0; i < members.length; i++ ) {
|
|
23
|
+
for ( let i = 0; i < members.length; i ++ ) {
|
|
24
24
|
|
|
25
25
|
types.push( members[ i ].getNodeType( builder ) );
|
|
26
26
|
|
|
@@ -41,11 +41,11 @@ class OutputStructNode extends Node {
|
|
|
41
41
|
|
|
42
42
|
const structPrefix = propertyName !== '' ? propertyName + '.' : '';
|
|
43
43
|
|
|
44
|
-
for ( let i = 0; i < members.length; i++ ) {
|
|
44
|
+
for ( let i = 0; i < members.length; i ++ ) {
|
|
45
45
|
|
|
46
46
|
const snippet = members[ i ].build( builder, output );
|
|
47
47
|
|
|
48
|
-
builder.addLineFlowCode( `${structPrefix}m${i} = ${snippet}` );
|
|
48
|
+
builder.addLineFlowCode( `${ structPrefix }m${ i } = ${ snippet }` );
|
|
49
49
|
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -3,11 +3,12 @@ import { nodeImmutable, nodeObject } from '../shadernode/ShaderNode.js';
|
|
|
3
3
|
|
|
4
4
|
class PropertyNode extends Node {
|
|
5
5
|
|
|
6
|
-
constructor( nodeType, name = null ) {
|
|
6
|
+
constructor( nodeType, name = null, varying = false ) {
|
|
7
7
|
|
|
8
8
|
super( nodeType );
|
|
9
9
|
|
|
10
10
|
this.name = name;
|
|
11
|
+
this.varying = varying;
|
|
11
12
|
|
|
12
13
|
this.isPropertyNode = true;
|
|
13
14
|
|
|
@@ -27,7 +28,20 @@ class PropertyNode extends Node {
|
|
|
27
28
|
|
|
28
29
|
generate( builder ) {
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
let nodeVar;
|
|
32
|
+
|
|
33
|
+
if ( this.varying === true ) {
|
|
34
|
+
|
|
35
|
+
nodeVar = builder.getVaryingFromNode( this, this.name );
|
|
36
|
+
nodeVar.needsInterpolation = true;
|
|
37
|
+
|
|
38
|
+
} else {
|
|
39
|
+
|
|
40
|
+
nodeVar = builder.getVarFromNode( this, this.name );
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return builder.getPropertyName( nodeVar );
|
|
31
45
|
|
|
32
46
|
}
|
|
33
47
|
|
|
@@ -36,6 +50,7 @@ class PropertyNode extends Node {
|
|
|
36
50
|
export default PropertyNode;
|
|
37
51
|
|
|
38
52
|
export const property = ( type, name ) => nodeObject( new PropertyNode( type, name ) );
|
|
53
|
+
export const varyingProperty = ( type, name ) => nodeObject( new PropertyNode( type, name, true ) );
|
|
39
54
|
|
|
40
55
|
export const diffuseColor = nodeImmutable( PropertyNode, 'vec4', 'DiffuseColor' );
|
|
41
56
|
export const roughness = nodeImmutable( PropertyNode, 'float', 'Roughness' );
|
|
@@ -6,16 +6,16 @@ class StructTypeNode extends Node {
|
|
|
6
6
|
|
|
7
7
|
super();
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
this.types = types;
|
|
10
10
|
this.isStructTypeNode = true;
|
|
11
11
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
getMemberTypes() {
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
return this.types;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
}
|
|
19
19
|
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import Node from './Node.js';
|
|
2
|
+
import { addNodeClass } from './Node.js';
|
|
3
|
+
|
|
4
|
+
class UniformGroupNode extends Node {
|
|
5
|
+
|
|
6
|
+
constructor( name, shared = false ) {
|
|
7
|
+
|
|
8
|
+
super( 'string' );
|
|
9
|
+
|
|
10
|
+
this.name = name;
|
|
11
|
+
this.version = 0;
|
|
12
|
+
|
|
13
|
+
this.shared = shared;
|
|
14
|
+
|
|
15
|
+
this.isUniformGroup = true;
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
set needsUpdate( value ) {
|
|
20
|
+
|
|
21
|
+
if ( value === true ) this.version ++;
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const uniformGroup = ( name ) => new UniformGroupNode( name );
|
|
28
|
+
export const sharedUniformGroup = ( name ) => new UniformGroupNode( name, true );
|
|
29
|
+
|
|
30
|
+
export const frameGroup = sharedUniformGroup( 'frame' );
|
|
31
|
+
export const renderGroup = sharedUniformGroup( 'render' );
|
|
32
|
+
export const objectGroup = uniformGroup( 'object' );
|
|
33
|
+
|
|
34
|
+
export default UniformGroupNode;
|
|
35
|
+
|
|
36
|
+
addNodeClass( 'UniformGroupNode', UniformGroupNode );
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import InputNode from './InputNode.js';
|
|
2
|
+
import { objectGroup } from './UniformGroupNode.js';
|
|
2
3
|
import { addNodeClass } from './Node.js';
|
|
3
4
|
import { nodeObject, getConstNodeType } from '../shadernode/ShaderNode.js';
|
|
4
5
|
|
|
@@ -10,6 +11,22 @@ class UniformNode extends InputNode {
|
|
|
10
11
|
|
|
11
12
|
this.isUniformNode = true;
|
|
12
13
|
|
|
14
|
+
this.groupNode = objectGroup;
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
setGroup( group ) {
|
|
19
|
+
|
|
20
|
+
this.groupNode = group;
|
|
21
|
+
|
|
22
|
+
return this;
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getGroup() {
|
|
27
|
+
|
|
28
|
+
return this.groupNode;
|
|
29
|
+
|
|
13
30
|
}
|
|
14
31
|
|
|
15
32
|
getUniformHash( builder ) {
|
|
@@ -40,17 +40,11 @@ class VaryingNode extends Node {
|
|
|
40
40
|
const { name, node } = this;
|
|
41
41
|
const type = this.getNodeType( builder );
|
|
42
42
|
|
|
43
|
-
const nodeVarying = builder.getVaryingFromNode( this, type );
|
|
43
|
+
const nodeVarying = builder.getVaryingFromNode( this, name, type );
|
|
44
44
|
|
|
45
45
|
// this property can be used to check if the varying can be optimized for a var
|
|
46
46
|
nodeVarying.needsInterpolation || ( nodeVarying.needsInterpolation = ( builder.shaderStage === 'fragment' ) );
|
|
47
47
|
|
|
48
|
-
if ( name !== null ) {
|
|
49
|
-
|
|
50
|
-
nodeVarying.name = name;
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
48
|
const propertyName = builder.getPropertyName( nodeVarying, NodeShaderStage.VERTEX );
|
|
55
49
|
|
|
56
50
|
// force node run in vertex stage
|
|
@@ -35,7 +35,7 @@ const dHdxy_fwd = tslFn( ( { textureNode, bumpScale } ) => {
|
|
|
35
35
|
const uvNode = texNode.uvNode || uv();
|
|
36
36
|
|
|
37
37
|
// It's used to preserve the same TextureNode instance
|
|
38
|
-
const sampleTexture = ( uv ) => textureNode.cache().context( {
|
|
38
|
+
const sampleTexture = ( uv ) => textureNode.cache().context( { getUV: () => uv, forceUVContext: true } );
|
|
39
39
|
|
|
40
40
|
return vec2(
|
|
41
41
|
float( sampleTexture( uvNode.add( uvNode.dFdx() ) ) ).sub( Hll ),
|
|
@@ -2,11 +2,11 @@ import TempNode from '../core/TempNode.js';
|
|
|
2
2
|
import { dot, mix } from '../math/MathNode.js';
|
|
3
3
|
import { add } from '../math/OperatorNode.js';
|
|
4
4
|
import { addNodeClass } from '../core/Node.js';
|
|
5
|
-
import { addNodeElement, tslFn, nodeProxy, float, vec3
|
|
5
|
+
import { addNodeElement, tslFn, nodeProxy, float, vec3 } from '../shadernode/ShaderNode.js';
|
|
6
6
|
|
|
7
7
|
const saturationNode = tslFn( ( { color, adjustment } ) => {
|
|
8
8
|
|
|
9
|
-
return adjustment.mix( luminance( color ), color );
|
|
9
|
+
return adjustment.mix( luminance( color.rgb ), color.rgb );
|
|
10
10
|
|
|
11
11
|
} );
|
|
12
12
|
|
|
@@ -17,21 +17,17 @@ const vibranceNode = tslFn( ( { color, adjustment } ) => {
|
|
|
17
17
|
const mx = color.r.max( color.g.max( color.b ) );
|
|
18
18
|
const amt = mx.sub( average ).mul( adjustment ).mul( - 3.0 );
|
|
19
19
|
|
|
20
|
-
return mix( color, mx, amt );
|
|
20
|
+
return mix( color.rgb, mx, amt );
|
|
21
21
|
|
|
22
22
|
} );
|
|
23
23
|
|
|
24
24
|
const hueNode = tslFn( ( { color, adjustment } ) => {
|
|
25
25
|
|
|
26
|
-
const
|
|
27
|
-
const YIQtoRGB = mat3( 1.0, 0.9563, 0.6210, 1.0, - 0.2721, - 0.6474, 1.0, - 1.107, 1.7046 );
|
|
26
|
+
const k = vec3( 0.57735, 0.57735, 0.57735 );
|
|
28
27
|
|
|
29
|
-
const
|
|
28
|
+
const cosAngle = adjustment.cos();
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
const chroma = yiq.yz.length();
|
|
33
|
-
|
|
34
|
-
return YIQtoRGB.mul( vec3( yiq.x, chroma.mul( hue.cos() ), chroma.mul( hue.sin() ) ) );
|
|
30
|
+
return vec3( color.rgb.mul( cosAngle ).add( k.cross( color.rgb ).mul( adjustment.sin() ).add( k.mul( dot( k, color.rgb ).mul( cosAngle.oneMinus() ) ) ) ) );
|
|
35
31
|
|
|
36
32
|
} );
|
|
37
33
|
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import TempNode from '../core/TempNode.js';
|
|
2
|
+
import { nodeObject, addNodeElement, tslFn, float, vec2, vec3, vec4 } from '../shadernode/ShaderNode.js';
|
|
3
|
+
import { NodeUpdateType } from '../core/constants.js';
|
|
4
|
+
import { mul } from '../math/OperatorNode.js';
|
|
5
|
+
import { uv } from '../accessors/UVNode.js';
|
|
6
|
+
import { texture } from '../accessors/TextureNode.js';
|
|
7
|
+
import { uniform } from '../core/UniformNode.js';
|
|
8
|
+
import { Vector2, RenderTarget } from 'three';
|
|
9
|
+
import QuadMesh from '../../objects/QuadMesh.js';
|
|
10
|
+
|
|
11
|
+
const quadMesh = new QuadMesh();
|
|
12
|
+
|
|
13
|
+
class GaussianBlurNode extends TempNode {
|
|
14
|
+
|
|
15
|
+
constructor( textureNode, sigma = 2 ) {
|
|
16
|
+
|
|
17
|
+
super( textureNode );
|
|
18
|
+
|
|
19
|
+
this.textureNode = textureNode;
|
|
20
|
+
this.sigma = sigma;
|
|
21
|
+
|
|
22
|
+
this.directionNode = vec2( 1 );
|
|
23
|
+
|
|
24
|
+
this._invSize = uniform( new Vector2() );
|
|
25
|
+
this._passDirection = uniform( new Vector2() );
|
|
26
|
+
|
|
27
|
+
this._horizontalRT = new RenderTarget();
|
|
28
|
+
this._verticalRT = new RenderTarget();
|
|
29
|
+
|
|
30
|
+
this.updateBeforeType = NodeUpdateType.RENDER;
|
|
31
|
+
|
|
32
|
+
this.resolution = new Vector2( 1, 1 );
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
setSize( width, height ) {
|
|
37
|
+
|
|
38
|
+
width = Math.max( Math.round( width * this.resolution.x ), 1 );
|
|
39
|
+
height = Math.max( Math.round( height * this.resolution.y ), 1 );
|
|
40
|
+
|
|
41
|
+
this._invSize.value.set( 1 / width, 1 / height );
|
|
42
|
+
this._horizontalRT.setSize( width, height );
|
|
43
|
+
this._verticalRT.setSize( width, height );
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
updateBefore( frame ) {
|
|
48
|
+
|
|
49
|
+
const { renderer } = frame;
|
|
50
|
+
|
|
51
|
+
const textureNode = this.textureNode;
|
|
52
|
+
const map = textureNode.value;
|
|
53
|
+
|
|
54
|
+
const currentRenderTarget = renderer.getRenderTarget();
|
|
55
|
+
const currentTexture = textureNode.value;
|
|
56
|
+
|
|
57
|
+
quadMesh.material = this._material;
|
|
58
|
+
|
|
59
|
+
this.setSize( map.image.width, map.image.height );
|
|
60
|
+
|
|
61
|
+
// horizontal
|
|
62
|
+
|
|
63
|
+
renderer.setRenderTarget( this._horizontalRT );
|
|
64
|
+
|
|
65
|
+
this._passDirection.value.set( 1, 0 );
|
|
66
|
+
|
|
67
|
+
quadMesh.render( renderer );
|
|
68
|
+
|
|
69
|
+
// vertical
|
|
70
|
+
|
|
71
|
+
textureNode.value = this._horizontalRT.texture;
|
|
72
|
+
renderer.setRenderTarget( this._verticalRT );
|
|
73
|
+
|
|
74
|
+
this._passDirection.value.set( 0, 1 );
|
|
75
|
+
|
|
76
|
+
quadMesh.render( renderer );
|
|
77
|
+
|
|
78
|
+
// restore
|
|
79
|
+
|
|
80
|
+
renderer.setRenderTarget( currentRenderTarget );
|
|
81
|
+
textureNode.value = currentTexture;
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
setup( builder ) {
|
|
86
|
+
|
|
87
|
+
const textureNode = this.textureNode;
|
|
88
|
+
|
|
89
|
+
if ( textureNode.isTextureNode !== true ) {
|
|
90
|
+
|
|
91
|
+
console.error( 'GaussianBlurNode requires a TextureNode.' );
|
|
92
|
+
|
|
93
|
+
return vec4();
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//
|
|
98
|
+
|
|
99
|
+
const uvNode = textureNode.uvNode || uv();
|
|
100
|
+
|
|
101
|
+
const sampleTexture = ( uv ) => textureNode.cache().context( { getUV: () => uv, forceUVContext: true } );
|
|
102
|
+
|
|
103
|
+
const blur = tslFn( () => {
|
|
104
|
+
|
|
105
|
+
const kernelSize = 3 + ( 2 * this.sigma );
|
|
106
|
+
const gaussianCoefficients = this._getCoefficients( kernelSize );
|
|
107
|
+
|
|
108
|
+
const invSize = this._invSize;
|
|
109
|
+
const direction = vec2( this.directionNode ).mul( this._passDirection );
|
|
110
|
+
|
|
111
|
+
const weightSum = float( gaussianCoefficients[ 0 ] ).toVar();
|
|
112
|
+
const diffuseSum = vec3( sampleTexture( uvNode ).mul( weightSum ) ).toVar();
|
|
113
|
+
|
|
114
|
+
for ( let i = 1; i < kernelSize; i ++ ) {
|
|
115
|
+
|
|
116
|
+
const x = float( i );
|
|
117
|
+
const w = float( gaussianCoefficients[ i ] );
|
|
118
|
+
|
|
119
|
+
const uvOffset = vec2( direction.mul( invSize.mul( x ) ) ).toVar();
|
|
120
|
+
|
|
121
|
+
const sample1 = vec3( sampleTexture( uvNode.add( uvOffset ) ) );
|
|
122
|
+
const sample2 = vec3( sampleTexture( uvNode.sub( uvOffset ) ) );
|
|
123
|
+
|
|
124
|
+
diffuseSum.addAssign( sample1.add( sample2 ).mul( w ) );
|
|
125
|
+
weightSum.addAssign( mul( 2.0, w ) );
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return vec4( diffuseSum.div( weightSum ), 1.0 );
|
|
130
|
+
|
|
131
|
+
} );
|
|
132
|
+
|
|
133
|
+
//
|
|
134
|
+
|
|
135
|
+
const material = this._material || ( this._material = builder.createNodeMaterial( 'MeshBasicNodeMaterial' ) );
|
|
136
|
+
material.fragmentNode = blur();
|
|
137
|
+
|
|
138
|
+
//
|
|
139
|
+
|
|
140
|
+
const properties = builder.getNodeProperties( this );
|
|
141
|
+
properties.textureNode = textureNode;
|
|
142
|
+
|
|
143
|
+
//
|
|
144
|
+
|
|
145
|
+
return texture( this._verticalRT.texture );
|
|
146
|
+
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
_getCoefficients( kernelRadius ) {
|
|
150
|
+
|
|
151
|
+
const coefficients = [];
|
|
152
|
+
|
|
153
|
+
for ( let i = 0; i < kernelRadius; i ++ ) {
|
|
154
|
+
|
|
155
|
+
coefficients.push( 0.39894 * Math.exp( - 0.5 * i * i / ( kernelRadius * kernelRadius ) ) / kernelRadius );
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return coefficients;
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export const gaussianBlur = ( node, sigma ) => nodeObject( new GaussianBlurNode( nodeObject( node ), sigma ) );
|
|
166
|
+
|
|
167
|
+
addNodeElement( 'gaussianBlur', gaussianBlur );
|
|
168
|
+
|
|
169
|
+
export default GaussianBlurNode;
|
|
170
|
+
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { addNodeClass } from '../core/Node.js';
|
|
2
|
+
import TempNode from '../core/TempNode.js';
|
|
3
|
+
import TextureNode from '../accessors/TextureNode.js';
|
|
4
|
+
import { NodeUpdateType } from '../core/constants.js';
|
|
5
|
+
import { nodeObject } from '../shadernode/ShaderNode.js';
|
|
6
|
+
import { uniform } from '../core/UniformNode.js';
|
|
7
|
+
import { viewZToOrthographicDepth, perspectiveDepthToViewZ } from './ViewportDepthNode.js';
|
|
8
|
+
import { RenderTarget, Vector2, HalfFloatType, DepthTexture, FloatType, NoToneMapping } from 'three';
|
|
9
|
+
|
|
10
|
+
class PassTextureNode extends TextureNode {
|
|
11
|
+
|
|
12
|
+
constructor( passNode, texture ) {
|
|
13
|
+
|
|
14
|
+
super( texture );
|
|
15
|
+
|
|
16
|
+
this.passNode = passNode;
|
|
17
|
+
|
|
18
|
+
this.setUpdateMatrix( false );
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
setup( builder ) {
|
|
23
|
+
|
|
24
|
+
this.passNode.build( builder );
|
|
25
|
+
|
|
26
|
+
return super.setup( builder );
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
clone() {
|
|
31
|
+
|
|
32
|
+
return new this.constructor( this.passNode, this.value );
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class PassNode extends TempNode {
|
|
39
|
+
|
|
40
|
+
constructor( scope, scene, camera ) {
|
|
41
|
+
|
|
42
|
+
super( 'vec4' );
|
|
43
|
+
|
|
44
|
+
this.scope = scope;
|
|
45
|
+
this.scene = scene;
|
|
46
|
+
this.camera = camera;
|
|
47
|
+
|
|
48
|
+
this._pixelRatio = 1;
|
|
49
|
+
this._width = 1;
|
|
50
|
+
this._height = 1;
|
|
51
|
+
|
|
52
|
+
const depthTexture = new DepthTexture();
|
|
53
|
+
depthTexture.isRenderTargetTexture = true;
|
|
54
|
+
depthTexture.type = FloatType;
|
|
55
|
+
depthTexture.name = 'PostProcessingDepth';
|
|
56
|
+
|
|
57
|
+
const renderTarget = new RenderTarget( this._width * this._pixelRatio, this._height * this._pixelRatio, { type: HalfFloatType } );
|
|
58
|
+
renderTarget.texture.name = 'PostProcessing';
|
|
59
|
+
renderTarget.depthTexture = depthTexture;
|
|
60
|
+
|
|
61
|
+
this.renderTarget = renderTarget;
|
|
62
|
+
|
|
63
|
+
this.updateBeforeType = NodeUpdateType.FRAME;
|
|
64
|
+
|
|
65
|
+
this._textureNode = nodeObject( new PassTextureNode( this, renderTarget.texture ) );
|
|
66
|
+
this._depthTextureNode = nodeObject( new PassTextureNode( this, depthTexture ) );
|
|
67
|
+
|
|
68
|
+
this._depthNode = null;
|
|
69
|
+
this._cameraNear = uniform( 0 );
|
|
70
|
+
this._cameraFar = uniform( 0 );
|
|
71
|
+
|
|
72
|
+
this.isPassNode = true;
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
isGlobal() {
|
|
77
|
+
|
|
78
|
+
return true;
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
getTextureNode() {
|
|
83
|
+
|
|
84
|
+
return this._textureNode;
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
getTextureDepthNode() {
|
|
89
|
+
|
|
90
|
+
return this._depthTextureNode;
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getDepthNode() {
|
|
95
|
+
|
|
96
|
+
if ( this._depthNode === null ) {
|
|
97
|
+
|
|
98
|
+
const cameraNear = this._cameraNear;
|
|
99
|
+
const cameraFar = this._cameraFar;
|
|
100
|
+
|
|
101
|
+
this._depthNode = viewZToOrthographicDepth( perspectiveDepthToViewZ( this._depthTextureNode, cameraNear, cameraFar ), cameraNear, cameraFar );
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return this._depthNode;
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
setup() {
|
|
110
|
+
|
|
111
|
+
return this.scope === PassNode.COLOR ? this.getTextureNode() : this.getDepthNode();
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
updateBefore( frame ) {
|
|
116
|
+
|
|
117
|
+
const { renderer } = frame;
|
|
118
|
+
const { scene, camera } = this;
|
|
119
|
+
|
|
120
|
+
this._pixelRatio = renderer.getPixelRatio();
|
|
121
|
+
|
|
122
|
+
const size = renderer.getSize( new Vector2() );
|
|
123
|
+
|
|
124
|
+
this.setSize( size.width, size.height );
|
|
125
|
+
|
|
126
|
+
const currentToneMapping = renderer.toneMapping;
|
|
127
|
+
const currentToneMappingNode = renderer.toneMappingNode;
|
|
128
|
+
const currentRenderTarget = renderer.getRenderTarget();
|
|
129
|
+
|
|
130
|
+
this._cameraNear.value = camera.near;
|
|
131
|
+
this._cameraFar.value = camera.far;
|
|
132
|
+
|
|
133
|
+
renderer.toneMapping = NoToneMapping;
|
|
134
|
+
renderer.toneMappingNode = null;
|
|
135
|
+
renderer.setRenderTarget( this.renderTarget );
|
|
136
|
+
|
|
137
|
+
renderer.render( scene, camera );
|
|
138
|
+
|
|
139
|
+
renderer.toneMapping = currentToneMapping;
|
|
140
|
+
renderer.toneMappingNode = currentToneMappingNode;
|
|
141
|
+
renderer.setRenderTarget( currentRenderTarget );
|
|
142
|
+
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
setSize( width, height ) {
|
|
146
|
+
|
|
147
|
+
this._width = width;
|
|
148
|
+
this._height = height;
|
|
149
|
+
|
|
150
|
+
const effectiveWidth = this._width * this._pixelRatio;
|
|
151
|
+
const effectiveHeight = this._height * this._pixelRatio;
|
|
152
|
+
|
|
153
|
+
this.renderTarget.setSize( effectiveWidth, effectiveHeight );
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
setPixelRatio( pixelRatio ) {
|
|
158
|
+
|
|
159
|
+
this._pixelRatio = pixelRatio;
|
|
160
|
+
|
|
161
|
+
this.setSize( this._width, this._height );
|
|
162
|
+
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
dispose() {
|
|
166
|
+
|
|
167
|
+
this.renderTarget.dispose();
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
PassNode.COLOR = 'color';
|
|
175
|
+
PassNode.DEPTH = 'depth';
|
|
176
|
+
|
|
177
|
+
export default PassNode;
|
|
178
|
+
|
|
179
|
+
export const pass = ( scene, camera ) => nodeObject( new PassNode( PassNode.COLOR, scene, camera ) );
|
|
180
|
+
export const depthPass = ( scene, camera ) => nodeObject( new PassNode( PassNode.DEPTH, scene, camera ) );
|
|
181
|
+
|
|
182
|
+
addNodeClass( 'PassNode', PassNode );
|
|
@@ -6,17 +6,31 @@ import { viewportDepthTexture } from './ViewportDepthTextureNode.js';
|
|
|
6
6
|
|
|
7
7
|
class ViewportDepthNode extends Node {
|
|
8
8
|
|
|
9
|
-
constructor( scope,
|
|
9
|
+
constructor( scope, valueNode = null ) {
|
|
10
10
|
|
|
11
11
|
super( 'float' );
|
|
12
12
|
|
|
13
13
|
this.scope = scope;
|
|
14
|
-
this.
|
|
14
|
+
this.valueNode = valueNode;
|
|
15
15
|
|
|
16
16
|
this.isViewportDepthNode = true;
|
|
17
17
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
generate( builder ) {
|
|
21
|
+
|
|
22
|
+
const { scope } = this;
|
|
23
|
+
|
|
24
|
+
if ( scope === ViewportDepthNode.DEPTH_PIXEL ) {
|
|
25
|
+
|
|
26
|
+
return builder.getFragDepth();
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return super.generate( builder );
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
20
34
|
setup( /*builder*/ ) {
|
|
21
35
|
|
|
22
36
|
const { scope } = this;
|
|
@@ -29,11 +43,19 @@ class ViewportDepthNode extends Node {
|
|
|
29
43
|
|
|
30
44
|
} else if ( scope === ViewportDepthNode.DEPTH_TEXTURE ) {
|
|
31
45
|
|
|
32
|
-
const texture = this.
|
|
46
|
+
const texture = this.valueNode || viewportDepthTexture();
|
|
33
47
|
|
|
34
48
|
const viewZ = perspectiveDepthToViewZ( texture, cameraNear, cameraFar );
|
|
35
49
|
node = viewZToOrthographicDepth( viewZ, cameraNear, cameraFar );
|
|
36
50
|
|
|
51
|
+
} else if ( scope === ViewportDepthNode.DEPTH_PIXEL ) {
|
|
52
|
+
|
|
53
|
+
if ( this.valueNode !== null ) {
|
|
54
|
+
|
|
55
|
+
node = depthPixelBase().assign( this.valueNode );
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
37
59
|
}
|
|
38
60
|
|
|
39
61
|
return node;
|
|
@@ -60,10 +82,16 @@ export const perspectiveDepthToViewZ = ( depth, near, far ) => near.mul( far ).d
|
|
|
60
82
|
|
|
61
83
|
ViewportDepthNode.DEPTH = 'depth';
|
|
62
84
|
ViewportDepthNode.DEPTH_TEXTURE = 'depthTexture';
|
|
85
|
+
ViewportDepthNode.DEPTH_PIXEL = 'depthPixel';
|
|
63
86
|
|
|
64
87
|
export default ViewportDepthNode;
|
|
65
88
|
|
|
89
|
+
const depthPixelBase = nodeProxy( ViewportDepthNode, ViewportDepthNode.DEPTH_PIXEL );
|
|
90
|
+
|
|
66
91
|
export const depth = nodeImmutable( ViewportDepthNode, ViewportDepthNode.DEPTH );
|
|
67
92
|
export const depthTexture = nodeProxy( ViewportDepthNode, ViewportDepthNode.DEPTH_TEXTURE );
|
|
93
|
+
export const depthPixel = nodeImmutable( ViewportDepthNode, ViewportDepthNode.DEPTH_PIXEL );
|
|
94
|
+
|
|
95
|
+
depthPixel.assign = ( value ) => depthPixelBase( value );
|
|
68
96
|
|
|
69
97
|
addNodeClass( 'ViewportDepthNode', ViewportDepthNode );
|