super-three 0.160.0 → 0.161.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/LICENSE +1 -1
- package/build/three.cjs +380 -109
- package/build/three.module.js +381 -109
- package/build/three.module.min.js +1 -1
- package/examples/jsm/Addons.js +5 -1
- package/examples/jsm/capabilities/WebGPU.js +13 -9
- package/examples/jsm/controls/OrbitControls.js +102 -13
- package/examples/jsm/curves/NURBSUtils.js +59 -4
- package/examples/jsm/curves/NURBSVolume.js +62 -0
- package/examples/jsm/exporters/USDZExporter.js +8 -7
- package/examples/jsm/helpers/TextureHelper.js +3 -3
- package/examples/jsm/loaders/3DMLoader.js +44 -43
- package/examples/jsm/loaders/DDSLoader.js +1 -0
- package/examples/jsm/loaders/KTX2Loader.js +20 -5
- package/examples/jsm/loaders/LUT3dlLoader.js +78 -46
- package/examples/jsm/loaders/LUTCubeLoader.js +81 -67
- package/examples/jsm/loaders/LUTImageLoader.js +3 -2
- package/examples/jsm/loaders/MaterialXLoader.js +115 -16
- package/examples/jsm/loaders/SVGLoader.js +4 -3
- package/examples/jsm/loaders/VRMLLoader.js +1 -1
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +144 -0
- package/examples/jsm/misc/Timer.js +13 -4
- package/examples/jsm/nodes/Nodes.js +16 -5
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +5 -3
- package/examples/jsm/nodes/accessors/CameraNode.js +9 -4
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +12 -1
- package/examples/jsm/nodes/accessors/StorageBufferNode.js +27 -0
- package/examples/jsm/nodes/accessors/TextureStoreNode.js +56 -3
- package/examples/jsm/nodes/accessors/VertexColorNode.js +70 -0
- package/examples/jsm/nodes/core/AttributeNode.js +1 -1
- package/examples/jsm/nodes/core/NodeBuilder.js +23 -18
- package/examples/jsm/nodes/core/NodeFrame.js +16 -8
- package/examples/jsm/nodes/core/constants.js +1 -0
- package/examples/jsm/nodes/display/AfterImageNode.js +148 -0
- package/examples/jsm/nodes/display/AnamorphicNode.js +148 -0
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +3 -0
- package/examples/jsm/nodes/display/GaussianBlurNode.js +33 -13
- package/examples/jsm/nodes/display/PassNode.js +3 -2
- package/examples/jsm/nodes/display/ToneMappingNode.js +46 -3
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +1 -4
- package/examples/jsm/nodes/display/ViewportNode.js +0 -2
- package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +4 -4
- package/examples/jsm/nodes/fog/FogNode.js +2 -1
- package/examples/jsm/nodes/lighting/AmbientLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +13 -5
- package/examples/jsm/nodes/lighting/LightingContextNode.js +1 -1
- package/examples/jsm/nodes/lighting/LightsNode.js +1 -1
- package/examples/jsm/nodes/materials/Line2NodeMaterial.js +18 -30
- package/examples/jsm/nodes/materials/Materials.js +1 -0
- package/examples/jsm/nodes/materials/MeshSSSNodeMaterial.js +84 -0
- package/examples/jsm/nodes/materials/NodeMaterial.js +6 -4
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +1 -7
- package/examples/jsm/nodes/math/MathNode.js +12 -2
- package/examples/jsm/nodes/math/MathUtils.js +15 -0
- package/examples/jsm/nodes/math/OperatorNode.js +13 -5
- package/examples/jsm/nodes/math/TriNoise3D.js +71 -0
- package/examples/jsm/nodes/shadernode/ShaderNode.js +10 -1
- package/examples/jsm/nodes/utils/ArrayElementNode.js +6 -0
- package/examples/jsm/nodes/utils/JoinNode.js +2 -2
- package/examples/jsm/nodes/utils/LoopNode.js +3 -3
- package/examples/jsm/nodes/utils/ReflectorNode.js +227 -0
- package/examples/jsm/nodes/utils/RotateNode.js +68 -0
- package/examples/jsm/nodes/utils/RotateUVNode.js +1 -9
- package/examples/jsm/nodes/utils/SplitNode.js +4 -4
- package/examples/jsm/objects/GroundedSkybox.js +50 -0
- package/examples/jsm/objects/QuadMesh.js +8 -2
- package/examples/jsm/objects/Water2.js +8 -8
- package/examples/jsm/postprocessing/GTAOPass.js +11 -1
- package/examples/jsm/renderers/common/Backend.js +14 -0
- package/examples/jsm/renderers/common/Bindings.js +1 -1
- package/examples/jsm/renderers/common/DataMap.js +1 -1
- package/examples/jsm/renderers/common/Info.js +25 -1
- package/examples/jsm/renderers/common/Pipelines.js +8 -8
- package/examples/jsm/renderers/common/PostProcessing.js +2 -2
- package/examples/jsm/renderers/common/ProgrammableStage.js +3 -1
- package/examples/jsm/renderers/common/RenderObject.js +2 -0
- package/examples/jsm/renderers/common/Renderer.js +238 -22
- package/examples/jsm/renderers/common/StorageBufferAttribute.js +17 -0
- package/examples/jsm/renderers/common/Textures.js +25 -5
- package/examples/jsm/renderers/common/nodes/NodeBuilderState.js +2 -1
- package/examples/jsm/renderers/common/nodes/Nodes.js +4 -2
- package/examples/jsm/renderers/webgl/WebGLBackend.js +631 -270
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +37 -30
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +89 -8
- package/examples/jsm/renderers/webgl/utils/WebGLConstants.js +11 -0
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +197 -0
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +377 -11
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +2 -2
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +1 -21
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +2 -2
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +289 -102
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +7 -2
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +56 -39
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +9 -1
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +38 -4
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +85 -12
- package/examples/jsm/transpiler/AST.js +1 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
- package/examples/jsm/transpiler/TSLEncoder.js +1 -1
- package/examples/jsm/utils/BufferGeometryUtils.js +23 -27
- package/examples/jsm/utils/SortUtils.js +2 -0
- package/examples/jsm/webxr/ARButton.js +12 -2
- package/examples/jsm/webxr/VRButton.js +12 -2
- package/examples/jsm/webxr/XRButton.js +12 -2
- package/examples/jsm/webxr/XRControllerModelFactory.js +6 -1
- package/examples/jsm/webxr/XRHandMeshModel.js +3 -1
- package/package.json +2 -2
- package/src/audio/Audio.js +1 -3
- package/src/cameras/PerspectiveCamera.js +35 -0
- package/src/constants.js +1 -2
- package/src/core/BufferAttribute.js +2 -1
- package/src/core/InterleavedBuffer.js +2 -1
- package/src/core/InterleavedBufferAttribute.js +20 -0
- package/src/materials/ShaderMaterial.js +2 -1
- package/src/math/Triangle.js +0 -30
- package/src/objects/BatchedMesh.js +6 -7
- package/src/objects/SkinnedMesh.js +0 -8
- package/src/renderers/WebGLRenderer.js +6 -2
- package/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js +9 -0
- package/src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl.js +56 -11
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +15 -7
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +3 -1
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/points.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +1 -1
- package/src/renderers/webgl/WebGLAttributes.js +2 -2
- package/src/renderers/webgl/WebGLCubeMaps.js +1 -1
- package/src/renderers/webgl/WebGLProgram.js +30 -3
- package/src/renderers/webgl/WebGLPrograms.js +19 -11
- package/src/renderers/webgl/WebGLTextures.js +90 -16
- package/src/renderers/webxr/WebXRDepthSensing.js +105 -0
- package/src/renderers/webxr/WebXRManager.js +46 -0
- package/src/textures/Source.js +1 -0
- package/build/three.js +0 -54519
- package/build/three.min.js +0 -7
- package/examples/jsm/objects/GroundProjectedSkybox.js +0 -172
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import TextureNode from '../accessors/TextureNode.js';
|
|
2
|
+
import { nodeObject, vec2 } from '../shadernode/ShaderNode.js';
|
|
3
|
+
import { NodeUpdateType } from '../core/constants.js';
|
|
4
|
+
import { viewportTopLeft } from '../display/ViewportNode.js';
|
|
5
|
+
import { Matrix4, Vector2, Vector3, Vector4, Object3D, Plane, RenderTarget, HalfFloatType, LinearMipMapLinearFilter } from 'three';
|
|
6
|
+
|
|
7
|
+
const _reflectorPlane = new Plane();
|
|
8
|
+
const _normal = new Vector3();
|
|
9
|
+
const _reflectorWorldPosition = new Vector3();
|
|
10
|
+
const _cameraWorldPosition = new Vector3();
|
|
11
|
+
const _rotationMatrix = new Matrix4();
|
|
12
|
+
const _lookAtPosition = new Vector3( 0, 0, - 1 );
|
|
13
|
+
const clipPlane = new Vector4();
|
|
14
|
+
|
|
15
|
+
const _view = new Vector3();
|
|
16
|
+
const _target = new Vector3();
|
|
17
|
+
const _q = new Vector4();
|
|
18
|
+
|
|
19
|
+
const _size = new Vector2();
|
|
20
|
+
|
|
21
|
+
const _defaultRT = new RenderTarget();
|
|
22
|
+
const _defaultUV = vec2( viewportTopLeft.x.oneMinus(), viewportTopLeft.y );
|
|
23
|
+
|
|
24
|
+
let _inReflector = false;
|
|
25
|
+
|
|
26
|
+
class ReflectorNode extends TextureNode {
|
|
27
|
+
|
|
28
|
+
constructor( parameters = {} ) {
|
|
29
|
+
|
|
30
|
+
super( _defaultRT.texture, _defaultUV );
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
target = new Object3D(),
|
|
34
|
+
resolution = 1,
|
|
35
|
+
generateMipmaps = false,
|
|
36
|
+
bounces = true
|
|
37
|
+
} = parameters;
|
|
38
|
+
|
|
39
|
+
//
|
|
40
|
+
|
|
41
|
+
this.target = target;
|
|
42
|
+
this.resolution = resolution;
|
|
43
|
+
this.generateMipmaps = generateMipmaps;
|
|
44
|
+
this.bounces = bounces;
|
|
45
|
+
|
|
46
|
+
this.updateBeforeType = bounces ? NodeUpdateType.RENDER : NodeUpdateType.FRAME;
|
|
47
|
+
|
|
48
|
+
this.virtualCameras = new WeakMap();
|
|
49
|
+
this.renderTargets = new WeakMap();
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
_updateResolution( renderTarget, renderer ) {
|
|
55
|
+
|
|
56
|
+
const resolution = this.resolution;
|
|
57
|
+
|
|
58
|
+
renderer.getDrawingBufferSize( _size );
|
|
59
|
+
|
|
60
|
+
renderTarget.setSize( Math.round( _size.width * resolution ), Math.round( _size.height * resolution ) );
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
setup( builder ) {
|
|
65
|
+
|
|
66
|
+
this._updateResolution( _defaultRT, builder.renderer );
|
|
67
|
+
|
|
68
|
+
return super.setup( builder );
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getTextureNode() {
|
|
73
|
+
|
|
74
|
+
return this.textureNode;
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getVirtualCamera( camera ) {
|
|
79
|
+
|
|
80
|
+
let virtualCamera = this.virtualCameras.get( camera );
|
|
81
|
+
|
|
82
|
+
if ( virtualCamera === undefined ) {
|
|
83
|
+
|
|
84
|
+
virtualCamera = camera.clone();
|
|
85
|
+
|
|
86
|
+
this.virtualCameras.set( camera, virtualCamera );
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return virtualCamera;
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getRenderTarget( camera ) {
|
|
95
|
+
|
|
96
|
+
let renderTarget = this.renderTargets.get( camera );
|
|
97
|
+
|
|
98
|
+
if ( renderTarget === undefined ) {
|
|
99
|
+
|
|
100
|
+
renderTarget = new RenderTarget( 0, 0, { type: HalfFloatType } );
|
|
101
|
+
|
|
102
|
+
if ( this.generateMipmaps === true ) {
|
|
103
|
+
|
|
104
|
+
renderTarget.texture.minFilter = LinearMipMapLinearFilter;
|
|
105
|
+
renderTarget.texture.generateMipmaps = true;
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
this.renderTargets.set( camera, renderTarget );
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return renderTarget;
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
updateBefore( frame ) {
|
|
118
|
+
|
|
119
|
+
if ( this.bounces === false && _inReflector ) return false;
|
|
120
|
+
|
|
121
|
+
_inReflector = true;
|
|
122
|
+
|
|
123
|
+
const { scene, camera, renderer, material } = frame;
|
|
124
|
+
const { target } = this;
|
|
125
|
+
|
|
126
|
+
const virtualCamera = this.getVirtualCamera( camera );
|
|
127
|
+
const renderTarget = this.getRenderTarget( virtualCamera );
|
|
128
|
+
|
|
129
|
+
renderer.getDrawingBufferSize( _size );
|
|
130
|
+
|
|
131
|
+
this._updateResolution( renderTarget, renderer );
|
|
132
|
+
|
|
133
|
+
//
|
|
134
|
+
|
|
135
|
+
_reflectorWorldPosition.setFromMatrixPosition( target.matrixWorld );
|
|
136
|
+
_cameraWorldPosition.setFromMatrixPosition( camera.matrixWorld );
|
|
137
|
+
|
|
138
|
+
_rotationMatrix.extractRotation( target.matrixWorld );
|
|
139
|
+
|
|
140
|
+
_normal.set( 0, 0, 1 );
|
|
141
|
+
_normal.applyMatrix4( _rotationMatrix );
|
|
142
|
+
|
|
143
|
+
_view.subVectors( _reflectorWorldPosition, _cameraWorldPosition );
|
|
144
|
+
|
|
145
|
+
// Avoid rendering when reflector is facing away
|
|
146
|
+
|
|
147
|
+
if ( _view.dot( _normal ) > 0 ) return;
|
|
148
|
+
|
|
149
|
+
_view.reflect( _normal ).negate();
|
|
150
|
+
_view.add( _reflectorWorldPosition );
|
|
151
|
+
|
|
152
|
+
_rotationMatrix.extractRotation( camera.matrixWorld );
|
|
153
|
+
|
|
154
|
+
_lookAtPosition.set( 0, 0, - 1 );
|
|
155
|
+
_lookAtPosition.applyMatrix4( _rotationMatrix );
|
|
156
|
+
_lookAtPosition.add( _cameraWorldPosition );
|
|
157
|
+
|
|
158
|
+
_target.subVectors( _reflectorWorldPosition, _lookAtPosition );
|
|
159
|
+
_target.reflect( _normal ).negate();
|
|
160
|
+
_target.add( _reflectorWorldPosition );
|
|
161
|
+
|
|
162
|
+
//
|
|
163
|
+
|
|
164
|
+
virtualCamera.coordinateSystem = camera.coordinateSystem;
|
|
165
|
+
virtualCamera.position.copy( _view );
|
|
166
|
+
virtualCamera.up.set( 0, 1, 0 );
|
|
167
|
+
virtualCamera.up.applyMatrix4( _rotationMatrix );
|
|
168
|
+
virtualCamera.up.reflect( _normal );
|
|
169
|
+
virtualCamera.lookAt( _target );
|
|
170
|
+
|
|
171
|
+
virtualCamera.near = camera.near;
|
|
172
|
+
virtualCamera.far = camera.far;
|
|
173
|
+
|
|
174
|
+
virtualCamera.updateMatrixWorld();
|
|
175
|
+
virtualCamera.projectionMatrix.copy( camera.projectionMatrix );
|
|
176
|
+
|
|
177
|
+
// Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html
|
|
178
|
+
// Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf
|
|
179
|
+
_reflectorPlane.setFromNormalAndCoplanarPoint( _normal, _reflectorWorldPosition );
|
|
180
|
+
_reflectorPlane.applyMatrix4( virtualCamera.matrixWorldInverse );
|
|
181
|
+
|
|
182
|
+
clipPlane.set( _reflectorPlane.normal.x, _reflectorPlane.normal.y, _reflectorPlane.normal.z, _reflectorPlane.constant );
|
|
183
|
+
|
|
184
|
+
const projectionMatrix = virtualCamera.projectionMatrix;
|
|
185
|
+
|
|
186
|
+
_q.x = ( Math.sign( clipPlane.x ) + projectionMatrix.elements[ 8 ] ) / projectionMatrix.elements[ 0 ];
|
|
187
|
+
_q.y = ( Math.sign( clipPlane.y ) + projectionMatrix.elements[ 9 ] ) / projectionMatrix.elements[ 5 ];
|
|
188
|
+
_q.z = - 1.0;
|
|
189
|
+
_q.w = ( 1.0 + projectionMatrix.elements[ 10 ] ) / projectionMatrix.elements[ 14 ];
|
|
190
|
+
|
|
191
|
+
// Calculate the scaled plane vector
|
|
192
|
+
clipPlane.multiplyScalar( 1.0 / clipPlane.dot( _q ) );
|
|
193
|
+
|
|
194
|
+
const clipBias = 0;
|
|
195
|
+
|
|
196
|
+
// Replacing the third row of the projection matrix
|
|
197
|
+
projectionMatrix.elements[ 2 ] = clipPlane.x;
|
|
198
|
+
projectionMatrix.elements[ 6 ] = clipPlane.y;
|
|
199
|
+
projectionMatrix.elements[ 10 ] = clipPlane.z - clipBias;
|
|
200
|
+
projectionMatrix.elements[ 14 ] = clipPlane.w;
|
|
201
|
+
|
|
202
|
+
//
|
|
203
|
+
|
|
204
|
+
this.value = renderTarget.texture;
|
|
205
|
+
|
|
206
|
+
material.visible = false;
|
|
207
|
+
|
|
208
|
+
const currentRenderTarget = renderer.getRenderTarget();
|
|
209
|
+
|
|
210
|
+
renderer.setRenderTarget( renderTarget );
|
|
211
|
+
|
|
212
|
+
renderer.render( scene, virtualCamera );
|
|
213
|
+
|
|
214
|
+
renderer.setRenderTarget( currentRenderTarget );
|
|
215
|
+
|
|
216
|
+
material.visible = true;
|
|
217
|
+
|
|
218
|
+
_inReflector = false;
|
|
219
|
+
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export const reflector = ( parameters ) => nodeObject( new ReflectorNode( parameters ) );
|
|
225
|
+
|
|
226
|
+
export default ReflectorNode;
|
|
227
|
+
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import TempNode from '../core/TempNode.js';
|
|
2
|
+
import { addNodeClass } from '../core/Node.js';
|
|
3
|
+
import {
|
|
4
|
+
addNodeElement,
|
|
5
|
+
nodeProxy,
|
|
6
|
+
vec4,
|
|
7
|
+
mat2,
|
|
8
|
+
mat4,
|
|
9
|
+
} from '../shadernode/ShaderNode.js';
|
|
10
|
+
import { cos, sin } from '../math/MathNode.js';
|
|
11
|
+
|
|
12
|
+
class RotateNode extends TempNode {
|
|
13
|
+
|
|
14
|
+
constructor( positionNode, rotationNode ) {
|
|
15
|
+
|
|
16
|
+
super();
|
|
17
|
+
|
|
18
|
+
this.positionNode = positionNode;
|
|
19
|
+
this.rotationNode = rotationNode;
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getNodeType( builder ) {
|
|
24
|
+
|
|
25
|
+
return this.positionNode.getNodeType( builder );
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
setup( builder ) {
|
|
30
|
+
|
|
31
|
+
const { rotationNode, positionNode } = this;
|
|
32
|
+
|
|
33
|
+
const nodeType = this.getNodeType( builder );
|
|
34
|
+
|
|
35
|
+
if ( nodeType === 'vec2' ) {
|
|
36
|
+
|
|
37
|
+
const cosAngle = rotationNode.cos();
|
|
38
|
+
const sinAngle = rotationNode.sin();
|
|
39
|
+
|
|
40
|
+
const rotationMatrix = mat2(
|
|
41
|
+
cosAngle, sinAngle,
|
|
42
|
+
sinAngle.negate(), cosAngle
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return rotationMatrix.mul( positionNode );
|
|
46
|
+
|
|
47
|
+
} else {
|
|
48
|
+
|
|
49
|
+
const rotation = rotationNode;
|
|
50
|
+
const rotationXMatrix = mat4( vec4( 1.0, 0.0, 0.0, 0.0 ), vec4( 0.0, cos( rotation.x ), sin( rotation.x ).negate(), 0.0 ), vec4( 0.0, sin( rotation.x ), cos( rotation.x ), 0.0 ), vec4( 0.0, 0.0, 0.0, 1.0 ) );
|
|
51
|
+
const rotationYMatrix = mat4( vec4( cos( rotation.y ), 0.0, sin( rotation.y ), 0.0 ), vec4( 0.0, 1.0, 0.0, 0.0 ), vec4( sin( rotation.y ).negate(), 0.0, cos( rotation.y ), 0.0 ), vec4( 0.0, 0.0, 0.0, 1.0 ) );
|
|
52
|
+
const rotationZMatrix = mat4( vec4( cos( rotation.z ), sin( rotation.z ).negate(), 0.0, 0.0 ), vec4( sin( rotation.z ), cos( rotation.z ), 0.0, 0.0 ), vec4( 0.0, 0.0, 1.0, 0.0 ), vec4( 0.0, 0.0, 0.0, 1.0 ) );
|
|
53
|
+
|
|
54
|
+
return rotationXMatrix.mul( rotationYMatrix ).mul( rotationZMatrix ).mul( vec4( positionNode, 1.0 ) ).xyz;
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export default RotateNode;
|
|
63
|
+
|
|
64
|
+
export const rotate = nodeProxy( RotateNode );
|
|
65
|
+
|
|
66
|
+
addNodeElement( 'rotate', rotate );
|
|
67
|
+
|
|
68
|
+
addNodeClass( 'RotateNode', RotateNode );
|
|
@@ -18,17 +18,9 @@ class RotateUVNode extends TempNode {
|
|
|
18
18
|
|
|
19
19
|
const { uvNode, rotationNode, centerNode } = this;
|
|
20
20
|
|
|
21
|
-
const cosAngle = rotationNode.cos();
|
|
22
|
-
const sinAngle = rotationNode.sin();
|
|
23
|
-
|
|
24
21
|
const vector = uvNode.sub( centerNode );
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
vec2( cosAngle, sinAngle ).dot( vector ),
|
|
28
|
-
vec2( sinAngle.negate(), cosAngle ).dot( vector )
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
return rotatedVector.add( centerNode );
|
|
23
|
+
return vector.rotate( rotationNode ).add( centerNode );
|
|
32
24
|
|
|
33
25
|
}
|
|
34
26
|
|
|
@@ -30,15 +30,15 @@ class SplitNode extends Node {
|
|
|
30
30
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
getComponentType( builder ) {
|
|
34
34
|
|
|
35
|
-
return builder.
|
|
35
|
+
return builder.getComponentType( this.node.getNodeType( builder ) );
|
|
36
36
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
getNodeType( builder ) {
|
|
40
40
|
|
|
41
|
-
return builder.getTypeFromLength( this.components.length, this.
|
|
41
|
+
return builder.getTypeFromLength( this.components.length, this.getComponentType( builder ) );
|
|
42
42
|
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -59,7 +59,7 @@ class SplitNode extends Node {
|
|
|
59
59
|
|
|
60
60
|
// needed expand the input node
|
|
61
61
|
|
|
62
|
-
type = builder.getTypeFromLength( this.getVectorLength(), this.
|
|
62
|
+
type = builder.getTypeFromLength( this.getVectorLength(), this.getComponentType( builder ) );
|
|
63
63
|
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Mesh, MeshBasicMaterial, SphereGeometry, Vector3 } from 'three';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A ground-projected skybox. The height is how far the camera that took the photo was above the ground -
|
|
5
|
+
* a larger value will magnify the downward part of the image. By default the object is centered at the camera,
|
|
6
|
+
* so it is often helpful to set skybox.position.y = height to put the ground at the origin. Set the radius
|
|
7
|
+
* large enough to ensure your user's camera stays inside.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
class GroundedSkybox extends Mesh {
|
|
11
|
+
|
|
12
|
+
constructor( map, height, radius, resolution = 128 ) {
|
|
13
|
+
|
|
14
|
+
if ( height <= 0 || radius <= 0 || resolution <= 0 ) {
|
|
15
|
+
|
|
16
|
+
throw new Error( 'GroundedSkybox height, radius, and resolution must be positive.' );
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const geometry = new SphereGeometry( radius, 2 * resolution, resolution );
|
|
21
|
+
geometry.scale( 1, 1, -1 );
|
|
22
|
+
|
|
23
|
+
const pos = geometry.getAttribute( 'position' );
|
|
24
|
+
const tmp = new Vector3();
|
|
25
|
+
|
|
26
|
+
for ( let i = 0; i < pos.count; ++ i ) {
|
|
27
|
+
|
|
28
|
+
tmp.fromBufferAttribute( pos, i );
|
|
29
|
+
if ( tmp.y < 0 ) {
|
|
30
|
+
|
|
31
|
+
// Smooth out the transition from flat floor to sphere:
|
|
32
|
+
const y1 = - height * 3 / 2;
|
|
33
|
+
const f =
|
|
34
|
+
tmp.y < y1 ? - height / tmp.y : ( 1 - tmp.y * tmp.y / ( 3 * y1 * y1 ) );
|
|
35
|
+
tmp.multiplyScalar( f );
|
|
36
|
+
tmp.toArray( pos.array, 3 * i );
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
pos.needsUpdate = true;
|
|
43
|
+
|
|
44
|
+
super( geometry, new MeshBasicMaterial( { map, depthWrite: false } ) );
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { GroundedSkybox };
|
|
@@ -37,9 +37,9 @@ class QuadMesh {
|
|
|
37
37
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
async renderAsync( renderer ) {
|
|
41
41
|
|
|
42
|
-
renderer.
|
|
42
|
+
await renderer.renderAsync( this._mesh, _camera );
|
|
43
43
|
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -55,6 +55,12 @@ class QuadMesh {
|
|
|
55
55
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
get render() {
|
|
59
|
+
|
|
60
|
+
return this.renderAsync;
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
export default QuadMesh;
|
|
@@ -34,14 +34,14 @@ class Water extends Mesh {
|
|
|
34
34
|
const scope = this;
|
|
35
35
|
|
|
36
36
|
const color = ( options.color !== undefined ) ? new Color( options.color ) : new Color( 0xFFFFFF );
|
|
37
|
-
const textureWidth = options.textureWidth
|
|
38
|
-
const textureHeight = options.textureHeight
|
|
39
|
-
const clipBias = options.clipBias
|
|
40
|
-
const flowDirection = options.flowDirection
|
|
41
|
-
const flowSpeed = options.flowSpeed
|
|
42
|
-
const reflectivity = options.reflectivity
|
|
43
|
-
const scale = options.scale
|
|
44
|
-
const shader = options.shader
|
|
37
|
+
const textureWidth = options.textureWidth !== undefined ? options.textureWidth : 512;
|
|
38
|
+
const textureHeight = options.textureHeight !== undefined ? options.textureHeight : 512;
|
|
39
|
+
const clipBias = options.clipBias !== undefined ? options.clipBias : 0;
|
|
40
|
+
const flowDirection = options.flowDirection !== undefined ? options.flowDirection : new Vector2( 1, 0 );
|
|
41
|
+
const flowSpeed = options.flowSpeed !== undefined ? options.flowSpeed : 0.03;
|
|
42
|
+
const reflectivity = options.reflectivity !== undefined ? options.reflectivity : 0.02;
|
|
43
|
+
const scale = options.scale !== undefined ? options.scale : 1;
|
|
44
|
+
const shader = options.shader !== undefined ? options.shader : Water.WaterShader;
|
|
45
45
|
|
|
46
46
|
const textureLoader = new TextureLoader();
|
|
47
47
|
|
|
@@ -61,7 +61,7 @@ class GTAOPass extends Pass {
|
|
|
61
61
|
depthTest: false,
|
|
62
62
|
depthWrite: false,
|
|
63
63
|
} );
|
|
64
|
-
this.gtaoMaterial.
|
|
64
|
+
this.gtaoMaterial.defines.PERSPECTIVE_CAMERA = this.camera.isPerspectiveCamera ? 1 : 0;
|
|
65
65
|
this.gtaoMaterial.uniforms.tNoise.value = this.gtaoNoiseTexture;
|
|
66
66
|
this.gtaoMaterial.uniforms.resolution.value.set( this.width, this.height );
|
|
67
67
|
this.gtaoMaterial.uniforms.cameraNear.value = this.camera.near;
|
|
@@ -162,6 +162,12 @@ class GTAOPass extends Pass {
|
|
|
162
162
|
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
get gtaoMap() {
|
|
166
|
+
|
|
167
|
+
return this.pdRenderTarget.texture;
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
165
171
|
setGBuffer( depthTexture, normalTexture ) {
|
|
166
172
|
|
|
167
173
|
if ( depthTexture !== undefined ) {
|
|
@@ -359,6 +365,9 @@ class GTAOPass extends Pass {
|
|
|
359
365
|
|
|
360
366
|
switch ( this.output ) {
|
|
361
367
|
|
|
368
|
+
case GTAOPass.OUTPUT.Off:
|
|
369
|
+
break;
|
|
370
|
+
|
|
362
371
|
case GTAOPass.OUTPUT.Diffuse:
|
|
363
372
|
|
|
364
373
|
this.copyMaterial.uniforms.tDiffuse.value = readBuffer.texture;
|
|
@@ -561,6 +570,7 @@ class GTAOPass extends Pass {
|
|
|
561
570
|
}
|
|
562
571
|
|
|
563
572
|
GTAOPass.OUTPUT = {
|
|
573
|
+
'Off': - 1,
|
|
564
574
|
'Default': 0,
|
|
565
575
|
'Diffuse': 1,
|
|
566
576
|
'Depth': 2,
|
|
@@ -84,10 +84,16 @@ class Backend {
|
|
|
84
84
|
|
|
85
85
|
// canvas
|
|
86
86
|
|
|
87
|
+
getContext() { }
|
|
88
|
+
|
|
87
89
|
updateSize() { }
|
|
88
90
|
|
|
89
91
|
// utils
|
|
90
92
|
|
|
93
|
+
resolveTimestampAsync( renderContext, type ) { }
|
|
94
|
+
|
|
95
|
+
hasFeatureAsync( name ) { } // return Boolean
|
|
96
|
+
|
|
91
97
|
hasFeature( name ) { } // return Boolean
|
|
92
98
|
|
|
93
99
|
getInstanceCount( renderObject ) {
|
|
@@ -114,6 +120,8 @@ class Backend {
|
|
|
114
120
|
|
|
115
121
|
}
|
|
116
122
|
|
|
123
|
+
setScissorTest( boolean ) { }
|
|
124
|
+
|
|
117
125
|
getClearColor() {
|
|
118
126
|
|
|
119
127
|
const renderer = this.renderer;
|
|
@@ -170,6 +178,12 @@ class Backend {
|
|
|
170
178
|
|
|
171
179
|
}
|
|
172
180
|
|
|
181
|
+
has( object ) {
|
|
182
|
+
|
|
183
|
+
return this.data.has( object );
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
173
187
|
delete( object ) {
|
|
174
188
|
|
|
175
189
|
this.data.delete( object );
|
|
@@ -16,7 +16,8 @@ class Info {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
this.compute = {
|
|
19
|
-
calls: 0
|
|
19
|
+
calls: 0,
|
|
20
|
+
computeCalls: 0
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
this.memory = {
|
|
@@ -24,6 +25,11 @@ class Info {
|
|
|
24
25
|
textures: 0
|
|
25
26
|
};
|
|
26
27
|
|
|
28
|
+
this.timestamp = {
|
|
29
|
+
compute: 0,
|
|
30
|
+
render: 0
|
|
31
|
+
};
|
|
32
|
+
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
update( object, count, instanceCount ) {
|
|
@@ -54,6 +60,20 @@ class Info {
|
|
|
54
60
|
|
|
55
61
|
}
|
|
56
62
|
|
|
63
|
+
updateTimestamp( type, time ) {
|
|
64
|
+
|
|
65
|
+
this.timestamp[ type ] += time;
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
resetCompute() {
|
|
70
|
+
|
|
71
|
+
this.compute.computeCalls = 0;
|
|
72
|
+
|
|
73
|
+
this.timestamp.compute = 0;
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
|
|
57
77
|
reset() {
|
|
58
78
|
|
|
59
79
|
this.render.drawCalls = 0;
|
|
@@ -61,6 +81,8 @@ class Info {
|
|
|
61
81
|
this.render.points = 0;
|
|
62
82
|
this.render.lines = 0;
|
|
63
83
|
|
|
84
|
+
this.timestamp.render = 0;
|
|
85
|
+
|
|
64
86
|
}
|
|
65
87
|
|
|
66
88
|
dispose() {
|
|
@@ -72,6 +94,8 @@ class Info {
|
|
|
72
94
|
this.render.calls = 0;
|
|
73
95
|
this.compute.calls = 0;
|
|
74
96
|
|
|
97
|
+
this.timestamp.compute = 0;
|
|
98
|
+
this.timestamp.render = 0;
|
|
75
99
|
this.memory.geometries = 0;
|
|
76
100
|
this.memory.textures = 0;
|
|
77
101
|
|
|
@@ -42,18 +42,18 @@ class Pipelines extends DataMap {
|
|
|
42
42
|
|
|
43
43
|
// get shader
|
|
44
44
|
|
|
45
|
-
const
|
|
45
|
+
const nodeBuilderState = this.nodes.getForCompute( computeNode );
|
|
46
46
|
|
|
47
47
|
// programmable stage
|
|
48
48
|
|
|
49
|
-
let stageCompute = this.programs.compute.get(
|
|
49
|
+
let stageCompute = this.programs.compute.get( nodeBuilderState.computeShader );
|
|
50
50
|
|
|
51
51
|
if ( stageCompute === undefined ) {
|
|
52
52
|
|
|
53
53
|
if ( previousPipeline && previousPipeline.computeProgram.usedTimes === 0 ) this._releaseProgram( previousPipeline.computeProgram );
|
|
54
54
|
|
|
55
|
-
stageCompute = new ProgrammableStage(
|
|
56
|
-
this.programs.compute.set(
|
|
55
|
+
stageCompute = new ProgrammableStage( nodeBuilderState.computeShader, 'compute', nodeBuilderState.transforms, nodeBuilderState.nodeAttributes );
|
|
56
|
+
this.programs.compute.set( nodeBuilderState.computeShader, stageCompute );
|
|
57
57
|
|
|
58
58
|
backend.createProgram( stageCompute );
|
|
59
59
|
|
|
@@ -89,7 +89,7 @@ class Pipelines extends DataMap {
|
|
|
89
89
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
getForRender( renderObject ) {
|
|
92
|
+
getForRender( renderObject, promises = null ) {
|
|
93
93
|
|
|
94
94
|
const { backend } = this;
|
|
95
95
|
|
|
@@ -149,7 +149,7 @@ class Pipelines extends DataMap {
|
|
|
149
149
|
|
|
150
150
|
if ( previousPipeline && previousPipeline.usedTimes === 0 ) this._releasePipeline( previousPipeline );
|
|
151
151
|
|
|
152
|
-
pipeline = this._getRenderPipeline( renderObject, stageVertex, stageFragment, cacheKey );
|
|
152
|
+
pipeline = this._getRenderPipeline( renderObject, stageVertex, stageFragment, cacheKey, promises );
|
|
153
153
|
|
|
154
154
|
} else {
|
|
155
155
|
|
|
@@ -250,7 +250,7 @@ class Pipelines extends DataMap {
|
|
|
250
250
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
_getRenderPipeline( renderObject, stageVertex, stageFragment, cacheKey ) {
|
|
253
|
+
_getRenderPipeline( renderObject, stageVertex, stageFragment, cacheKey, promises ) {
|
|
254
254
|
|
|
255
255
|
// check for existing pipeline
|
|
256
256
|
|
|
@@ -266,7 +266,7 @@ class Pipelines extends DataMap {
|
|
|
266
266
|
|
|
267
267
|
renderObject.pipeline = pipeline;
|
|
268
268
|
|
|
269
|
-
this.backend.createRenderPipeline( renderObject );
|
|
269
|
+
this.backend.createRenderPipeline( renderObject, promises );
|
|
270
270
|
|
|
271
271
|
}
|
|
272
272
|
|
|
@@ -2,12 +2,14 @@ let _id = 0;
|
|
|
2
2
|
|
|
3
3
|
class ProgrammableStage {
|
|
4
4
|
|
|
5
|
-
constructor( code, type ) {
|
|
5
|
+
constructor( code, type, transforms = null, attributes = null ) {
|
|
6
6
|
|
|
7
7
|
this.id = _id ++;
|
|
8
8
|
|
|
9
9
|
this.code = code;
|
|
10
10
|
this.stage = type;
|
|
11
|
+
this.transforms = transforms;
|
|
12
|
+
this.attributes = attributes;
|
|
11
13
|
|
|
12
14
|
this.usedTimes = 0;
|
|
13
15
|
|
|
@@ -82,6 +82,8 @@ export default class RenderObject {
|
|
|
82
82
|
|
|
83
83
|
const attribute = nodeAttribute.node && nodeAttribute.node.attribute ? nodeAttribute.node.attribute : geometry.getAttribute( nodeAttribute.name );
|
|
84
84
|
|
|
85
|
+
if ( attribute === undefined ) continue;
|
|
86
|
+
|
|
85
87
|
attributes.push( attribute );
|
|
86
88
|
|
|
87
89
|
const bufferAttribute = attribute.isInterleavedBufferAttribute ? attribute.data : attribute;
|