@threepipe/webgi-plugins 0.7.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 (82) hide show
  1. package/CHANGELOG.md +36 -1
  2. package/LICENSE +182 -16
  3. package/README.md +5 -7
  4. package/THIRD_PARTY_NOTICES.md +1 -1
  5. package/dist/index.js +3946 -4433
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +3825 -4404
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/passes/BilateralFilterPass.d.ts +1 -1
  10. package/dist/passes/BilateralFilterPass.d.ts.map +1 -1
  11. package/dist/plugins/buffer/VelocityBufferPlugin.d.ts +23 -0
  12. package/dist/plugins/buffer/VelocityBufferPlugin.d.ts.map +1 -1
  13. package/dist/plugins/extras/AdvancedGroundPlugin.d.ts +1 -1
  14. package/dist/plugins/extras/AdvancedGroundPlugin.d.ts.map +1 -1
  15. package/dist/plugins/extras/AnisotropyPlugin.d.ts +5 -4
  16. package/dist/plugins/extras/AnisotropyPlugin.d.ts.map +1 -1
  17. package/dist/plugins/extras/WatchHandsPlugin.d.ts +1 -1
  18. package/dist/plugins/extras/WatchHandsPlugin.d.ts.map +1 -1
  19. package/dist/plugins/index.d.ts +9 -9
  20. package/dist/plugins/postprocessing/BloomPlugin.d.ts.map +1 -1
  21. package/dist/plugins/postprocessing/DepthOfFieldPlugin.d.ts.map +1 -1
  22. package/dist/plugins/postprocessing/OutlinePlugin.d.ts +4 -1
  23. package/dist/plugins/postprocessing/OutlinePlugin.d.ts.map +1 -1
  24. package/dist/plugins/postprocessing/SSContactShadowsPlugin.d.ts.map +1 -1
  25. package/dist/plugins/postprocessing/SSGIPlugin.d.ts +1 -1
  26. package/dist/plugins/postprocessing/SSGIPlugin.d.ts.map +1 -1
  27. package/dist/plugins/postprocessing/SSReflectionPlugin.d.ts.map +1 -1
  28. package/dist/plugins/postprocessing/TemporalAAPlugin.d.ts +14 -0
  29. package/dist/plugins/postprocessing/TemporalAAPlugin.d.ts.map +1 -1
  30. package/dist/utils/FSShadowMaterial.d.ts.map +1 -1
  31. package/dist/utils/RandomizedDirectionalLight.d.ts.map +1 -1
  32. package/dist/utils/Reflector2.d.ts +4 -4
  33. package/dist/utils/Reflector2.d.ts.map +1 -1
  34. package/dist/utils/ShadowMapBaker.d.ts +1 -1
  35. package/dist/utils/ShadowMapBaker.d.ts.map +1 -1
  36. package/docs/.nojekyll +1 -0
  37. package/docs/assets/highlight.css +1 -1
  38. package/docs/assets/icons.js +1 -1
  39. package/docs/assets/icons.svg +1 -1
  40. package/docs/assets/main.js +4 -4
  41. package/docs/assets/search.js +1 -1
  42. package/docs/assets/style.css +18 -3
  43. package/docs/classes/AdvancedGroundPlugin.html +678 -11
  44. package/docs/classes/AnisotropyPlugin.html +400 -8
  45. package/docs/classes/BloomPlugin.html +436 -7
  46. package/docs/classes/BloomPluginPass.html +301 -12
  47. package/docs/classes/DepthOfFieldPlugin.html +459 -7
  48. package/docs/classes/DepthOfFieldPluginPass.html +315 -12
  49. package/docs/classes/OutlinePlugin.html +632 -11
  50. package/docs/classes/OutlineRenderPass.html +239 -12
  51. package/docs/classes/SSContactShadowsPlugin.html +390 -6
  52. package/docs/classes/SSGIPlugin.html +454 -8
  53. package/docs/classes/SSGIPluginPass.html +372 -12
  54. package/docs/classes/SSReflectionPlugin.html +460 -8
  55. package/docs/classes/SSReflectionPluginPass.html +377 -12
  56. package/docs/classes/SSVelocityMaterial.html +123 -5
  57. package/docs/classes/TemporalAAPlugin.html +418 -8
  58. package/docs/classes/TemporalAAPluginPass.html +357 -13
  59. package/docs/classes/VelocityBufferPlugin.html +466 -7
  60. package/docs/classes/WatchHandsPlugin.html +410 -6
  61. package/docs/hierarchy.html +28 -1
  62. package/docs/index.html +38 -1
  63. package/docs/types/OutlinePluginPass.html +32 -1
  64. package/docs/types/OutlinePluginTarget.html +32 -1
  65. package/docs/types/SSGIPluginTarget.html +32 -1
  66. package/docs/types/SSReflectionPluginTarget.html +32 -1
  67. package/docs/types/VelocityBufferPluginPass.html +32 -1
  68. package/docs/types/VelocityBufferPluginTarget.html +32 -1
  69. package/docs/variables/anisotropyGLTFExtension.html +43 -1
  70. package/docs/variables/webgiPlugins.html +32 -1
  71. package/package.json +6 -3
  72. package/src/plugins/buffer/VelocityBufferPlugin.ts +119 -8
  73. package/src/plugins/buffer/shaders/VelocityBufferPlugin.mat.frag.glsl +9 -1
  74. package/src/plugins/buffer/shaders/VelocityBufferPlugin.mat.vert.glsl +14 -1
  75. package/src/plugins/extras/AnisotropyPlugin.ts +2 -2
  76. package/src/plugins/postprocessing/BloomPlugin.ts +5 -2
  77. package/src/plugins/postprocessing/DepthOfFieldPlugin.ts +3 -3
  78. package/src/plugins/postprocessing/OutlinePlugin.ts +53 -38
  79. package/src/plugins/postprocessing/SSContactShadowsPlugin.ts +1 -1
  80. package/src/plugins/postprocessing/TemporalAAPlugin.ts +42 -0
  81. package/src/utils/shaders/temporalaa.glsl +9 -0
  82. package/tsconfig.json +2 -1
@@ -324,15 +324,15 @@ export class DepthOfFieldPluginPass<Tid extends IPassID> extends ExtendedShaderP
324
324
  public dofBlurMaterial: ExtendedShaderMaterial = dofBlurMaterialPoisson
325
325
  // public dofBlurMaterialBox: ShaderMaterialEncodingSupport = dofBlurMaterialBox
326
326
 
327
- @bindToValue({obj: 'focalDepthRange', key: 'y'})
327
+ @bindToValue({obj: 'focalDepthRange', key: 'y', onChange: 'setDirty'})
328
328
  @uiSlider('Depth Range', [0.25, 3])
329
329
  depthRange: number
330
330
 
331
- @bindToValue({obj: 'nearFarBlurScale', key: 'x'})
331
+ @bindToValue({obj: 'nearFarBlurScale', key: 'x', onChange: 'setDirty'})
332
332
  @uiSlider('Near Blur Scale', [0, 1])
333
333
  nearBlurScale: number
334
334
 
335
- @bindToValue({obj: 'nearFarBlurScale', key: 'y'})
335
+ @bindToValue({obj: 'nearFarBlurScale', key: 'y', onChange: 'setDirty'})
336
336
  @uiSlider('Far Blur Scale', [0, 1])
337
337
  farBlurScale: number
338
338
 
@@ -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
 
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "baseUrl": "./src",
3
+ "strict": false,
4
+ "types": ["*"],
4
5
  "rootDir": "./src",
5
6
  "allowJs": true,
6
7
  "checkJs": false,