@threepipe/webgi-plugins 0.8.0 → 0.9.0-r172.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE +190 -141
  3. package/README.md +2 -17
  4. package/THIRD_PARTY_NOTICES.md +1 -1
  5. package/dist/index.js +184 -42
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +185 -43
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/plugins/buffer/VelocityBufferPlugin.d.ts +23 -0
  10. package/dist/plugins/buffer/VelocityBufferPlugin.d.ts.map +1 -1
  11. package/dist/plugins/extras/AnisotropyPlugin.d.ts +1 -1
  12. package/dist/plugins/extras/AnisotropyPlugin.d.ts.map +1 -1
  13. package/dist/plugins/postprocessing/OutlinePlugin.d.ts +3 -0
  14. package/dist/plugins/postprocessing/OutlinePlugin.d.ts.map +1 -1
  15. package/dist/plugins/postprocessing/TemporalAAPlugin.d.ts +14 -0
  16. package/dist/plugins/postprocessing/TemporalAAPlugin.d.ts.map +1 -1
  17. package/docs/assets/search.js +1 -1
  18. package/docs/classes/AdvancedGroundPlugin.html +64 -64
  19. package/docs/classes/AnisotropyPlugin.html +32 -32
  20. package/docs/classes/BloomPlugin.html +36 -36
  21. package/docs/classes/BloomPluginPass.html +28 -28
  22. package/docs/classes/DepthOfFieldPlugin.html +40 -40
  23. package/docs/classes/DepthOfFieldPluginPass.html +31 -31
  24. package/docs/classes/OutlinePlugin.html +64 -64
  25. package/docs/classes/OutlineRenderPass.html +18 -18
  26. package/docs/classes/SSContactShadowsPlugin.html +35 -35
  27. package/docs/classes/SSGIPlugin.html +40 -40
  28. package/docs/classes/SSGIPluginPass.html +38 -38
  29. package/docs/classes/SSReflectionPlugin.html +41 -41
  30. package/docs/classes/SSReflectionPluginPass.html +39 -39
  31. package/docs/classes/SSVelocityMaterial.html +22 -7
  32. package/docs/classes/TemporalAAPlugin.html +34 -34
  33. package/docs/classes/TemporalAAPluginPass.html +68 -28
  34. package/docs/classes/VelocityBufferPlugin.html +62 -42
  35. package/docs/classes/WatchHandsPlugin.html +39 -39
  36. package/docs/types/OutlinePluginPass.html +1 -1
  37. package/docs/types/OutlinePluginTarget.html +1 -1
  38. package/docs/types/SSGIPluginTarget.html +1 -1
  39. package/docs/types/SSReflectionPluginTarget.html +1 -1
  40. package/docs/types/VelocityBufferPluginPass.html +1 -1
  41. package/docs/types/VelocityBufferPluginTarget.html +1 -1
  42. package/docs/variables/anisotropyGLTFExtension.html +3 -3
  43. package/docs/variables/webgiPlugins.html +1 -1
  44. package/package.json +6 -3
  45. package/src/plugins/buffer/VelocityBufferPlugin.ts +119 -8
  46. package/src/plugins/buffer/shaders/VelocityBufferPlugin.mat.frag.glsl +9 -1
  47. package/src/plugins/buffer/shaders/VelocityBufferPlugin.mat.vert.glsl +14 -1
  48. package/src/plugins/extras/AnisotropyPlugin.ts +2 -2
  49. package/src/plugins/postprocessing/OutlinePlugin.ts +53 -38
  50. package/src/plugins/postprocessing/SSContactShadowsPlugin.ts +1 -1
  51. package/src/plugins/postprocessing/TemporalAAPlugin.ts +42 -0
  52. package/src/utils/shaders/temporalaa.glsl +9 -0
@@ -2,6 +2,11 @@ import {
2
2
  BufferGeometry,
3
3
  Camera,
4
4
  Color,
5
+ DataTexture,
6
+ FloatType,
7
+ InstancedMesh,
8
+ NearestFilter,
9
+ RGBAFormat,
5
10
  DoubleSide,
6
11
  GBufferRenderPass,
7
12
  ICamera,
@@ -22,8 +27,11 @@ import {
22
27
  Texture,
23
28
  TextureDataType,
24
29
  ThreeViewer,
30
+ onChange,
31
+ serialize,
25
32
  uiFolderContainer,
26
33
  uiImage,
34
+ uiSlider,
27
35
  Group,
28
36
  UnsignedByteType,
29
37
  Vector2,
@@ -56,6 +64,27 @@ export class VelocityBufferPlugin
56
64
  @uiImage('Velocity Buffer', {readOnly: true}) texture?: Texture
57
65
  readonly material: SSVelocityMaterial = new SSVelocityMaterial()
58
66
 
67
+ /**
68
+ * Debug: a split of the screen at this x (0 to 1, 0 is off). Left of it the buffer holds the camera's motion only,
69
+ * as if there were no velocity buffer, so TAA and the screen-space reflections and GI smear moving objects there;
70
+ * right of it, the full motion. Off (0), the shader is as without it.
71
+ */
72
+ @uiSlider('Split', [0, 1], 0.01, {tags: ['debug']})
73
+ @onChange(VelocityBufferPlugin.prototype._splitChanged)
74
+ @serialize() split = 0
75
+
76
+ protected _splitChanged() {
77
+ const m = this.material, on = this.split > 0
78
+ m.uniforms.velocitySplitX.value = this.split
79
+ if (!!m.defines.VELOCITY_SPLIT !== on) {
80
+ if (on) m.defines.VELOCITY_SPLIT = 1
81
+ else delete m.defines.VELOCITY_SPLIT
82
+ m.needsUpdate = true
83
+ }
84
+ // (also set while constructing, before the extension below exists)
85
+ if (this._viewer) this.setDirty()
86
+ }
87
+
59
88
  // @onChange2(VelocityBufferPlugin.prototype._createTarget)
60
89
  // @uiDropdown('Buffer Type', threeConstMappings.TextureDataType.uiConfig)
61
90
  readonly bufferType: TextureDataType // cannot be changed after creation (for now)
@@ -146,6 +175,9 @@ export class VelocityBufferPlugin
146
175
 
147
176
  onRemove(viewer: ThreeViewer): void {
148
177
  this._disposeTarget()
178
+ // the per-mesh history (instance matrix textures, listeners on the meshes) lives in the material: released
179
+ // here, not only when each mesh is disposed. The material is reused if the plugin is added again.
180
+ this.material.dispose()
149
181
  return super.onRemove(viewer)
150
182
  }
151
183
 
@@ -209,6 +241,7 @@ export class SSVelocityMaterial extends ShaderMaterial {
209
241
  alphaMapTransform: {value: /* @__PURE__*/ new Matrix3()},
210
242
  currentProjectionViewMatrix: {value: new Matrix4()},
211
243
  lastProjectionViewMatrix: {value: new Matrix4()},
244
+ velocitySplitX: {value: 0},
212
245
  },
213
246
  blending: NoBlending, // todo?
214
247
  })
@@ -216,21 +249,99 @@ export class SSVelocityMaterial extends ShaderMaterial {
216
249
 
217
250
  extraUniformsToUpload: Record<string, IUniform> = {
218
251
  modelMatrixPrevious: {value: new Matrix4().identity()},
252
+ // instanced meshes: the previous frame's instance matrices, 4 texels (columns) per instance, 1024 per row
253
+ instanceMatrixPrevious: {value: null},
254
+ hasInstanceMatrixPrevious: {value: false},
255
+ }
256
+
257
+ /**
258
+ * The world matrix of each object in the last and in this frame's velocity render. Advanced once per render
259
+ * (`frame`): an object with several material groups is drawn (and gets onBeforeRender) once per group, and
260
+ * copying the matrix at each draw left every group after the first with no motion.
261
+ */
262
+ private _previousWorldMatrices: Record<string, {previous: Matrix4, current: Matrix4, frame: number}> = {}
263
+ /**
264
+ * Previous instance matrices per instanced mesh: two float textures, the one written last frame is read by this
265
+ * frame's draw while this frame's matrices go into the other (once per render, for all of the mesh's groups).
266
+ * Without them every instance got the mesh's motion only (camera motion for a static mesh), so TAA and the
267
+ * SSGI/SSR history smeared moving instances.
268
+ */
269
+ private _previousInstanceMatrices: Record<string, {textures: [DataTexture, DataTexture], data: [Float32Array, Float32Array], read: 0 | 1, valid: boolean, capacity: number, frame: number, readNow: DataTexture | null}> = {}
270
+ /** The dispose listener added to each instanced mesh with a history (removed in {@link dispose}). */
271
+ private _meshListeners = new Map<string, {object: IObject3D, listener: () => void}>()
272
+
273
+ private _instancePrevious(object: InstancedMesh, frame: number) {
274
+ const capacity = object.instanceMatrix.count
275
+ let e = this._previousInstanceMatrices[object.uuid]
276
+ if (!e || e.capacity !== capacity) {
277
+ if (e) e.textures.forEach(t => t.dispose())
278
+ else if ((object as any as IObject3D).addEventListener) {
279
+ const o = object as any as IObject3D
280
+ const listener = () => {
281
+ const d = this._previousInstanceMatrices[object.uuid]
282
+ if (d) d.textures.forEach(t => t.dispose())
283
+ delete this._previousInstanceMatrices[object.uuid]
284
+ delete this._previousWorldMatrices[object.uuid]
285
+ this._meshListeners.delete(object.uuid)
286
+ o.removeEventListener('dispose', listener)
287
+ }
288
+ o.addEventListener('dispose', listener)
289
+ this._meshListeners.set(object.uuid, {object: o, listener})
290
+ }
291
+ // the texture's layout is the instanceMatrix array's: instance i's 16 floats at i * 16
292
+ const width = 4 * Math.min(capacity, 1024), height = Math.ceil(capacity / 1024)
293
+ const data = [new Float32Array(width * height * 4), new Float32Array(width * height * 4)] as const
294
+ const make = (i: 0 | 1) => {
295
+ const t = new DataTexture(data[i], width, height, RGBAFormat, FloatType)
296
+ t.minFilter = t.magFilter = NearestFilter
297
+ t.generateMipmaps = false
298
+ t.name = 'instanceMatrixPrevious'
299
+ return t
300
+ }
301
+ e = this._previousInstanceMatrices[object.uuid] = {textures: [make(0), make(1)], data: [data[0], data[1]], read: 0, valid: false, capacity, frame: -1, readNow: null}
302
+ }
303
+ if (e.frame !== frame) {
304
+ e.frame = frame
305
+ e.readNow = e.valid ? e.textures[e.read] : null
306
+ // this frame's matrices, for the next frame
307
+ const w = 1 - e.read as 0 | 1
308
+ e.data[w].set(object.instanceMatrix.array)
309
+ e.textures[w].needsUpdate = true
310
+ e.read = 1 - e.read as 0 | 1
311
+ e.valid = true
312
+ }
313
+ const u = this.extraUniformsToUpload
314
+ u.instanceMatrixPrevious.value = e.readNow
315
+ u.hasInstanceMatrixPrevious.value = !!e.readNow
219
316
  }
220
317
 
221
- private _previousWorldMatrices: Record<string, Matrix4> = {}
318
+ dispose() {
319
+ for (const e of Object.values(this._previousInstanceMatrices)) e.textures.forEach(t => t.dispose())
320
+ for (const {object, listener} of this._meshListeners.values()) object.removeEventListener('dispose', listener)
321
+ this._meshListeners.clear()
322
+ this._previousInstanceMatrices = {}
323
+ this._previousWorldMatrices = {}
324
+ super.dispose()
325
+ }
222
326
 
223
327
  // this gets called for each object.
224
328
  onBeforeRender(_r: WebGLRenderer, _s: Scene, _c: Camera, _geometry: BufferGeometry, object: IObject3D, group: Group) {
225
329
  super.onBeforeRender(_r, _s, _c, _geometry, object, group)
226
- const prevMatrix = this._previousWorldMatrices[object.uuid]
227
- this.extraUniformsToUpload.modelMatrixPrevious.value.copy(prevMatrix ?? object.matrixWorld)
330
+ // one velocity render is one renderer.render call: its frame counter tells a new frame from another group's draw
331
+ const frame = _r.info.render.frame
332
+ let world = this._previousWorldMatrices[object.uuid]
333
+ if (!world) world = this._previousWorldMatrices[object.uuid] = {previous: object.matrixWorld.clone(), current: object.matrixWorld.clone(), frame}
334
+ else if (world.frame !== frame) {
335
+ world.previous.copy(world.current)
336
+ world.current.copy(object.matrixWorld)
337
+ world.frame = frame
338
+ }
339
+ this.extraUniformsToUpload.modelMatrixPrevious.value.copy(world.previous)
228
340
 
229
- // todo: make sure all objects are only rendered once.
230
- if (prevMatrix) {
231
- prevMatrix.copy(object.matrixWorld)
232
- } else {
233
- this._previousWorldMatrices[object.uuid] = object.matrixWorld.clone()
341
+ if ((object as any).isInstancedMesh) this._instancePrevious(object as any as InstancedMesh, frame)
342
+ else {
343
+ this.extraUniformsToUpload.instanceMatrixPrevious.value = null
344
+ this.extraUniformsToUpload.hasInstanceMatrixPrevious.value = false
234
345
  }
235
346
 
236
347
  // todo: add support for all this in the shaders.
@@ -10,10 +10,18 @@ varying vec3 vWorldPosition;
10
10
  varying vec3 vWorldPositionPrevious;
11
11
  uniform mat4 currentProjectionViewMatrix;
12
12
  uniform mat4 lastProjectionViewMatrix;
13
+ #ifdef VELOCITY_SPLIT
14
+ // left of it (screen x, 0 to 1) the objects' own motion is left out: the camera's only, as without a velocity buffer
15
+ uniform float velocitySplitX;
16
+ #endif
13
17
 
14
18
  vec2 computeScreenSpaceVelocity2() {
15
19
  vec4 currentPositionClip = currentProjectionViewMatrix * vec4(vWorldPosition, 1.0);
16
- vec4 prevPositionClip = lastProjectionViewMatrix * vec4(vWorldPositionPrevious, 1.0);
20
+ vec3 previousWorld = vWorldPositionPrevious;
21
+ #ifdef VELOCITY_SPLIT
22
+ if (currentPositionClip.x / currentPositionClip.w * 0.5 + 0.5 < velocitySplitX) previousWorld = vWorldPosition;
23
+ #endif
24
+ vec4 prevPositionClip = lastProjectionViewMatrix * vec4(previousWorld, 1.0);
17
25
 
18
26
  vec2 currentPositionNDC = currentPositionClip.xy / currentPositionClip.w;
19
27
  vec2 prevPositionNDC = prevPositionClip.xy / prevPositionClip.w;
@@ -15,6 +15,17 @@ varying vec3 vWorldPositionPrevious;
15
15
 
16
16
  uniform mat4 modelMatrixPrevious;
17
17
 
18
+ #ifdef USE_INSTANCING
19
+ // the previous frame's instance matrices (VelocityBufferPlugin): 4 texels (columns) per instance, 1024 instances a row
20
+ uniform sampler2D instanceMatrixPrevious;
21
+ uniform bool hasInstanceMatrixPrevious;
22
+ mat4 getInstanceMatrixPrevious() {
23
+ int x = (gl_InstanceID % 1024) * 4, y = gl_InstanceID / 1024;
24
+ return mat4(texelFetch(instanceMatrixPrevious, ivec2(x, y), 0), texelFetch(instanceMatrixPrevious, ivec2(x + 1, y), 0),
25
+ texelFetch(instanceMatrixPrevious, ivec2(x + 2, y), 0), texelFetch(instanceMatrixPrevious, ivec2(x + 3, y), 0));
26
+ }
27
+ #endif
28
+
18
29
  void main() {
19
30
 
20
31
  #include <uv_vertex>
@@ -29,15 +40,17 @@ void main() {
29
40
  // project_vertex
30
41
 
31
42
  vec4 mvPosition = vec4( transformed, 1.0 );
43
+ vec4 previousPosition = mvPosition;
32
44
 
33
45
  #ifdef USE_INSTANCING
34
46
 
47
+ previousPosition = hasInstanceMatrixPrevious ? getInstanceMatrixPrevious() * mvPosition : instanceMatrix * mvPosition;
35
48
  mvPosition = instanceMatrix * mvPosition;
36
49
 
37
50
  #endif
38
51
 
39
52
  vWorldPosition = (modelMatrix * mvPosition).xyz;
40
- vWorldPositionPrevious = (modelMatrixPrevious * mvPosition).xyz;
53
+ vWorldPositionPrevious = (modelMatrixPrevious * previousPosition).xyz;
41
54
 
42
55
  mvPosition = modelViewMatrix * mvPosition;
43
56
 
@@ -478,7 +478,7 @@ class GLTFMaterialsAnisotropyExtensionImport implements GLTFLoaderPlugin {
478
478
 
479
479
 
480
480
  const glTFMaterialsAnisotropyExtensionExport = (w: GLTFWriter2)=> ({
481
- writeMaterial: (material: any, materialDef: any) => {
481
+ writeMaterialAsync: async(material: any, materialDef: any) => {
482
482
  if (!material.isMeshStandardMaterial || !material.userData._isAnisotropic) return
483
483
 
484
484
  if ((material.userData._anisotropyFactor || 0) < 0.001) return // todo: is this correct?
@@ -493,7 +493,7 @@ const glTFMaterialsAnisotropyExtensionExport = (w: GLTFWriter2)=> ({
493
493
 
494
494
  if (w.checkEmptyMap(material.userData._anisotropyDirectionMap) && extensionDef.anisotropyDirectionMode !== 'CONSTANT') {
495
495
 
496
- const anisotropyDirectionMapDef = {index: w.processTexture(material.userData._anisotropyDirectionMap)}
496
+ const anisotropyDirectionMapDef = {index: await w.processTextureAsync(material.userData._anisotropyDirectionMap)}
497
497
  w.applyTextureTransform(anisotropyDirectionMapDef, material.userData._anisotropyDirectionMap)
498
498
  extensionDef.anisotropyDirection = anisotropyDirectionMapDef
499
499
 
@@ -144,9 +144,48 @@ export class OutlinePlugin extends AScreenPassExtensionPlugin {
144
144
  }
145
145
  dependencies = [PickingPlugin, GBufferPlugin]
146
146
 
147
+ private _pickingPlugin?: PickingPlugin
148
+
149
+ private _onSelectedObjectChanged = () => {
150
+ if (this._animationCallBack) return
151
+ if (this._pickingPlugin?.getSelectedObject()) {
152
+ if (this.enableDynamicSelection) {
153
+ this.transparency = 1
154
+ this._animationCallBack = this._startTransparencyAnimation(1, this.highlightTransparency, 400)
155
+ } else {
156
+ this.transparency = this.highlightTransparency
157
+ }
158
+ } else {
159
+ this.transparency = 1
160
+ }
161
+ }
162
+
163
+ private _onMouseMove = (e: MouseEvent) => {
164
+ if (!this.mouseInOutAnimationEnabled) return
165
+ if (!this.enableHighlight) return
166
+ const selectedObject = this._pickingPlugin?.getSelectedObject()
167
+ if (selectedObject && this.enableDynamicSelection) {
168
+ if (e.target !== this._viewer?.canvas) {
169
+ if (!this._animationCallBack && this._state === 'in') {
170
+ this._animationCallBack = this._startTransparencyAnimation(this.highlightTransparency, 1, 600)
171
+ this._state = 'out'
172
+ }
173
+ } else {
174
+ if (!this._animationCallBack && this._state === 'out') {
175
+ this._animationCallBack = this._startTransparencyAnimation(1, this.highlightTransparency, 600)
176
+ this._state = 'in'
177
+ }
178
+ }
179
+ } else {
180
+ this.transparency = selectedObject ? this.highlightTransparency : 1
181
+ }
182
+ }
183
+
147
184
  private _pickingWidgetDisabled = false
148
185
  setDirty() {
149
186
  super.setDirty()
187
+ // the pass renders the selection into the outline buffer: not while the plugin is disabled
188
+ if (this._pass) this._pass.enabled = !this.isDisabled()
150
189
  if (!this._viewer) return
151
190
  const picking = this._viewer.getPlugin(PickingPlugin)
152
191
  let enabled = !this.isDisabled()
@@ -177,51 +216,27 @@ export class OutlinePlugin extends AScreenPassExtensionPlugin {
177
216
  this.setDirty() // for picking widget
178
217
 
179
218
  this._pass = this._createPass()
219
+ this._pass.enabled = !this.isDisabled()
180
220
  this._pass.onDirty?.push(viewer.setDirty)
181
221
  // this._pass.beforeRender = wrapThisFunction2(this._beforeRender, this._pass.beforeRender) // not needed at the moment
182
222
  viewer.renderManager.registerPass(this._pass)
183
223
 
184
- // todo use forPlugin and remove listener
185
- const pickingPlugin = viewer.getPlugin(PickingPlugin)
186
- pickingPlugin?.addEventListener('selectedObjectChanged', ()=> {
187
- if (!this._animationCallBack && this) {
188
- if (pickingPlugin?.getSelectedObject()) {
189
- if (this.enableDynamicSelection) {
190
- this.transparency = 1
191
- this._animationCallBack = this._startTransparencyAnimation(1, this.highlightTransparency, 400)
192
- } else {
193
- this.transparency = this.highlightTransparency
194
- }
195
- } else {
196
- this.transparency = 1
197
- }
198
- }
199
- })
224
+ viewer.forPlugin(PickingPlugin, (p) => {
225
+ this._pickingPlugin = p
226
+ p.addEventListener('selectedObjectChanged', this._onSelectedObjectChanged)
227
+ }, (p) => {
228
+ p.removeEventListener('selectedObjectChanged', this._onSelectedObjectChanged)
229
+ this._pickingPlugin = undefined
230
+ }, this)
200
231
 
201
- // todo remove listener
202
- document.addEventListener('mousemove', (e: MouseEvent)=> {
203
- if (!this) return
204
- if (!this.mouseInOutAnimationEnabled) return
205
- if (!this.enableHighlight) return
206
- const selectedObject = pickingPlugin?.getSelectedObject()
207
- if (selectedObject && this.enableDynamicSelection) {
208
- if (e.target !== viewer.canvas) {
209
- if (!this._animationCallBack && this._state === 'in') {
210
- this._animationCallBack = this._startTransparencyAnimation(this.highlightTransparency, 1, 600)
211
- this._state = 'out'
212
- }
213
- } else {
214
- if (!this._animationCallBack && this._state === 'out') {
215
- this._animationCallBack = this._startTransparencyAnimation(1, this.highlightTransparency, 600)
216
- this._state = 'in'
217
- }
218
- }
219
- } else {
220
- this.transparency = selectedObject ? this.highlightTransparency : 1
221
- }
222
- })
232
+ document.addEventListener('mousemove', this._onMouseMove, {passive: true})
223
233
  }
224
234
  onRemove(viewer: ThreeViewer): void {
235
+ document.removeEventListener('mousemove', this._onMouseMove)
236
+ this._pickingPlugin?.removeEventListener('selectedObjectChanged', this._onSelectedObjectChanged)
237
+ this._pickingPlugin = undefined
238
+ this._animationCallBack = undefined
239
+
225
240
  this._disposeTarget()
226
241
  if (this._pass) {
227
242
  viewer.renderManager.unregisterPass(this._pass)
@@ -362,7 +362,7 @@ export class SSContactShadowsPlugin extends AViewerPluginSync {
362
362
  // }
363
363
  //
364
364
  // const glTFMaterialsSSContactShadowsExtensionExport = (w: GLTFWriter2)=> ({
365
- // writeMaterial: (material: any, materialDef: any) => {
365
+ // writeMaterialAsync: async(material: any, materialDef: any) => {
366
366
  // if (!material.isMeshStandardMaterial || !material.userData._clearcoatTint?.enableTint) return
367
367
  // materialDef.extensions = materialDef.extensions || {}
368
368
  //
@@ -14,12 +14,14 @@ import {
14
14
  matDefineBool,
15
15
  MaterialExtension,
16
16
  Matrix4,
17
+ onChange,
17
18
  PipelinePassPlugin,
18
19
  ProgressivePlugin,
19
20
  serialize,
20
21
  ThreeViewer,
21
22
  uiConfig,
22
23
  UiObjectConfig,
24
+ uiSlider,
23
25
  uiToggle,
24
26
  uiVector,
25
27
  uniform,
@@ -210,6 +212,7 @@ export class TemporalAAPluginPass<Tid extends IPassID> extends ExtendedShaderPas
210
212
  inverseViewMatrix: {value: new Matrix4()},
211
213
  jitterSample: {value: new Vector2()},
212
214
  firstFrame: {value: true},
215
+ taaSplitX: {value: 0},
213
216
  },
214
217
  defines: {
215
218
  ['QUALITY']: 1,
@@ -275,6 +278,45 @@ export class TemporalAAPluginPass<Tid extends IPassID> extends ExtendedShaderPas
275
278
  @matDefineBool('DEBUG_VELOCITY', undefined, false, undefined, true)
276
279
  debugVelocity = false
277
280
 
281
+ /**
282
+ * Debug: a split of the screen at this x (0 to 1, 0 is off): left of it the current frame without TAA, right of
283
+ * it with TAA, like the Split of SSReflectionPlugin and SSGIPlugin. Off (0), the shader is as without it.
284
+ */
285
+ @uiSlider('Split', [0, 1], 0.01, {tags: ['debug']})
286
+ @onChange(TemporalAAPluginPass.prototype._splitChanged)
287
+ @serialize() split = 0
288
+
289
+ /**
290
+ * Debug: clamp the history to the colours around each pixel in the current frame (on, the default). Off, a pixel
291
+ * whose history was taken from the wrong place (an object moving where only the camera's motion is known) shows it as
292
+ * ghosting and smear, which the clamp otherwise hides at the cost of less smoothing on that object. Off, it is
293
+ * compiled out of the shader.
294
+ */
295
+ @uiToggle('Clamp history', {tags: ['debug']})
296
+ @onChange(TemporalAAPluginPass.prototype._clampChanged)
297
+ @serialize() clamp = true
298
+
299
+ protected _clampChanged() {
300
+ const off = !this.clamp
301
+ if (!!this.material.defines.TAA_NO_CLAMP !== off) {
302
+ if (off) this.material.defines.TAA_NO_CLAMP = 1
303
+ else delete this.material.defines.TAA_NO_CLAMP
304
+ this.material.needsUpdate = true
305
+ }
306
+ this.setDirty()
307
+ }
308
+
309
+ protected _splitChanged() {
310
+ const on = this.split > 0
311
+ this.uniforms.taaSplitX.value = this.split
312
+ if (!!this.material.defines.TAA_SPLIT !== on) {
313
+ if (on) this.material.defines.TAA_SPLIT = 1
314
+ else delete this.material.defines.TAA_SPLIT
315
+ this.material.needsUpdate = true
316
+ }
317
+ this.setDirty()
318
+ }
319
+
278
320
  uiConfig: UiObjectConfig = {
279
321
  type: 'folder',
280
322
  label: 'Temporal AA Pass',
@@ -14,6 +14,9 @@ uniform vec2 previousRTSize;
14
14
  uniform vec2 jitterSample;
15
15
  uniform vec2 feedBack;
16
16
  uniform bool firstFrame;
17
+ #ifdef TAA_SPLIT
18
+ uniform float taaSplitX;
19
+ #endif
17
20
 
18
21
  //float getViewZ( const in float depth ) {
19
22
  // #if PERSPECTIVE_CAMERA == 1
@@ -137,7 +140,9 @@ vec4 computeTAA(const in vec2 uv, const in vec2 screenSpaceVelocity, const in fl
137
140
 
138
141
  cmin = 0.5 * (cmin + min5);
139
142
  cmax = 0.5 * (cmax + max5);
143
+ #ifndef TAA_NO_CLAMP
140
144
  previousColor = clip_aabb(cmin, cmax, previousColor);
145
+ #endif
141
146
 
142
147
  float lum0 = luminance(currentColor.rgb);
143
148
  float lum1 = luminance(previousColor.rgb);
@@ -168,6 +173,10 @@ void main() {
168
173
  #endif
169
174
 
170
175
  bool bg = firstFrame;
176
+ #ifdef TAA_SPLIT
177
+ // left of the split: the current frame, as without TAA
178
+ bg = bg || vUv.x < taaSplitX;
179
+ #endif
171
180
 
172
181
  #if BACKGROUND_TAA // this is required for edge artifacts in msaa
173
182