super-three 0.169.1 → 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 +974 -562
- package/build/three.module.js +975 -559
- 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 +120 -117
- 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/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { Color, Vector2, PostProcessingUtils, NearestFilter, Matrix4 } from 'three';
|
|
2
|
+
import { add, float, If, Loop, int, Fn, min, max, clamp, nodeObject, PassNode, QuadMesh, texture, NodeMaterial, uniform, uv, vec2, vec4, luminance } from 'three/tsl';
|
|
3
|
+
|
|
4
|
+
const _quadMesh = /*@__PURE__*/ new QuadMesh();
|
|
5
|
+
const _size = /*@__PURE__*/ new Vector2();
|
|
6
|
+
|
|
7
|
+
let _rendererState;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Temporal Reprojection Anti-Aliasing (TRAA).
|
|
11
|
+
*
|
|
12
|
+
* References:
|
|
13
|
+
* https://alextardif.com/TAA.html
|
|
14
|
+
* https://www.elopezr.com/temporal-aa-and-the-quest-for-the-holy-trail/
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
class TRAAPassNode extends PassNode {
|
|
18
|
+
|
|
19
|
+
static get type() {
|
|
20
|
+
|
|
21
|
+
return 'TRAAPassNode';
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
constructor( scene, camera ) {
|
|
26
|
+
|
|
27
|
+
super( PassNode.COLOR, scene, camera );
|
|
28
|
+
|
|
29
|
+
this.isTRAAPassNode = true;
|
|
30
|
+
|
|
31
|
+
this.clearColor = new Color( 0x000000 );
|
|
32
|
+
this.clearAlpha = 0;
|
|
33
|
+
|
|
34
|
+
this._jitterIndex = 0;
|
|
35
|
+
this._originalProjectionMatrix = new Matrix4();
|
|
36
|
+
|
|
37
|
+
// uniforms
|
|
38
|
+
|
|
39
|
+
this._invSize = uniform( new Vector2() );
|
|
40
|
+
|
|
41
|
+
// render targets
|
|
42
|
+
|
|
43
|
+
this._sampleRenderTarget = null;
|
|
44
|
+
this._historyRenderTarget = null;
|
|
45
|
+
|
|
46
|
+
// materials
|
|
47
|
+
|
|
48
|
+
this._resolveMaterial = new NodeMaterial();
|
|
49
|
+
this._resolveMaterial.name = 'TRAA.Resolve';
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
setSize( width, height ) {
|
|
54
|
+
|
|
55
|
+
super.setSize( width, height );
|
|
56
|
+
|
|
57
|
+
let needsRestart = false;
|
|
58
|
+
|
|
59
|
+
if ( this.renderTarget.width !== this._sampleRenderTarget.width || this.renderTarget.height !== this._sampleRenderTarget.height ) {
|
|
60
|
+
|
|
61
|
+
this._sampleRenderTarget.setSize( this.renderTarget.width, this.renderTarget.height );
|
|
62
|
+
this._historyRenderTarget.setSize( this.renderTarget.width, this.renderTarget.height );
|
|
63
|
+
|
|
64
|
+
this._invSize.value.set( 1 / this.renderTarget.width, 1 / this.renderTarget.height );
|
|
65
|
+
|
|
66
|
+
needsRestart = true;
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return needsRestart;
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
updateBefore( frame ) {
|
|
75
|
+
|
|
76
|
+
const { renderer } = frame;
|
|
77
|
+
const { scene, camera } = this;
|
|
78
|
+
|
|
79
|
+
_rendererState = PostProcessingUtils.resetRendererAndSceneState( renderer, scene, _rendererState );
|
|
80
|
+
|
|
81
|
+
//
|
|
82
|
+
|
|
83
|
+
this._pixelRatio = renderer.getPixelRatio();
|
|
84
|
+
const size = renderer.getSize( _size );
|
|
85
|
+
|
|
86
|
+
const needsRestart = this.setSize( size.width, size.height );
|
|
87
|
+
|
|
88
|
+
// save original/unjittered projection matrix for velocity pass
|
|
89
|
+
|
|
90
|
+
camera.updateProjectionMatrix();
|
|
91
|
+
this._originalProjectionMatrix.copy( camera.projectionMatrix );
|
|
92
|
+
|
|
93
|
+
// camera configuration
|
|
94
|
+
|
|
95
|
+
this._cameraNear.value = camera.near;
|
|
96
|
+
this._cameraFar.value = camera.far;
|
|
97
|
+
|
|
98
|
+
// configure jitter as view offset
|
|
99
|
+
|
|
100
|
+
const viewOffset = {
|
|
101
|
+
|
|
102
|
+
fullWidth: this.renderTarget.width,
|
|
103
|
+
fullHeight: this.renderTarget.height,
|
|
104
|
+
offsetX: 0,
|
|
105
|
+
offsetY: 0,
|
|
106
|
+
width: this.renderTarget.width,
|
|
107
|
+
height: this.renderTarget.height
|
|
108
|
+
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const originalViewOffset = Object.assign( {}, camera.view );
|
|
112
|
+
|
|
113
|
+
if ( originalViewOffset.enabled ) Object.assign( viewOffset, originalViewOffset );
|
|
114
|
+
|
|
115
|
+
const jitterOffset = _JitterVectors[ this._jitterIndex ];
|
|
116
|
+
|
|
117
|
+
camera.setViewOffset(
|
|
118
|
+
|
|
119
|
+
viewOffset.fullWidth, viewOffset.fullHeight,
|
|
120
|
+
|
|
121
|
+
viewOffset.offsetX + jitterOffset[ 0 ] * 0.0625, viewOffset.offsetY + jitterOffset[ 1 ] * 0.0625, // 0.0625 = 1 / 16
|
|
122
|
+
|
|
123
|
+
viewOffset.width, viewOffset.height
|
|
124
|
+
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
// configure velocity
|
|
128
|
+
|
|
129
|
+
const mrt = this.getMRT();
|
|
130
|
+
const velocityOutput = mrt.get( 'velocity' );
|
|
131
|
+
|
|
132
|
+
if ( velocityOutput !== undefined ) {
|
|
133
|
+
|
|
134
|
+
velocityOutput.setProjectionMatrix( this._originalProjectionMatrix );
|
|
135
|
+
|
|
136
|
+
} else {
|
|
137
|
+
|
|
138
|
+
throw new Error( 'THREE:TRAAPassNode: Missing velocity output in MRT configuration.' );
|
|
139
|
+
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// render sample
|
|
143
|
+
|
|
144
|
+
renderer.setMRT( mrt );
|
|
145
|
+
|
|
146
|
+
renderer.setClearColor( this.clearColor, this.clearAlpha );
|
|
147
|
+
renderer.setRenderTarget( this._sampleRenderTarget );
|
|
148
|
+
renderer.render( scene, camera );
|
|
149
|
+
|
|
150
|
+
renderer.setRenderTarget( null );
|
|
151
|
+
renderer.setMRT( null );
|
|
152
|
+
|
|
153
|
+
// every time when the dimensions change we need fresh history data. Copy the sample
|
|
154
|
+
// into the history and final render target (no AA happens at that point).
|
|
155
|
+
|
|
156
|
+
if ( needsRestart === true ) {
|
|
157
|
+
|
|
158
|
+
// bind and clear render target to make sure they are initialized after the resize which triggers a dispose()
|
|
159
|
+
|
|
160
|
+
renderer.setRenderTarget( this._historyRenderTarget );
|
|
161
|
+
renderer.clear();
|
|
162
|
+
|
|
163
|
+
renderer.setRenderTarget( this.renderTarget );
|
|
164
|
+
renderer.clear();
|
|
165
|
+
|
|
166
|
+
renderer.setRenderTarget( null );
|
|
167
|
+
|
|
168
|
+
renderer.copyTextureToTexture( this._sampleRenderTarget.texture, this._historyRenderTarget.texture );
|
|
169
|
+
renderer.copyTextureToTexture( this._sampleRenderTarget.texture, this.renderTarget.texture );
|
|
170
|
+
|
|
171
|
+
} else {
|
|
172
|
+
|
|
173
|
+
// resolve
|
|
174
|
+
|
|
175
|
+
renderer.setRenderTarget( this.renderTarget );
|
|
176
|
+
_quadMesh.material = this._resolveMaterial;
|
|
177
|
+
_quadMesh.render( renderer );
|
|
178
|
+
renderer.setRenderTarget( null );
|
|
179
|
+
|
|
180
|
+
// update history
|
|
181
|
+
|
|
182
|
+
renderer.copyTextureToTexture( this.renderTarget.texture, this._historyRenderTarget.texture );
|
|
183
|
+
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// copy depth
|
|
187
|
+
|
|
188
|
+
renderer.copyTextureToTexture( this._sampleRenderTarget.depthTexture, this.renderTarget.depthTexture );
|
|
189
|
+
|
|
190
|
+
// update jitter index
|
|
191
|
+
|
|
192
|
+
this._jitterIndex ++;
|
|
193
|
+
this._jitterIndex = this._jitterIndex % ( _JitterVectors.length - 1 );
|
|
194
|
+
|
|
195
|
+
// restore
|
|
196
|
+
|
|
197
|
+
if ( originalViewOffset.enabled ) {
|
|
198
|
+
|
|
199
|
+
camera.setViewOffset(
|
|
200
|
+
|
|
201
|
+
originalViewOffset.fullWidth, originalViewOffset.fullHeight,
|
|
202
|
+
|
|
203
|
+
originalViewOffset.offsetX, originalViewOffset.offsetY,
|
|
204
|
+
|
|
205
|
+
originalViewOffset.width, originalViewOffset.height
|
|
206
|
+
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
} else {
|
|
210
|
+
|
|
211
|
+
camera.clearViewOffset();
|
|
212
|
+
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
velocityOutput.setProjectionMatrix( null );
|
|
216
|
+
|
|
217
|
+
PostProcessingUtils.restoreRendererAndSceneState( renderer, scene, _rendererState );
|
|
218
|
+
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
setup( builder ) {
|
|
222
|
+
|
|
223
|
+
if ( this._sampleRenderTarget === null ) {
|
|
224
|
+
|
|
225
|
+
this._sampleRenderTarget = this.renderTarget.clone();
|
|
226
|
+
this._historyRenderTarget = this.renderTarget.clone();
|
|
227
|
+
|
|
228
|
+
this._sampleRenderTarget.texture.minFiler = NearestFilter;
|
|
229
|
+
this._sampleRenderTarget.texture.magFilter = NearestFilter;
|
|
230
|
+
|
|
231
|
+
const velocityTarget = this._sampleRenderTarget.texture.clone();
|
|
232
|
+
velocityTarget.isRenderTargetTexture = true;
|
|
233
|
+
velocityTarget.name = 'velocity';
|
|
234
|
+
|
|
235
|
+
this._sampleRenderTarget.textures.push( velocityTarget ); // for MRT
|
|
236
|
+
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// textures
|
|
240
|
+
|
|
241
|
+
const historyTexture = texture( this._historyRenderTarget.texture );
|
|
242
|
+
const sampleTexture = texture( this._sampleRenderTarget.textures[ 0 ] );
|
|
243
|
+
const velocityTexture = texture( this._sampleRenderTarget.textures[ 1 ] );
|
|
244
|
+
const depthTexture = texture( this._sampleRenderTarget.depthTexture );
|
|
245
|
+
|
|
246
|
+
const resolve = Fn( () => {
|
|
247
|
+
|
|
248
|
+
const uvNode = uv();
|
|
249
|
+
|
|
250
|
+
const minColor = vec4( 10000 ).toVar();
|
|
251
|
+
const maxColor = vec4( - 10000 ).toVar();
|
|
252
|
+
const closestDepth = float( 1 ).toVar();
|
|
253
|
+
const closestDepthPixelPosition = vec2( 0 ).toVar();
|
|
254
|
+
|
|
255
|
+
// sample a 3x3 neighborhood to create a box in color space
|
|
256
|
+
// clamping the history color with the resulting min/max colors mitigates ghosting
|
|
257
|
+
|
|
258
|
+
Loop( { start: int( - 1 ), end: int( 1 ), type: 'int', condition: '<=', name: 'x' }, ( { x } ) => {
|
|
259
|
+
|
|
260
|
+
Loop( { start: int( - 1 ), end: int( 1 ), type: 'int', condition: '<=', name: 'y' }, ( { y } ) => {
|
|
261
|
+
|
|
262
|
+
const uvNeighbor = uvNode.add( vec2( float( x ), float( y ) ).mul( this._invSize ) ).toVar();
|
|
263
|
+
const colorNeighbor = max( vec4( 0 ), sampleTexture.uv( uvNeighbor ) ).toVar(); // use max() to avoid propagate garbage values
|
|
264
|
+
|
|
265
|
+
minColor.assign( min( minColor, colorNeighbor ) );
|
|
266
|
+
maxColor.assign( max( maxColor, colorNeighbor ) );
|
|
267
|
+
|
|
268
|
+
const currentDepth = depthTexture.uv( uvNeighbor ).r.toVar();
|
|
269
|
+
|
|
270
|
+
// find the sample position of the closest depth in the neighborhood (used for velocity)
|
|
271
|
+
|
|
272
|
+
If( currentDepth.lessThan( closestDepth ), () => {
|
|
273
|
+
|
|
274
|
+
closestDepth.assign( currentDepth );
|
|
275
|
+
closestDepthPixelPosition.assign( uvNeighbor );
|
|
276
|
+
|
|
277
|
+
} );
|
|
278
|
+
|
|
279
|
+
} );
|
|
280
|
+
|
|
281
|
+
} );
|
|
282
|
+
|
|
283
|
+
// sampling/reprojection
|
|
284
|
+
|
|
285
|
+
const offset = velocityTexture.uv( closestDepthPixelPosition ).xy.mul( vec2( 0.5, - 0.5 ) ); // NDC to uv offset
|
|
286
|
+
|
|
287
|
+
const currentColor = sampleTexture.uv( uvNode );
|
|
288
|
+
const historyColor = historyTexture.uv( uvNode.sub( offset ) );
|
|
289
|
+
|
|
290
|
+
// clamping
|
|
291
|
+
|
|
292
|
+
const clampedHistoryColor = clamp( historyColor, minColor, maxColor );
|
|
293
|
+
|
|
294
|
+
// flicker reduction based on luminance weighing
|
|
295
|
+
|
|
296
|
+
const currentWeight = float( 0.05 ).toVar();
|
|
297
|
+
const historyWeight = currentWeight.oneMinus().toVar();
|
|
298
|
+
|
|
299
|
+
const compressedCurrent = currentColor.mul( float( 1 ).div( ( max( max( currentColor.r, currentColor.g ), currentColor.b ).add( 1.0 ) ) ) );
|
|
300
|
+
const compressedHistory = clampedHistoryColor.mul( float( 1 ).div( ( max( max( clampedHistoryColor.r, clampedHistoryColor.g ), clampedHistoryColor.b ).add( 1.0 ) ) ) );
|
|
301
|
+
|
|
302
|
+
const luminanceCurrent = luminance( compressedCurrent.rgb );
|
|
303
|
+
const luminanceHistory = luminance( compressedHistory.rgb );
|
|
304
|
+
|
|
305
|
+
currentWeight.mulAssign( float( 1.0 ).div( luminanceCurrent.add( 1 ) ) );
|
|
306
|
+
historyWeight.mulAssign( float( 1.0 ).div( luminanceHistory.add( 1 ) ) );
|
|
307
|
+
|
|
308
|
+
return add( currentColor.mul( currentWeight ), clampedHistoryColor.mul( historyWeight ) ).div( max( currentWeight.add( historyWeight ), 0.00001 ) );
|
|
309
|
+
|
|
310
|
+
} );
|
|
311
|
+
|
|
312
|
+
// materials
|
|
313
|
+
|
|
314
|
+
this._resolveMaterial.fragmentNode = resolve();
|
|
315
|
+
|
|
316
|
+
return super.setup( builder );
|
|
317
|
+
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
dispose() {
|
|
321
|
+
|
|
322
|
+
super.dispose();
|
|
323
|
+
|
|
324
|
+
if ( this._sampleRenderTarget !== null ) {
|
|
325
|
+
|
|
326
|
+
this._sampleRenderTarget.dispose();
|
|
327
|
+
this._historyRenderTarget.dispose();
|
|
328
|
+
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
this._resolveMaterial.dispose();
|
|
332
|
+
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export default TRAAPassNode;
|
|
338
|
+
|
|
339
|
+
// These jitter vectors are specified in integers because it is easier.
|
|
340
|
+
// I am assuming a [-8,8) integer grid, but it needs to be mapped onto [-0.5,0.5)
|
|
341
|
+
// before being used, thus these integers need to be scaled by 1/16.
|
|
342
|
+
//
|
|
343
|
+
// Sample patterns reference: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476218%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
|
|
344
|
+
const _JitterVectors = [
|
|
345
|
+
[ - 4, - 7 ], [ - 7, - 5 ], [ - 3, - 5 ], [ - 5, - 4 ],
|
|
346
|
+
[ - 1, - 4 ], [ - 2, - 2 ], [ - 6, - 1 ], [ - 4, 0 ],
|
|
347
|
+
[ - 7, 1 ], [ - 1, 2 ], [ - 6, 3 ], [ - 3, 3 ],
|
|
348
|
+
[ - 7, 6 ], [ - 3, 6 ], [ - 5, 7 ], [ - 1, 7 ],
|
|
349
|
+
[ 5, - 7 ], [ 1, - 6 ], [ 6, - 5 ], [ 4, - 4 ],
|
|
350
|
+
[ 2, - 3 ], [ 7, - 2 ], [ 1, - 1 ], [ 4, - 1 ],
|
|
351
|
+
[ 2, 1 ], [ 6, 2 ], [ 0, 4 ], [ 4, 4 ],
|
|
352
|
+
[ 2, 5 ], [ 7, 5 ], [ 5, 6 ], [ 3, 7 ]
|
|
353
|
+
];
|
|
354
|
+
|
|
355
|
+
export const traaPass = ( scene, camera ) => nodeObject( new TRAAPassNode( scene, camera ) );
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import TempNode from '
|
|
2
|
-
import { uv } from '../accessors/UV.js';
|
|
3
|
-
import { Fn, nodeObject, float, int, vec4, If } from '../tsl/TSLBase.js';
|
|
4
|
-
import { clamp, mix } from '../math/MathNode.js';
|
|
5
|
-
import { sub } from '../math/OperatorNode.js';
|
|
6
|
-
import { convertToTexture } from '../utils/RTTNode.js';
|
|
1
|
+
import { TempNode, nodeObject, Fn, float, uv, convertToTexture, vec4, If, int, clamp, sub, mix } from 'three/tsl';
|
|
7
2
|
|
|
8
3
|
class TransitionNode extends TempNode {
|
|
9
4
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { float, Fn, vec2, uv, sin, rand, degrees, cos, Loop, vec4 } from 'three/tsl';
|
|
2
|
+
|
|
3
|
+
// https://www.shadertoy.com/view/4lXXWn
|
|
4
|
+
|
|
5
|
+
export const hashBlur = /*#__PURE__*/ Fn( ( [ textureNode, bluramount = float( 0.1 ), repeats = float( 45 ) ] ) => {
|
|
6
|
+
|
|
7
|
+
const draw = ( uv ) => textureNode.uv( uv );
|
|
8
|
+
|
|
9
|
+
const targetUV = textureNode.uvNode || uv();
|
|
10
|
+
const blurred_image = vec4( 0. ).toVar();
|
|
11
|
+
|
|
12
|
+
Loop( { start: 0., end: repeats, type: 'float' }, ( { i } ) => {
|
|
13
|
+
|
|
14
|
+
const q = vec2( vec2( cos( degrees( i.div( repeats ).mul( 360. ) ) ), sin( degrees( i.div( repeats ).mul( 360. ) ) ) ).mul( rand( vec2( i, targetUV.x.add( targetUV.y ) ) ).add( bluramount ) ) );
|
|
15
|
+
const uv2 = vec2( targetUV.add( q.mul( bluramount ) ) );
|
|
16
|
+
blurred_image.addAssign( draw( uv2 ) );
|
|
17
|
+
|
|
18
|
+
} );
|
|
19
|
+
|
|
20
|
+
blurred_image.divAssign( repeats );
|
|
21
|
+
|
|
22
|
+
return blurred_image;
|
|
23
|
+
|
|
24
|
+
} );
|