super-three 0.169.0 → 0.170.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 +989 -1131
- package/build/three.module.js +990 -1128
- package/build/three.module.min.js +1 -1
- package/build/three.webgpu.js +8398 -9842
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +8398 -9842
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +3 -3
- package/examples/jsm/animation/MMDAnimationHelper.js +2 -0
- package/examples/jsm/animation/MMDPhysics.js +2 -0
- package/examples/jsm/controls/TransformControls.js +22 -6
- package/examples/jsm/csm/CSM.js +2 -2
- package/examples/jsm/csm/CSMFrustum.js +7 -4
- package/examples/jsm/csm/CSMHelper.js +2 -0
- package/examples/jsm/csm/CSMShadowNode.js +435 -0
- package/examples/jsm/curves/NURBSCurve.js +34 -3
- package/examples/jsm/exporters/GLTFExporter.js +138 -71
- package/examples/jsm/exporters/KTX2Exporter.js +35 -12
- package/examples/jsm/exporters/MMDExporter.js +6 -0
- package/examples/jsm/exporters/USDZExporter.js +21 -3
- package/examples/jsm/geometries/DecalGeometry.js +65 -20
- package/examples/jsm/geometries/InstancedPointsGeometry.js +2 -0
- package/examples/jsm/helpers/TextureHelperGPU.js +175 -0
- package/examples/jsm/interactive/HTMLMesh.js +1 -0
- package/examples/jsm/lighting/TiledLighting.js +18 -0
- package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
- package/examples/jsm/lines/LineMaterial.js +7 -2
- package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
- package/examples/jsm/lines/webgpu/LineSegments2.js +0 -15
- package/examples/jsm/lines/webgpu/Wireframe.js +56 -0
- package/examples/jsm/loaders/3DMLoader.js +1 -0
- package/examples/jsm/loaders/3MFLoader.js +91 -0
- package/examples/jsm/loaders/FBXLoader.js +12 -2
- package/examples/jsm/loaders/GLTFLoader.js +2 -0
- package/examples/jsm/loaders/KTX2Loader.js +140 -49
- package/examples/jsm/loaders/LDrawLoader.js +22 -136
- package/examples/jsm/loaders/LottieLoader.js +1 -0
- package/examples/jsm/loaders/MMDLoader.js +9 -2
- package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
- package/examples/jsm/materials/MeshGouraudMaterial.js +6 -2
- package/examples/jsm/math/ColorSpaces.js +76 -0
- package/examples/jsm/misc/ProgressiveLightMap.js +52 -40
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +293 -0
- package/examples/jsm/misc/VolumeSlice.js +1 -0
- package/examples/jsm/objects/WaterMesh.js +8 -8
- package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
- package/examples/jsm/postprocessing/SSRPass.js +6 -0
- package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
- package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
- package/examples/jsm/shaders/FXAAShader.js +225 -224
- package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
- package/{src/nodes → examples/jsm/tsl}/display/AfterImageNode.js +17 -20
- package/{src/nodes → examples/jsm/tsl}/display/AnaglyphPassNode.js +2 -6
- package/{src/nodes → examples/jsm/tsl}/display/AnamorphicNode.js +12 -18
- package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +1 -3
- package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +11 -40
- package/{src/nodes → examples/jsm/tsl}/display/DenoiseNode.js +18 -41
- package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +2 -8
- package/{src/nodes → examples/jsm/tsl}/display/DotScreenNode.js +2 -9
- package/examples/jsm/tsl/display/FXAANode.js +316 -0
- package/{src/nodes → examples/jsm/tsl}/display/FilmNode.js +2 -6
- package/{src/nodes → examples/jsm/tsl}/display/GTAONode.js +30 -70
- package/{src/nodes → examples/jsm/tsl}/display/GaussianBlurNode.js +74 -36
- package/examples/jsm/tsl/display/LensflareNode.js +161 -0
- package/{src/nodes → examples/jsm/tsl}/display/Lut3DNode.js +1 -4
- package/{src/nodes → examples/jsm/tsl}/display/MotionBlur.js +2 -3
- package/examples/jsm/tsl/display/OutlineNode.js +434 -0
- package/{src/nodes → examples/jsm/tsl}/display/ParallaxBarrierPassNode.js +1 -5
- package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +3 -15
- package/{src/nodes → examples/jsm/tsl}/display/RGBShiftNode.js +1 -6
- package/examples/jsm/tsl/display/SMAANode.js +620 -0
- package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +10 -25
- package/examples/jsm/tsl/display/SSRNode.js +343 -0
- package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +1 -2
- package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +3 -11
- package/{src/nodes → examples/jsm/tsl}/display/StereoCompositePassNode.js +9 -11
- package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +10 -11
- package/examples/jsm/tsl/display/TRAAPassNode.js +355 -0
- package/{src/nodes → examples/jsm/tsl}/display/TransitionNode.js +1 -6
- package/examples/jsm/tsl/display/hashBlur.js +24 -0
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +392 -0
- package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +2 -1
- package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
- package/examples/jsm/webxr/Text2D.js +6 -6
- package/package.json +2 -2
- package/src/Three.WebGPU.Nodes.js +4 -0
- package/src/Three.WebGPU.js +4 -0
- package/src/constants.js +1 -6
- package/src/core/BufferGeometry.js +44 -6
- package/src/geometries/CylinderGeometry.js +2 -2
- package/src/materials/LineBasicMaterial.js +6 -2
- package/src/materials/LineDashedMaterial.js +6 -2
- package/src/materials/Material.js +14 -1
- package/src/materials/MeshBasicMaterial.js +6 -2
- package/src/materials/MeshDepthMaterial.js +6 -2
- package/src/materials/MeshDistanceMaterial.js +6 -2
- package/src/materials/MeshLambertMaterial.js +6 -2
- package/src/materials/MeshMatcapMaterial.js +6 -2
- package/src/materials/MeshNormalMaterial.js +6 -2
- package/src/materials/MeshPhongMaterial.js +6 -2
- package/src/materials/MeshPhysicalMaterial.js +6 -2
- package/src/materials/MeshStandardMaterial.js +6 -2
- package/src/materials/MeshToonMaterial.js +6 -2
- package/src/materials/PointsMaterial.js +6 -2
- package/src/materials/RawShaderMaterial.js +6 -2
- package/src/materials/ShaderMaterial.js +6 -2
- package/src/materials/ShadowMaterial.js +6 -2
- package/src/materials/SpriteMaterial.js +6 -2
- package/src/materials/nodes/NodeMaterial.js +31 -9
- package/src/materials/nodes/SpriteNodeMaterial.js +11 -2
- package/src/materials/nodes/manager/NodeMaterialObserver.js +111 -2
- package/src/math/ColorManagement.js +118 -85
- package/src/math/Vector4.js +11 -0
- package/src/nodes/Nodes.js +1 -21
- package/src/nodes/TSL.js +6 -24
- package/src/nodes/accessors/Camera.js +0 -1
- package/src/nodes/accessors/SceneNode.js +35 -1
- package/src/nodes/accessors/StorageBufferNode.js +32 -10
- package/src/nodes/accessors/VelocityNode.js +13 -3
- package/src/nodes/code/FunctionCallNode.js +16 -5
- package/src/nodes/code/ScriptableNode.js +4 -4
- package/src/nodes/core/Node.js +1 -0
- package/src/nodes/core/NodeBuilder.js +29 -5
- package/src/nodes/core/VarNode.js +15 -3
- package/src/nodes/display/ColorAdjustment.js +53 -4
- package/src/nodes/display/ColorSpaceFunctions.js +5 -5
- package/src/nodes/display/ColorSpaceNode.js +27 -39
- package/src/nodes/display/PassNode.js +6 -4
- package/src/nodes/display/ToneMappingNode.js +1 -1
- package/src/nodes/display/ViewportDepthNode.js +33 -1
- package/src/nodes/functions/PhysicalLightingModel.js +21 -15
- package/src/nodes/functions/material/getAlphaHashThreshold.js +64 -0
- package/src/nodes/functions/material/getGeometryRoughness.js +8 -2
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +22 -0
- package/src/nodes/gpgpu/ComputeNode.js +9 -1
- package/src/nodes/lighting/AnalyticLightNode.js +12 -416
- package/src/nodes/lighting/LightsNode.js +24 -12
- package/src/nodes/lighting/PointLightNode.js +36 -26
- package/src/nodes/lighting/RectAreaLightNode.js +3 -0
- package/src/nodes/lighting/ShadowNode.js +484 -0
- package/src/nodes/utils/LoopNode.js +2 -2
- package/src/nodes/utils/Oscillators.js +6 -0
- package/src/nodes/utils/PostProcessingUtils.js +89 -0
- package/src/nodes/utils/ReflectorNode.js +101 -15
- package/src/nodes/utils/Timer.js +29 -0
- package/src/objects/BatchedMesh.js +458 -241
- package/src/renderers/WebGLRenderer.js +121 -126
- package/src/renderers/common/Attributes.js +4 -0
- package/src/renderers/common/Backend.js +2 -0
- package/src/renderers/common/Background.js +14 -4
- package/src/renderers/common/Bindings.js +3 -2
- package/src/renderers/common/Constants.js +2 -1
- package/src/renderers/common/Geometries.js +20 -0
- package/src/renderers/common/IndirectStorageBufferAttribute.js +15 -0
- package/src/renderers/common/Lighting.js +45 -0
- package/src/renderers/common/PostProcessingUtils.js +86 -0
- package/src/renderers/common/RenderList.js +39 -11
- package/src/renderers/common/RenderLists.js +4 -2
- package/src/renderers/common/RenderObject.js +18 -1
- package/src/renderers/common/Renderer.js +165 -26
- package/src/renderers/common/Textures.js +30 -14
- package/src/renderers/common/nodes/NodeLibrary.js +1 -14
- package/src/renderers/common/nodes/Nodes.js +2 -2
- package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
- package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLCapabilities.js +0 -7
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLProgram.js +24 -28
- package/src/renderers/webgl/WebGLPrograms.js +5 -2
- package/src/renderers/webgl/WebGLState.js +37 -1
- package/src/renderers/webgl/WebGLTextures.js +29 -12
- package/src/renderers/webgl-fallback/WebGLBackend.js +98 -31
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +2 -7
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +33 -8
- package/src/renderers/webgpu/WebGPUBackend.js +105 -25
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +1 -1
- package/src/renderers/webgpu/WebGPURenderer.js +1 -1
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +0 -8
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +0 -8
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +10 -20
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +12 -4
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +29 -9
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +24 -6
- package/src/renderers/webgpu/utils/WebGPUUtils.js +0 -1
- package/src/renderers/webxr/WebXRManager.js +4 -4
- package/examples/jsm/cameras/CinematicCamera.js +0 -208
- package/src/nodes/display/FXAANode.js +0 -332
- package/src/nodes/utils/OscNode.js +0 -85
- package/src/nodes/utils/TimerNode.js +0 -97
- package/src/renderers/webvr/WebVRManager.js +0 -495
- package/src/renderers/webvr/WebVRUtils.js +0 -66
- /package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import PassNode from '
|
|
3
|
-
import { Color } from '../../math/Color.js';
|
|
4
|
-
import { Vector2 } from '../../math/Vector2.js';
|
|
5
|
-
import { AdditiveBlending } from '../../constants.js';
|
|
6
|
-
import { uniform } from '../core/UniformNode.js';
|
|
7
|
-
import QuadMesh from '../../renderers/common/QuadMesh.js';
|
|
8
|
-
import { texture } from '../accessors/TextureNode.js';
|
|
9
|
-
import { mrt, getTextureIndex } from '../core/MRTNode.js';
|
|
10
|
-
import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
|
|
1
|
+
import { AdditiveBlending, Color, Vector2, PostProcessingUtils } from 'three';
|
|
2
|
+
import { nodeObject, uniform, mrt, PassNode, QuadMesh, texture, NodeMaterial, getTextureIndex } from 'three/tsl';
|
|
11
3
|
|
|
12
4
|
const _size = /*@__PURE__*/ new Vector2();
|
|
13
5
|
|
|
6
|
+
let _rendererState;
|
|
7
|
+
|
|
14
8
|
/**
|
|
15
9
|
*
|
|
16
10
|
* Supersample Anti-Aliasing Render Pass
|
|
@@ -40,8 +34,6 @@ class SSAAPassNode extends PassNode {
|
|
|
40
34
|
this.clearColor = new Color( 0x000000 );
|
|
41
35
|
this.clearAlpha = 0;
|
|
42
36
|
|
|
43
|
-
this._currentClearColor = new Color();
|
|
44
|
-
|
|
45
37
|
this.sampleWeight = uniform( 1 );
|
|
46
38
|
|
|
47
39
|
this.sampleRenderTarget = null;
|
|
@@ -55,6 +47,10 @@ class SSAAPassNode extends PassNode {
|
|
|
55
47
|
const { renderer } = frame;
|
|
56
48
|
const { scene, camera } = this;
|
|
57
49
|
|
|
50
|
+
_rendererState = PostProcessingUtils.resetRendererAndSceneState( renderer, scene, _rendererState );
|
|
51
|
+
|
|
52
|
+
//
|
|
53
|
+
|
|
58
54
|
this._pixelRatio = renderer.getPixelRatio();
|
|
59
55
|
|
|
60
56
|
const size = renderer.getSize( _size );
|
|
@@ -62,14 +58,6 @@ class SSAAPassNode extends PassNode {
|
|
|
62
58
|
this.setSize( size.width, size.height );
|
|
63
59
|
this.sampleRenderTarget.setSize( this.renderTarget.width, this.renderTarget.height );
|
|
64
60
|
|
|
65
|
-
// save current renderer settings
|
|
66
|
-
|
|
67
|
-
renderer.getClearColor( this._currentClearColor );
|
|
68
|
-
const currentClearAlpha = renderer.getClearAlpha();
|
|
69
|
-
const currentRenderTarget = renderer.getRenderTarget();
|
|
70
|
-
const currentMRT = renderer.getMRT();
|
|
71
|
-
const currentAutoClear = renderer.autoClear;
|
|
72
|
-
|
|
73
61
|
//
|
|
74
62
|
|
|
75
63
|
this._cameraNear.value = camera.near;
|
|
@@ -173,11 +161,9 @@ class SSAAPassNode extends PassNode {
|
|
|
173
161
|
|
|
174
162
|
}
|
|
175
163
|
|
|
176
|
-
|
|
177
|
-
renderer.setMRT( currentMRT );
|
|
164
|
+
//
|
|
178
165
|
|
|
179
|
-
|
|
180
|
-
renderer.setClearColor( this._currentClearColor, currentClearAlpha );
|
|
166
|
+
PostProcessingUtils.restoreRendererAndSceneState( renderer, scene, _rendererState );
|
|
181
167
|
|
|
182
168
|
}
|
|
183
169
|
|
|
@@ -224,7 +210,6 @@ class SSAAPassNode extends PassNode {
|
|
|
224
210
|
this._quadMesh.material.depthWrite = false;
|
|
225
211
|
this._quadMesh.material.premultipliedAlpha = true;
|
|
226
212
|
this._quadMesh.material.blending = AdditiveBlending;
|
|
227
|
-
this._quadMesh.material.normals = false;
|
|
228
213
|
this._quadMesh.material.name = 'SSAA';
|
|
229
214
|
|
|
230
215
|
return super.setup( builder );
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { NearestFilter, RenderTarget, Vector2, PostProcessingUtils } from 'three';
|
|
2
|
+
import { getScreenPosition, getViewPosition, sqrt, mul, div, cross, float, Continue, Break, Loop, int, max, abs, sub, If, dot, reflect, normalize, screenCoordinate, QuadMesh, TempNode, nodeObject, Fn, NodeUpdateType, passTexture, NodeMaterial, uv, uniform, perspectiveDepthToViewZ, orthographicDepthToViewZ, vec2, vec3, vec4 } from 'three/tsl';
|
|
3
|
+
|
|
4
|
+
const _quadMesh = /*@__PURE__*/ new QuadMesh();
|
|
5
|
+
const _size = /*@__PURE__*/ new Vector2();
|
|
6
|
+
let _rendererState;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* References:
|
|
10
|
+
* https://lettier.github.io/3d-game-shaders-for-beginners/screen-space-reflection.html
|
|
11
|
+
*/
|
|
12
|
+
class SSRNode extends TempNode {
|
|
13
|
+
|
|
14
|
+
static get type() {
|
|
15
|
+
|
|
16
|
+
return 'SSRNode';
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
constructor( colorNode, depthNode, normalNode, metalnessNode, camera ) {
|
|
21
|
+
|
|
22
|
+
super();
|
|
23
|
+
|
|
24
|
+
this.colorNode = colorNode;
|
|
25
|
+
this.depthNode = depthNode;
|
|
26
|
+
this.normalNode = normalNode;
|
|
27
|
+
this.metalnessNode = metalnessNode;
|
|
28
|
+
this.camera = camera;
|
|
29
|
+
|
|
30
|
+
this.resolutionScale = 0.5;
|
|
31
|
+
|
|
32
|
+
this.updateBeforeType = NodeUpdateType.FRAME;
|
|
33
|
+
|
|
34
|
+
// render targets
|
|
35
|
+
|
|
36
|
+
this._ssrRenderTarget = new RenderTarget( 1, 1, { depthBuffer: false, minFilter: NearestFilter, magFilter: NearestFilter } );
|
|
37
|
+
this._ssrRenderTarget.texture.name = 'SSRNode.SSR';
|
|
38
|
+
|
|
39
|
+
// uniforms
|
|
40
|
+
|
|
41
|
+
this.maxDistance = uniform( 1 ); // controls how far a fragment can reflect
|
|
42
|
+
this.thickness = uniform( 0.1 ); // controls the cutoff between what counts as a possible reflection hit and what does not
|
|
43
|
+
this.opacity = uniform( 1 ); // controls the transparency of the reflected colors
|
|
44
|
+
|
|
45
|
+
this._cameraNear = uniform( camera.near );
|
|
46
|
+
this._cameraFar = uniform( camera.far );
|
|
47
|
+
this._cameraProjectionMatrix = uniform( camera.projectionMatrix );
|
|
48
|
+
this._cameraProjectionMatrixInverse = uniform( camera.projectionMatrixInverse );
|
|
49
|
+
this._isPerspectiveCamera = uniform( camera.isPerspectiveCamera ? 1 : 0 );
|
|
50
|
+
this._resolution = uniform( new Vector2() );
|
|
51
|
+
this._maxStep = uniform( 0 );
|
|
52
|
+
|
|
53
|
+
// materials
|
|
54
|
+
|
|
55
|
+
this._material = new NodeMaterial();
|
|
56
|
+
this._material.name = 'SSRNode.SSR';
|
|
57
|
+
|
|
58
|
+
//
|
|
59
|
+
|
|
60
|
+
this._textureNode = passTexture( this, this._ssrRenderTarget.texture );
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getTextureNode() {
|
|
65
|
+
|
|
66
|
+
return this._textureNode;
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
setSize( width, height ) {
|
|
71
|
+
|
|
72
|
+
width = Math.round( this.resolutionScale * width );
|
|
73
|
+
height = Math.round( this.resolutionScale * height );
|
|
74
|
+
|
|
75
|
+
this._resolution.value.set( width, height );
|
|
76
|
+
this._maxStep.value = Math.round( Math.sqrt( width * width + height * height ) );
|
|
77
|
+
|
|
78
|
+
this._ssrRenderTarget.setSize( width, height );
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
updateBefore( frame ) {
|
|
83
|
+
|
|
84
|
+
const { renderer } = frame;
|
|
85
|
+
|
|
86
|
+
_rendererState = PostProcessingUtils.resetRendererState( renderer, _rendererState );
|
|
87
|
+
|
|
88
|
+
const size = renderer.getDrawingBufferSize( _size );
|
|
89
|
+
|
|
90
|
+
_quadMesh.material = this._material;
|
|
91
|
+
|
|
92
|
+
this.setSize( size.width, size.height );
|
|
93
|
+
|
|
94
|
+
// clear
|
|
95
|
+
|
|
96
|
+
renderer.setMRT( null );
|
|
97
|
+
renderer.setClearColor( 0x000000, 0 );
|
|
98
|
+
|
|
99
|
+
// ssr
|
|
100
|
+
|
|
101
|
+
renderer.setRenderTarget( this._ssrRenderTarget );
|
|
102
|
+
_quadMesh.render( renderer );
|
|
103
|
+
|
|
104
|
+
// restore
|
|
105
|
+
|
|
106
|
+
PostProcessingUtils.restoreRendererState( renderer, _rendererState );
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
setup( builder ) {
|
|
111
|
+
|
|
112
|
+
const uvNode = uv();
|
|
113
|
+
|
|
114
|
+
const pointToLineDistance = Fn( ( [ point, linePointA, linePointB ] )=> {
|
|
115
|
+
|
|
116
|
+
// https://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html
|
|
117
|
+
|
|
118
|
+
return cross( point.sub( linePointA ), point.sub( linePointB ) ).length().div( linePointB.sub( linePointA ).length() );
|
|
119
|
+
|
|
120
|
+
} );
|
|
121
|
+
|
|
122
|
+
const pointPlaneDistance = Fn( ( [ point, planePoint, planeNormal ] )=> {
|
|
123
|
+
|
|
124
|
+
// https://mathworld.wolfram.com/Point-PlaneDistance.html
|
|
125
|
+
// https://en.wikipedia.org/wiki/Plane_(geometry)
|
|
126
|
+
// http://paulbourke.net/geometry/pointlineplane/
|
|
127
|
+
|
|
128
|
+
const d = mul( planeNormal.x, planePoint.x ).add( mul( planeNormal.y, planePoint.y ) ).add( mul( planeNormal.z, planePoint.z ) ).negate().toVar();
|
|
129
|
+
|
|
130
|
+
const denominator = sqrt( mul( planeNormal.x, planeNormal.x, ).add( mul( planeNormal.y, planeNormal.y ) ).add( mul( planeNormal.z, planeNormal.z ) ) ).toVar();
|
|
131
|
+
const distance = div( mul( planeNormal.x, point.x ).add( mul( planeNormal.y, point.y ) ).add( mul( planeNormal.z, point.z ) ).add( d ), denominator );
|
|
132
|
+
return distance;
|
|
133
|
+
|
|
134
|
+
} );
|
|
135
|
+
|
|
136
|
+
const getViewZ = Fn( ( [ depth ] ) => {
|
|
137
|
+
|
|
138
|
+
let viewZNode;
|
|
139
|
+
|
|
140
|
+
if ( this.camera.isPerspectiveCamera ) {
|
|
141
|
+
|
|
142
|
+
viewZNode = perspectiveDepthToViewZ( depth, this._cameraNear, this._cameraFar );
|
|
143
|
+
|
|
144
|
+
} else {
|
|
145
|
+
|
|
146
|
+
viewZNode = orthographicDepthToViewZ( depth, this._cameraNear, this._cameraFar );
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return viewZNode;
|
|
151
|
+
|
|
152
|
+
} );
|
|
153
|
+
|
|
154
|
+
const ssr = Fn( () => {
|
|
155
|
+
|
|
156
|
+
const metalness = this.metalnessNode.uv( uvNode ).r;
|
|
157
|
+
|
|
158
|
+
// fragments with no metalness do not reflect their environment
|
|
159
|
+
metalness.equal( 0.0 ).discard();
|
|
160
|
+
|
|
161
|
+
// compute some standard FX entities
|
|
162
|
+
const depth = this.depthNode.uv( uvNode ).r.toVar();
|
|
163
|
+
const viewPosition = getViewPosition( uvNode, depth, this._cameraProjectionMatrixInverse ).toVar();
|
|
164
|
+
const viewNormal = this.normalNode.rgb.normalize().toVar();
|
|
165
|
+
|
|
166
|
+
// compute the direction from the position in view space to the camera
|
|
167
|
+
const viewIncidentDir = ( ( this.camera.isPerspectiveCamera ) ? normalize( viewPosition ) : vec3( 0, 0, - 1 ) ).toVar();
|
|
168
|
+
|
|
169
|
+
// compute the direction in which the light is reflected on the surface
|
|
170
|
+
const viewReflectDir = reflect( viewIncidentDir, viewNormal ).toVar();
|
|
171
|
+
|
|
172
|
+
// adapt maximum distance to the local geometry (see https://www.mathsisfun.com/algebra/vectors-dot-product.html)
|
|
173
|
+
const maxReflectRayLen = this.maxDistance.div( dot( viewIncidentDir.negate(), viewNormal ) ).toVar();
|
|
174
|
+
|
|
175
|
+
// compute the maximum point of the reflection ray in view space
|
|
176
|
+
const d1viewPosition = viewPosition.add( viewReflectDir.mul( maxReflectRayLen ) ).toVar();
|
|
177
|
+
|
|
178
|
+
// check if d1viewPosition lies behind the camera near plane
|
|
179
|
+
If( this._isPerspectiveCamera.equal( float( 1 ) ).and( d1viewPosition.z.greaterThan( this._cameraNear.negate() ) ), () => {
|
|
180
|
+
|
|
181
|
+
// if so, ensure d1viewPosition is clamped on the near plane.
|
|
182
|
+
// this prevents artifacts during the ray marching process
|
|
183
|
+
const t = sub( this._cameraNear.negate(), viewPosition.z ).div( viewReflectDir.z );
|
|
184
|
+
d1viewPosition.assign( viewPosition.add( viewReflectDir.mul( t ) ) );
|
|
185
|
+
|
|
186
|
+
} );
|
|
187
|
+
|
|
188
|
+
// d0 and d1 are the start and maximum points of the reflection ray in screen space
|
|
189
|
+
const d0 = screenCoordinate.xy.toVar();
|
|
190
|
+
const d1 = getScreenPosition( d1viewPosition, this._cameraProjectionMatrix ).mul( this._resolution ).toVar();
|
|
191
|
+
|
|
192
|
+
// below variables are used to control the raymarching process
|
|
193
|
+
|
|
194
|
+
// total length of the ray
|
|
195
|
+
const totalLen = d1.sub( d0 ).length().toVar();
|
|
196
|
+
|
|
197
|
+
// offset in x and y direction
|
|
198
|
+
const xLen = d1.x.sub( d0.x ).toVar();
|
|
199
|
+
const yLen = d1.y.sub( d0.y ).toVar();
|
|
200
|
+
|
|
201
|
+
// determine the larger delta
|
|
202
|
+
// The larger difference will help to determine how much to travel in the X and Y direction each iteration and
|
|
203
|
+
// how many iterations are needed to travel the entire ray
|
|
204
|
+
const totalStep = max( abs( xLen ), abs( yLen ) ).toVar();
|
|
205
|
+
|
|
206
|
+
// step sizes in the x and y directions
|
|
207
|
+
const xSpan = xLen.div( totalStep ).toVar();
|
|
208
|
+
const ySpan = yLen.div( totalStep ).toVar();
|
|
209
|
+
|
|
210
|
+
const output = vec4( 0 ).toVar();
|
|
211
|
+
|
|
212
|
+
// the actual ray marching loop
|
|
213
|
+
// starting from d0, the code gradually travels along the ray and looks for an intersection with the geometry.
|
|
214
|
+
// it does not exceed d1 (the maximum ray extend)
|
|
215
|
+
Loop( { start: int( 0 ), end: int( this._maxStep ), type: 'int', condition: '<' }, ( { i } ) => {
|
|
216
|
+
|
|
217
|
+
// stop if the maximum number of steps is reached for this specific ray
|
|
218
|
+
If( float( i ).greaterThanEqual( totalStep ), () => {
|
|
219
|
+
|
|
220
|
+
Break();
|
|
221
|
+
|
|
222
|
+
} );
|
|
223
|
+
|
|
224
|
+
// advance on the ray by computing a new position in screen space
|
|
225
|
+
const xy = vec2( d0.x.add( xSpan.mul( float( i ) ) ), d0.y.add( ySpan.mul( float( i ) ) ) ).toVar();
|
|
226
|
+
|
|
227
|
+
// stop processing if the new position lies outside of the screen
|
|
228
|
+
If( xy.x.lessThan( 0 ).or( xy.x.greaterThan( this._resolution.x ) ).or( xy.y.lessThan( 0 ) ).or( xy.y.greaterThan( this._resolution.y ) ), () => {
|
|
229
|
+
|
|
230
|
+
Break();
|
|
231
|
+
|
|
232
|
+
} );
|
|
233
|
+
|
|
234
|
+
// compute new uv, depth, viewZ and viewPosition for the new location on the ray
|
|
235
|
+
const uvNode = xy.div( this._resolution );
|
|
236
|
+
const d = this.depthNode.uv( uvNode ).r.toVar();
|
|
237
|
+
const vZ = getViewZ( d ).toVar();
|
|
238
|
+
const vP = getViewPosition( uvNode, d, this._cameraProjectionMatrixInverse ).toVar();
|
|
239
|
+
|
|
240
|
+
const viewReflectRayZ = float( 0 ).toVar();
|
|
241
|
+
|
|
242
|
+
// normalized distance between the current position xy and the starting point d0
|
|
243
|
+
const s = xy.sub( d0 ).length().div( totalLen );
|
|
244
|
+
|
|
245
|
+
// depending on the camera type, we now compute the z-coordinate of the reflected ray at the current step in view space
|
|
246
|
+
If( this._isPerspectiveCamera.equal( float( 1 ) ), () => {
|
|
247
|
+
|
|
248
|
+
const recipVPZ = float( 1 ).div( viewPosition.z ).toVar();
|
|
249
|
+
viewReflectRayZ.assign( float( 1 ).div( recipVPZ.add( s.mul( float( 1 ).div( d1viewPosition.z ).sub( recipVPZ ) ) ) ) );
|
|
250
|
+
|
|
251
|
+
} ).Else( () => {
|
|
252
|
+
|
|
253
|
+
viewReflectRayZ.assign( viewPosition.z.add( s.mul( d1viewPosition.z.sub( viewPosition.z ) ) ) );
|
|
254
|
+
|
|
255
|
+
} );
|
|
256
|
+
|
|
257
|
+
// if viewReflectRayZ is less or equal than the real z-coordinate at this place, it potentially intersects the geometry
|
|
258
|
+
If( viewReflectRayZ.lessThanEqual( vZ ), () => {
|
|
259
|
+
|
|
260
|
+
// compute the distance of the new location to the ray in view space
|
|
261
|
+
// to clarify vP is the fragment's view position which is not an exact point on the ray
|
|
262
|
+
const away = pointToLineDistance( vP, viewPosition, d1viewPosition ).toVar();
|
|
263
|
+
|
|
264
|
+
// compute the minimum thickness between the current fragment and its neighbor in the x-direction.
|
|
265
|
+
const xyNeighbor = vec2( xy.x.add( 1 ), xy.y ).toVar(); // move one pixel
|
|
266
|
+
const uvNeighbor = xyNeighbor.div( this._resolution );
|
|
267
|
+
const vPNeighbor = getViewPosition( uvNeighbor, d, this._cameraProjectionMatrixInverse ).toVar();
|
|
268
|
+
const minThickness = vPNeighbor.x.sub( vP.x ).toVar();
|
|
269
|
+
minThickness.mulAssign( 3 ); // expand a bit to avoid errors
|
|
270
|
+
|
|
271
|
+
const tk = max( minThickness, this.thickness ).toVar();
|
|
272
|
+
|
|
273
|
+
If( away.lessThanEqual( tk ), () => { // hit
|
|
274
|
+
|
|
275
|
+
const vN = this.normalNode.uv( uvNode ).rgb.normalize().toVar();
|
|
276
|
+
|
|
277
|
+
If( dot( viewReflectDir, vN ).greaterThanEqual( 0 ), () => {
|
|
278
|
+
|
|
279
|
+
// the reflected ray is pointing towards the same side as the fragment's normal (current ray position),
|
|
280
|
+
// which means it wouldn't reflect off the surface. The loop continues to the next step for the next ray sample.
|
|
281
|
+
Continue();
|
|
282
|
+
|
|
283
|
+
} );
|
|
284
|
+
|
|
285
|
+
// this distance represents the depth of the intersection point between the reflected ray and the scene.
|
|
286
|
+
const distance = pointPlaneDistance( vP, viewPosition, viewNormal ).toVar();
|
|
287
|
+
|
|
288
|
+
If( distance.greaterThan( this.maxDistance ), () => {
|
|
289
|
+
|
|
290
|
+
// Distance exceeding limit: The reflection is potentially too far away and
|
|
291
|
+
// might not contribute significantly to the final color
|
|
292
|
+
Break();
|
|
293
|
+
|
|
294
|
+
} );
|
|
295
|
+
|
|
296
|
+
const op = this.opacity.mul( metalness ).toVar();
|
|
297
|
+
|
|
298
|
+
// distance attenuation (the reflection should fade out the farther it is away from the surface)
|
|
299
|
+
const ratio = float( 1 ).sub( distance.div( this.maxDistance ) ).toVar();
|
|
300
|
+
const attenuation = ratio.mul( ratio );
|
|
301
|
+
op.mulAssign( attenuation );
|
|
302
|
+
|
|
303
|
+
// fresnel (reflect more light on surfaces that are viewed at grazing angles)
|
|
304
|
+
const fresnelCoe = div( dot( viewIncidentDir, viewReflectDir ).add( 1 ), 2 );
|
|
305
|
+
op.mulAssign( fresnelCoe );
|
|
306
|
+
|
|
307
|
+
// output
|
|
308
|
+
const reflectColor = this.colorNode.uv( uvNode );
|
|
309
|
+
output.assign( vec4( reflectColor.rgb, op ) );
|
|
310
|
+
Break();
|
|
311
|
+
|
|
312
|
+
} );
|
|
313
|
+
|
|
314
|
+
} );
|
|
315
|
+
|
|
316
|
+
} );
|
|
317
|
+
|
|
318
|
+
return output;
|
|
319
|
+
|
|
320
|
+
} );
|
|
321
|
+
|
|
322
|
+
this._material.fragmentNode = ssr().context( builder.getSharedContext() );
|
|
323
|
+
this._material.needsUpdate = true;
|
|
324
|
+
|
|
325
|
+
//
|
|
326
|
+
|
|
327
|
+
return this._textureNode;
|
|
328
|
+
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
dispose() {
|
|
332
|
+
|
|
333
|
+
this._ssrRenderTarget.dispose();
|
|
334
|
+
|
|
335
|
+
this._material.dispose();
|
|
336
|
+
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export default SSRNode;
|
|
342
|
+
|
|
343
|
+
export const ssr = ( colorNode, depthNode, normalNode, metalnessNode, camera ) => nodeObject( new SSRNode( nodeObject( colorNode ), nodeObject( depthNode ), nodeObject( normalNode ), nodeObject( metalnessNode ), camera ) );
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { uv } from '
|
|
3
|
-
import { luminance } from './ColorAdjustment.js';
|
|
4
|
-
import { Fn, nodeObject, vec2, vec3, vec4, mat3 } from '../tsl/TSLBase.js';
|
|
5
|
-
import { NodeUpdateType } from '../core/constants.js';
|
|
6
|
-
import { uniform } from '../core/UniformNode.js';
|
|
7
|
-
import { add } from '../math/OperatorNode.js';
|
|
8
|
-
import { convertToTexture } from '../utils/RTTNode.js';
|
|
9
|
-
|
|
10
|
-
import { Vector2 } from '../../math/Vector2.js';
|
|
1
|
+
import { Vector2 } from 'three';
|
|
2
|
+
import { TempNode, nodeObject, Fn, NodeUpdateType, uv, uniform, convertToTexture, vec2, vec3, vec4, mat3, luminance, add } from 'three/tsl';
|
|
11
3
|
|
|
12
4
|
class SobelOperatorNode extends TempNode {
|
|
13
5
|
|
|
@@ -23,7 +15,7 @@ class SobelOperatorNode extends TempNode {
|
|
|
23
15
|
|
|
24
16
|
this.textureNode = textureNode;
|
|
25
17
|
|
|
26
|
-
this.updateBeforeType = NodeUpdateType.
|
|
18
|
+
this.updateBeforeType = NodeUpdateType.FRAME;
|
|
27
19
|
|
|
28
20
|
this._invSize = uniform( new Vector2() );
|
|
29
21
|
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import PassNode from '
|
|
3
|
-
import { StereoCamera } from '../../cameras/StereoCamera.js';
|
|
4
|
-
import { HalfFloatType, LinearFilter, NearestFilter } from '../../constants.js';
|
|
5
|
-
import { RenderTarget } from '../../core/RenderTarget.js';
|
|
6
|
-
import { texture } from '../accessors/TextureNode.js';
|
|
7
|
-
import { Vector2 } from '../../math/Vector2.js';
|
|
8
|
-
import QuadMesh from '../../renderers/common/QuadMesh.js';
|
|
1
|
+
import { RenderTarget, StereoCamera, HalfFloatType, LinearFilter, NearestFilter, Vector2, PostProcessingUtils } from 'three';
|
|
2
|
+
import { PassNode, QuadMesh, texture } from 'three/tsl';
|
|
9
3
|
|
|
10
4
|
const _size = /*@__PURE__*/ new Vector2();
|
|
11
5
|
const _quadMesh = /*@__PURE__*/ new QuadMesh();
|
|
12
6
|
|
|
7
|
+
let _rendererState;
|
|
8
|
+
|
|
13
9
|
class StereoCompositePassNode extends PassNode {
|
|
14
10
|
|
|
15
11
|
static get type() {
|
|
@@ -59,6 +55,10 @@ class StereoCompositePassNode extends PassNode {
|
|
|
59
55
|
const { renderer } = frame;
|
|
60
56
|
const { scene, stereo, renderTarget } = this;
|
|
61
57
|
|
|
58
|
+
_rendererState = PostProcessingUtils.resetRendererAndSceneState( renderer, scene, _rendererState );
|
|
59
|
+
|
|
60
|
+
//
|
|
61
|
+
|
|
62
62
|
this._pixelRatio = renderer.getPixelRatio();
|
|
63
63
|
|
|
64
64
|
this.updateStereoCamera( renderer.coordinateSystem );
|
|
@@ -66,8 +66,6 @@ class StereoCompositePassNode extends PassNode {
|
|
|
66
66
|
const size = renderer.getSize( _size );
|
|
67
67
|
this.setSize( size.width, size.height );
|
|
68
68
|
|
|
69
|
-
const currentRenderTarget = renderer.getRenderTarget();
|
|
70
|
-
|
|
71
69
|
// left
|
|
72
70
|
|
|
73
71
|
renderer.setRenderTarget( this._renderTargetL );
|
|
@@ -86,7 +84,7 @@ class StereoCompositePassNode extends PassNode {
|
|
|
86
84
|
|
|
87
85
|
// restore
|
|
88
86
|
|
|
89
|
-
|
|
87
|
+
PostProcessingUtils.restoreRendererState( renderer, scene, _rendererState );
|
|
90
88
|
|
|
91
89
|
}
|
|
92
90
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import PassNode from '
|
|
3
|
-
import { Vector2 } from '../../math/Vector2.js';
|
|
4
|
-
import { StereoCamera } from '../../cameras/StereoCamera.js';
|
|
1
|
+
import { StereoCamera, Vector2, PostProcessingUtils } from 'three';
|
|
2
|
+
import { PassNode, nodeObject } from 'three/tsl';
|
|
5
3
|
|
|
6
4
|
const _size = /*@__PURE__*/ new Vector2();
|
|
7
5
|
|
|
6
|
+
let _rendererState;
|
|
7
|
+
|
|
8
8
|
class StereoPassNode extends PassNode {
|
|
9
9
|
|
|
10
10
|
static get type() {
|
|
@@ -29,6 +29,10 @@ class StereoPassNode extends PassNode {
|
|
|
29
29
|
const { renderer } = frame;
|
|
30
30
|
const { scene, camera, stereo, renderTarget } = this;
|
|
31
31
|
|
|
32
|
+
_rendererState = PostProcessingUtils.resetRendererState( renderer, _rendererState );
|
|
33
|
+
|
|
34
|
+
//
|
|
35
|
+
|
|
32
36
|
this._pixelRatio = renderer.getPixelRatio();
|
|
33
37
|
|
|
34
38
|
stereo.cameraL.coordinateSystem = renderer.coordinateSystem;
|
|
@@ -38,12 +42,8 @@ class StereoPassNode extends PassNode {
|
|
|
38
42
|
const size = renderer.getSize( _size );
|
|
39
43
|
this.setSize( size.width, size.height );
|
|
40
44
|
|
|
41
|
-
const currentAutoClear = renderer.autoClear;
|
|
42
45
|
renderer.autoClear = false;
|
|
43
46
|
|
|
44
|
-
const currentRenderTarget = renderer.getRenderTarget();
|
|
45
|
-
const currentMRT = renderer.getMRT();
|
|
46
|
-
|
|
47
47
|
this._cameraNear.value = camera.near;
|
|
48
48
|
this._cameraFar.value = camera.far;
|
|
49
49
|
|
|
@@ -69,10 +69,9 @@ class StereoPassNode extends PassNode {
|
|
|
69
69
|
|
|
70
70
|
renderTarget.scissorTest = false;
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
renderer.setMRT( currentMRT );
|
|
72
|
+
// restore
|
|
74
73
|
|
|
75
|
-
|
|
74
|
+
PostProcessingUtils.restoreRendererState( renderer, _rendererState );
|
|
76
75
|
|
|
77
76
|
}
|
|
78
77
|
|