@nodetool-ai/timeline 0.8.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.
- package/README.md +55 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/animation/bakedAnimation.d.ts +84 -0
- package/dist/animation/bakedAnimation.d.ts.map +1 -0
- package/dist/animation/bakedAnimation.js +95 -0
- package/dist/animation/bakedAnimation.js.map +1 -0
- package/dist/animation/beat.d.ts +7 -0
- package/dist/animation/beat.d.ts.map +1 -0
- package/dist/animation/beat.js +36 -0
- package/dist/animation/beat.js.map +1 -0
- package/dist/animation/compile.d.ts +184 -0
- package/dist/animation/compile.d.ts.map +1 -0
- package/dist/animation/compile.js +312 -0
- package/dist/animation/compile.js.map +1 -0
- package/dist/animation/custom.d.ts +183 -0
- package/dist/animation/custom.d.ts.map +1 -0
- package/dist/animation/custom.js +583 -0
- package/dist/animation/custom.js.map +1 -0
- package/dist/animation/easing.d.ts +34 -0
- package/dist/animation/easing.d.ts.map +1 -0
- package/dist/animation/easing.js +332 -0
- package/dist/animation/easing.js.map +1 -0
- package/dist/animation/index.d.ts +20 -0
- package/dist/animation/index.d.ts.map +1 -0
- package/dist/animation/index.js +20 -0
- package/dist/animation/index.js.map +1 -0
- package/dist/animation/links.d.ts +33 -0
- package/dist/animation/links.d.ts.map +1 -0
- package/dist/animation/links.js +126 -0
- package/dist/animation/links.js.map +1 -0
- package/dist/animation/presets.d.ts +86 -0
- package/dist/animation/presets.d.ts.map +1 -0
- package/dist/animation/presets.js +642 -0
- package/dist/animation/presets.js.map +1 -0
- package/dist/animation/sample.d.ts +145 -0
- package/dist/animation/sample.d.ts.map +1 -0
- package/dist/animation/sample.js +390 -0
- package/dist/animation/sample.js.map +1 -0
- package/dist/animation/simplify.d.ts +70 -0
- package/dist/animation/simplify.d.ts.map +1 -0
- package/dist/animation/simplify.js +278 -0
- package/dist/animation/simplify.js.map +1 -0
- package/dist/animation/sourceCurves.d.ts +45 -0
- package/dist/animation/sourceCurves.d.ts.map +1 -0
- package/dist/animation/sourceCurves.js +168 -0
- package/dist/animation/sourceCurves.js.map +1 -0
- package/dist/animation/styleTracks.d.ts +23 -0
- package/dist/animation/styleTracks.d.ts.map +1 -0
- package/dist/animation/styleTracks.js +341 -0
- package/dist/animation/styleTracks.js.map +1 -0
- package/dist/animation/types.d.ts +269 -0
- package/dist/animation/types.d.ts.map +1 -0
- package/dist/animation/types.js +173 -0
- package/dist/animation/types.js.map +1 -0
- package/dist/animation/typewriter.d.ts +8 -0
- package/dist/animation/typewriter.d.ts.map +1 -0
- package/dist/animation/typewriter.js +32 -0
- package/dist/animation/typewriter.js.map +1 -0
- package/dist/audioFade.d.ts +73 -0
- package/dist/audioFade.d.ts.map +1 -0
- package/dist/audioFade.js +134 -0
- package/dist/audioFade.js.map +1 -0
- package/dist/authoredStyles.d.ts +61 -0
- package/dist/authoredStyles.d.ts.map +1 -0
- package/dist/authoredStyles.js +90 -0
- package/dist/authoredStyles.js.map +1 -0
- package/dist/authoring.d.ts +50 -0
- package/dist/authoring.d.ts.map +1 -0
- package/dist/authoring.js +207 -0
- package/dist/authoring.js.map +1 -0
- package/dist/beats.d.ts +103 -0
- package/dist/beats.d.ts.map +1 -0
- package/dist/beats.js +228 -0
- package/dist/beats.js.map +1 -0
- package/dist/clone.d.ts +32 -0
- package/dist/clone.d.ts.map +1 -0
- package/dist/clone.js +53 -0
- package/dist/clone.js.map +1 -0
- package/dist/composition.d.ts +87 -0
- package/dist/composition.d.ts.map +1 -0
- package/dist/composition.js +253 -0
- package/dist/composition.js.map +1 -0
- package/dist/crop.d.ts +48 -0
- package/dist/crop.d.ts.map +1 -0
- package/dist/crop.js +75 -0
- package/dist/crop.js.map +1 -0
- package/dist/defaults.d.ts +142 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +335 -0
- package/dist/defaults.js.map +1 -0
- package/dist/dependencyHash.d.ts +14 -0
- package/dist/dependencyHash.d.ts.map +1 -0
- package/dist/dependencyHash.js +19 -0
- package/dist/dependencyHash.js.map +1 -0
- package/dist/dropResolve.d.ts +40 -0
- package/dist/dropResolve.d.ts.map +1 -0
- package/dist/dropResolve.js +137 -0
- package/dist/dropResolve.js.map +1 -0
- package/dist/examples/node.d.ts +11 -0
- package/dist/examples/node.d.ts.map +1 -0
- package/dist/examples/node.js +87 -0
- package/dist/examples/node.js.map +1 -0
- package/dist/extension.d.ts +52 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/extension.js +269 -0
- package/dist/extension.js.map +1 -0
- package/dist/extensionRequest.d.ts +40 -0
- package/dist/extensionRequest.d.ts.map +1 -0
- package/dist/extensionRequest.js +135 -0
- package/dist/extensionRequest.js.map +1 -0
- package/dist/fill-text.d.ts +30 -0
- package/dist/fill-text.d.ts.map +1 -0
- package/dist/fill-text.js +73 -0
- package/dist/fill-text.js.map +1 -0
- package/dist/fonts/catalog.d.ts +97 -0
- package/dist/fonts/catalog.d.ts.map +1 -0
- package/dist/fonts/catalog.js +276 -0
- package/dist/fonts/catalog.js.map +1 -0
- package/dist/fonts/css.d.ts +24 -0
- package/dist/fonts/css.d.ts.map +1 -0
- package/dist/fonts/css.js +50 -0
- package/dist/fonts/css.js.map +1 -0
- package/dist/fonts/index.d.ts +10 -0
- package/dist/fonts/index.d.ts.map +1 -0
- package/dist/fonts/index.js +10 -0
- package/dist/fonts/index.js.map +1 -0
- package/dist/fonts/register-node.d.ts +45 -0
- package/dist/fonts/register-node.d.ts.map +1 -0
- package/dist/fonts/register-node.js +71 -0
- package/dist/fonts/register-node.js.map +1 -0
- package/dist/generatedMatte.d.ts +86 -0
- package/dist/generatedMatte.d.ts.map +1 -0
- package/dist/generatedMatte.js +152 -0
- package/dist/generatedMatte.js.map +1 -0
- package/dist/generative.d.ts +145 -0
- package/dist/generative.d.ts.map +1 -0
- package/dist/generative.js +396 -0
- package/dist/generative.js.map +1 -0
- package/dist/group.d.ts +47 -0
- package/dist/group.d.ts.map +1 -0
- package/dist/group.js +131 -0
- package/dist/group.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/interchange.d.ts +47 -0
- package/dist/interchange.d.ts.map +1 -0
- package/dist/interchange.js +158 -0
- package/dist/interchange.js.map +1 -0
- package/dist/keyframes.d.ts +44 -0
- package/dist/keyframes.d.ts.map +1 -0
- package/dist/keyframes.js +148 -0
- package/dist/keyframes.js.map +1 -0
- package/dist/lineDelivery.d.ts +108 -0
- package/dist/lineDelivery.d.ts.map +1 -0
- package/dist/lineDelivery.js +154 -0
- package/dist/lineDelivery.js.map +1 -0
- package/dist/linked.d.ts +41 -0
- package/dist/linked.d.ts.map +1 -0
- package/dist/linked.js +166 -0
- package/dist/linked.js.map +1 -0
- package/dist/lipSyncRequest.d.ts +65 -0
- package/dist/lipSyncRequest.d.ts.map +1 -0
- package/dist/lipSyncRequest.js +73 -0
- package/dist/lipSyncRequest.js.map +1 -0
- package/dist/measureClipDurations.d.ts +7 -0
- package/dist/measureClipDurations.d.ts.map +1 -0
- package/dist/measureClipDurations.js +17 -0
- package/dist/measureClipDurations.js.map +1 -0
- package/dist/mediaTrack.d.ts +120 -0
- package/dist/mediaTrack.d.ts.map +1 -0
- package/dist/mediaTrack.js +269 -0
- package/dist/mediaTrack.js.map +1 -0
- package/dist/midi/cacheKey.d.ts +25 -0
- package/dist/midi/cacheKey.d.ts.map +1 -0
- package/dist/midi/cacheKey.js +54 -0
- package/dist/midi/cacheKey.js.map +1 -0
- package/dist/midi/edit.d.ts +48 -0
- package/dist/midi/edit.d.ts.map +1 -0
- package/dist/midi/edit.js +93 -0
- package/dist/midi/edit.js.map +1 -0
- package/dist/midi/engines/bl1.d.ts +29 -0
- package/dist/midi/engines/bl1.d.ts.map +1 -0
- package/dist/midi/engines/bl1.js +128 -0
- package/dist/midi/engines/bl1.js.map +1 -0
- package/dist/midi/engines/dr1.d.ts +28 -0
- package/dist/midi/engines/dr1.d.ts.map +1 -0
- package/dist/midi/engines/dr1.js +101 -0
- package/dist/midi/engines/dr1.js.map +1 -0
- package/dist/midi/engines/dsp.d.ts +126 -0
- package/dist/midi/engines/dsp.d.ts.map +1 -0
- package/dist/midi/engines/dsp.js +371 -0
- package/dist/midi/engines/dsp.js.map +1 -0
- package/dist/midi/engines/index.d.ts +13 -0
- package/dist/midi/engines/index.d.ts.map +1 -0
- package/dist/midi/engines/index.js +13 -0
- package/dist/midi/engines/index.js.map +1 -0
- package/dist/midi/engines/kits.d.ts +12 -0
- package/dist/midi/engines/kits.d.ts.map +1 -0
- package/dist/midi/engines/kits.js +121 -0
- package/dist/midi/engines/kits.js.map +1 -0
- package/dist/midi/engines/wavetables.d.ts +45 -0
- package/dist/midi/engines/wavetables.d.ts.map +1 -0
- package/dist/midi/engines/wavetables.js +334 -0
- package/dist/midi/engines/wavetables.js.map +1 -0
- package/dist/midi/engines/wt1.d.ts +30 -0
- package/dist/midi/engines/wt1.d.ts.map +1 -0
- package/dist/midi/engines/wt1.js +91 -0
- package/dist/midi/engines/wt1.js.map +1 -0
- package/dist/midi/grid.d.ts +51 -0
- package/dist/midi/grid.d.ts.map +1 -0
- package/dist/midi/grid.js +104 -0
- package/dist/midi/grid.js.map +1 -0
- package/dist/midi/index.d.ts +20 -0
- package/dist/midi/index.d.ts.map +1 -0
- package/dist/midi/index.js +20 -0
- package/dist/midi/index.js.map +1 -0
- package/dist/midi/instrument.d.ts +32 -0
- package/dist/midi/instrument.d.ts.map +1 -0
- package/dist/midi/instrument.js +73 -0
- package/dist/midi/instrument.js.map +1 -0
- package/dist/midi/notes.d.ts +46 -0
- package/dist/midi/notes.d.ts.map +1 -0
- package/dist/midi/notes.js +121 -0
- package/dist/midi/notes.js.map +1 -0
- package/dist/midi/notesEdit.d.ts +94 -0
- package/dist/midi/notesEdit.d.ts.map +1 -0
- package/dist/midi/notesEdit.js +159 -0
- package/dist/midi/notesEdit.js.map +1 -0
- package/dist/midi/presets.d.ts +29 -0
- package/dist/midi/presets.d.ts.map +1 -0
- package/dist/midi/presets.js +281 -0
- package/dist/midi/presets.js.map +1 -0
- package/dist/midi/tempo.d.ts +27 -0
- package/dist/midi/tempo.d.ts.map +1 -0
- package/dist/midi/tempo.js +57 -0
- package/dist/midi/tempo.js.map +1 -0
- package/dist/midi/ticks.d.ts +25 -0
- package/dist/midi/ticks.d.ts.map +1 -0
- package/dist/midi/ticks.js +35 -0
- package/dist/midi/ticks.js.map +1 -0
- package/dist/midi/voice.d.ts +148 -0
- package/dist/midi/voice.d.ts.map +1 -0
- package/dist/midi/voice.js +348 -0
- package/dist/midi/voice.js.map +1 -0
- package/dist/midi/wav.d.ts +14 -0
- package/dist/midi/wav.d.ts.map +1 -0
- package/dist/midi/wav.js +51 -0
- package/dist/midi/wav.js.map +1 -0
- package/dist/model3d.d.ts +41 -0
- package/dist/model3d.d.ts.map +1 -0
- package/dist/model3d.js +39 -0
- package/dist/model3d.js.map +1 -0
- package/dist/model3dBake.d.ts +80 -0
- package/dist/model3dBake.d.ts.map +1 -0
- package/dist/model3dBake.js +127 -0
- package/dist/model3dBake.js.map +1 -0
- package/dist/ops/apply.d.ts +32 -0
- package/dist/ops/apply.d.ts.map +1 -0
- package/dist/ops/apply.js +1595 -0
- package/dist/ops/apply.js.map +1 -0
- package/dist/ops/index.d.ts +13 -0
- package/dist/ops/index.d.ts.map +1 -0
- package/dist/ops/index.js +13 -0
- package/dist/ops/index.js.map +1 -0
- package/dist/ops/op.d.ts +407 -0
- package/dist/ops/op.d.ts.map +1 -0
- package/dist/ops/op.js +61 -0
- package/dist/ops/op.js.map +1 -0
- package/dist/ops/serialize.d.ts +77 -0
- package/dist/ops/serialize.d.ts.map +1 -0
- package/dist/ops/serialize.js +81 -0
- package/dist/ops/serialize.js.map +1 -0
- package/dist/ops/types.d.ts +150 -0
- package/dist/ops/types.d.ts.map +1 -0
- package/dist/ops/types.js +12 -0
- package/dist/ops/types.js.map +1 -0
- package/dist/pathSampling.d.ts +51 -0
- package/dist/pathSampling.d.ts.map +1 -0
- package/dist/pathSampling.js +111 -0
- package/dist/pathSampling.js.map +1 -0
- package/dist/placement/index.d.ts +2 -0
- package/dist/placement/index.d.ts.map +1 -0
- package/dist/placement/index.js +2 -0
- package/dist/placement/index.js.map +1 -0
- package/dist/placement/resolveTrackPlacement.d.ts +40 -0
- package/dist/placement/resolveTrackPlacement.d.ts.map +1 -0
- package/dist/placement/resolveTrackPlacement.js +71 -0
- package/dist/placement/resolveTrackPlacement.js.map +1 -0
- package/dist/production.d.ts +99 -0
- package/dist/production.d.ts.map +1 -0
- package/dist/production.js +328 -0
- package/dist/production.js.map +1 -0
- package/dist/reassemble.d.ts +68 -0
- package/dist/reassemble.d.ts.map +1 -0
- package/dist/reassemble.js +187 -0
- package/dist/reassemble.js.map +1 -0
- package/dist/recipe.d.ts +24 -0
- package/dist/recipe.d.ts.map +1 -0
- package/dist/recipe.js +89 -0
- package/dist/recipe.js.map +1 -0
- package/dist/recordedVoiceReplacement.d.ts +70 -0
- package/dist/recordedVoiceReplacement.d.ts.map +1 -0
- package/dist/recordedVoiceReplacement.js +82 -0
- package/dist/recordedVoiceReplacement.js.map +1 -0
- package/dist/reframe.d.ts +31 -0
- package/dist/reframe.d.ts.map +1 -0
- package/dist/reframe.js +227 -0
- package/dist/reframe.js.map +1 -0
- package/dist/render/canvas2d.d.ts +419 -0
- package/dist/render/canvas2d.d.ts.map +1 -0
- package/dist/render/canvas2d.js +1392 -0
- package/dist/render/canvas2d.js.map +1 -0
- package/dist/render/color.d.ts +26 -0
- package/dist/render/color.d.ts.map +1 -0
- package/dist/render/color.js +305 -0
- package/dist/render/color.js.map +1 -0
- package/dist/render/cpuLegacyEffects.d.ts +17 -0
- package/dist/render/cpuLegacyEffects.d.ts.map +1 -0
- package/dist/render/cpuLegacyEffects.js +347 -0
- package/dist/render/cpuLegacyEffects.js.map +1 -0
- package/dist/render/cpuVisualEffects.d.ts +13 -0
- package/dist/render/cpuVisualEffects.d.ts.map +1 -0
- package/dist/render/cpuVisualEffects.js +388 -0
- package/dist/render/cpuVisualEffects.js.map +1 -0
- package/dist/render/cubeLut.d.ts +12 -0
- package/dist/render/cubeLut.d.ts.map +1 -0
- package/dist/render/cubeLut.js +81 -0
- package/dist/render/cubeLut.js.map +1 -0
- package/dist/render/curveFitting.d.ts +28 -0
- package/dist/render/curveFitting.d.ts.map +1 -0
- package/dist/render/curveFitting.js +94 -0
- package/dist/render/curveFitting.js.map +1 -0
- package/dist/render/draw.d.ts +265 -0
- package/dist/render/draw.d.ts.map +1 -0
- package/dist/render/draw.js +929 -0
- package/dist/render/draw.js.map +1 -0
- package/dist/render/effects.d.ts +120 -0
- package/dist/render/effects.d.ts.map +1 -0
- package/dist/render/effects.js +804 -0
- package/dist/render/effects.js.map +1 -0
- package/dist/render/frameCompositor.d.ts +502 -0
- package/dist/render/frameCompositor.d.ts.map +1 -0
- package/dist/render/frameCompositor.js +1331 -0
- package/dist/render/frameCompositor.js.map +1 -0
- package/dist/render/index.d.ts +27 -0
- package/dist/render/index.d.ts.map +1 -0
- package/dist/render/index.js +27 -0
- package/dist/render/index.js.map +1 -0
- package/dist/render/layout.d.ts +17 -0
- package/dist/render/layout.d.ts.map +1 -0
- package/dist/render/layout.js +197 -0
- package/dist/render/layout.js.map +1 -0
- package/dist/render/model3dBakeSamples.d.ts +45 -0
- package/dist/render/model3dBakeSamples.d.ts.map +1 -0
- package/dist/render/model3dBakeSamples.js +68 -0
- package/dist/render/model3dBakeSamples.js.map +1 -0
- package/dist/render/motionBlur.d.ts +170 -0
- package/dist/render/motionBlur.d.ts.map +1 -0
- package/dist/render/motionBlur.js +193 -0
- package/dist/render/motionBlur.js.map +1 -0
- package/dist/render/sceneModel.d.ts +577 -0
- package/dist/render/sceneModel.d.ts.map +1 -0
- package/dist/render/sceneModel.js +1460 -0
- package/dist/render/sceneModel.js.map +1 -0
- package/dist/render/shapeGeometry.d.ts +81 -0
- package/dist/render/shapeGeometry.d.ts.map +1 -0
- package/dist/render/shapeGeometry.js +460 -0
- package/dist/render/shapeGeometry.js.map +1 -0
- package/dist/render/spatial.d.ts +9 -0
- package/dist/render/spatial.d.ts.map +1 -0
- package/dist/render/spatial.js +58 -0
- package/dist/render/spatial.js.map +1 -0
- package/dist/render/svgPath.d.ts +80 -0
- package/dist/render/svgPath.d.ts.map +1 -0
- package/dist/render/svgPath.js +199 -0
- package/dist/render/svgPath.js.map +1 -0
- package/dist/render/temporal.d.ts +6 -0
- package/dist/render/temporal.d.ts.map +1 -0
- package/dist/render/temporal.js +74 -0
- package/dist/render/temporal.js.map +1 -0
- package/dist/render/textLayout.d.ts +159 -0
- package/dist/render/textLayout.d.ts.map +1 -0
- package/dist/render/textLayout.js +301 -0
- package/dist/render/textLayout.js.map +1 -0
- package/dist/render/trackEffects.d.ts +23 -0
- package/dist/render/trackEffects.d.ts.map +1 -0
- package/dist/render/trackEffects.js +93 -0
- package/dist/render/trackEffects.js.map +1 -0
- package/dist/render/transform.d.ts +54 -0
- package/dist/render/transform.d.ts.map +1 -0
- package/dist/render/transform.js +222 -0
- package/dist/render/transform.js.map +1 -0
- package/dist/render/transition.d.ts +109 -0
- package/dist/render/transition.d.ts.map +1 -0
- package/dist/render/transition.js +351 -0
- package/dist/render/transition.js.map +1 -0
- package/dist/retarget.d.ts +73 -0
- package/dist/retarget.d.ts.map +1 -0
- package/dist/retarget.js +305 -0
- package/dist/retarget.js.map +1 -0
- package/dist/rippleEdit.d.ts +83 -0
- package/dist/rippleEdit.d.ts.map +1 -0
- package/dist/rippleEdit.js +184 -0
- package/dist/rippleEdit.js.map +1 -0
- package/dist/scene.d.ts +28 -0
- package/dist/scene.d.ts.map +1 -0
- package/dist/scene.js +28 -0
- package/dist/scene.js.map +1 -0
- package/dist/script-link.d.ts +52 -0
- package/dist/script-link.d.ts.map +1 -0
- package/dist/script-link.js +78 -0
- package/dist/script-link.js.map +1 -0
- package/dist/script.d.ts +52 -0
- package/dist/script.d.ts.map +1 -0
- package/dist/script.js +93 -0
- package/dist/script.js.map +1 -0
- package/dist/snap.d.ts +2 -0
- package/dist/snap.d.ts.map +1 -0
- package/dist/snap.js +21 -0
- package/dist/snap.js.map +1 -0
- package/dist/snapping/buildSnapPoints.d.ts +16 -0
- package/dist/snapping/buildSnapPoints.d.ts.map +1 -0
- package/dist/snapping/buildSnapPoints.js +39 -0
- package/dist/snapping/buildSnapPoints.js.map +1 -0
- package/dist/snapping/index.d.ts +3 -0
- package/dist/snapping/index.d.ts.map +1 -0
- package/dist/snapping/index.js +3 -0
- package/dist/snapping/index.js.map +1 -0
- package/dist/snapping/resolveSnap.d.ts +19 -0
- package/dist/snapping/resolveSnap.d.ts.map +1 -0
- package/dist/snapping/resolveSnap.js +39 -0
- package/dist/snapping/resolveSnap.js.map +1 -0
- package/dist/sourceRate.d.ts +12 -0
- package/dist/sourceRate.d.ts.map +1 -0
- package/dist/sourceRate.js +13 -0
- package/dist/sourceRate.js.map +1 -0
- package/dist/spatialVideoRequest.d.ts +91 -0
- package/dist/spatialVideoRequest.d.ts.map +1 -0
- package/dist/spatialVideoRequest.js +175 -0
- package/dist/spatialVideoRequest.js.map +1 -0
- package/dist/splitClip.d.ts +3 -0
- package/dist/splitClip.d.ts.map +1 -0
- package/dist/splitClip.js +190 -0
- package/dist/splitClip.js.map +1 -0
- package/dist/stableSerialize.d.ts +11 -0
- package/dist/stableSerialize.d.ts.map +1 -0
- package/dist/stableSerialize.js +31 -0
- package/dist/stableSerialize.js.map +1 -0
- package/dist/staleSet.d.ts +41 -0
- package/dist/staleSet.d.ts.map +1 -0
- package/dist/staleSet.js +106 -0
- package/dist/staleSet.js.map +1 -0
- package/dist/storyboard.d.ts +221 -0
- package/dist/storyboard.d.ts.map +1 -0
- package/dist/storyboard.js +417 -0
- package/dist/storyboard.js.map +1 -0
- package/dist/subtitles.d.ts +61 -0
- package/dist/subtitles.d.ts.map +1 -0
- package/dist/subtitles.js +92 -0
- package/dist/subtitles.js.map +1 -0
- package/dist/takes.d.ts +76 -0
- package/dist/takes.d.ts.map +1 -0
- package/dist/takes.js +238 -0
- package/dist/takes.js.map +1 -0
- package/dist/timeRemap.d.ts +101 -0
- package/dist/timeRemap.d.ts.map +1 -0
- package/dist/timeRemap.js +183 -0
- package/dist/timeRemap.js.map +1 -0
- package/dist/trackOrder.d.ts +38 -0
- package/dist/trackOrder.d.ts.map +1 -0
- package/dist/trackOrder.js +54 -0
- package/dist/trackOrder.js.map +1 -0
- package/dist/transitionAtCut.d.ts +89 -0
- package/dist/transitionAtCut.d.ts.map +1 -0
- package/dist/transitionAtCut.js +217 -0
- package/dist/transitionAtCut.js.map +1 -0
- package/dist/trimClip.d.ts +13 -0
- package/dist/trimClip.d.ts.map +1 -0
- package/dist/trimClip.js +60 -0
- package/dist/trimClip.js.map +1 -0
- package/dist/types.d.ts +1772 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +84 -0
- package/dist/types.js.map +1 -0
- package/fonts/BebasNeue-Regular.ttf +0 -0
- package/fonts/Inter-ExtraBold.ttf +0 -0
- package/fonts/Inter-Italic-Variable.ttf +0 -0
- package/fonts/Inter-SemiBold.ttf +0 -0
- package/fonts/Inter-Variable.ttf +0 -0
- package/fonts/JetBrainsMono-Italic-Variable.ttf +0 -0
- package/fonts/JetBrainsMono-Variable.ttf +0 -0
- package/fonts/Lora-Italic-Variable.ttf +0 -0
- package/fonts/Lora-Variable.ttf +0 -0
- package/fonts/OFL-BebasNeue.txt +93 -0
- package/fonts/OFL-Inter.txt +93 -0
- package/fonts/OFL-JetBrainsMono.txt +93 -0
- package/fonts/OFL-Lora.txt +93 -0
- package/fonts/OFL-PlayfairDisplay.txt +93 -0
- package/fonts/OFL-SpaceGrotesk.txt +93 -0
- package/fonts/PlayfairDisplay-Italic-Variable.ttf +0 -0
- package/fonts/PlayfairDisplay-Variable.ttf +0 -0
- package/fonts/SpaceGrotesk-Variable.ttf +0 -0
- package/package.json +108 -0
|
@@ -0,0 +1,1331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The WebGPU compositing rules every timeline render surface draws through.
|
|
3
|
+
*
|
|
4
|
+
* {@link GpuFrameCompositor} is the whole of it: placement, the effects
|
|
5
|
+
* pre-pass, shape masks, track mattes, transition geometry, the dip solid, and
|
|
6
|
+
* the precomposite pass that lets a group's effects and blend mode act on its
|
|
7
|
+
* children together. It is generic in what a layer's pixels arrive as, because
|
|
8
|
+
* that is the only thing its two hosts disagree about — the server hands it CPU
|
|
9
|
+
* RGBA buffers, the editor hands it `<video>` elements and `ImageBitmap`s — and
|
|
10
|
+
* a rule that lived in both would drift, which is exactly what happened while
|
|
11
|
+
* the browser kept a compositor of its own.
|
|
12
|
+
*
|
|
13
|
+
* {@link HeadlessFrameCompositor} is the server host: CPU pixels in, one
|
|
14
|
+
* frame's RGBA read back out. The editor's host lives in `web/` and differs
|
|
15
|
+
* only in uploading through `copyExternalImageToTexture` and presenting to a
|
|
16
|
+
* swap chain instead of a buffer.
|
|
17
|
+
*
|
|
18
|
+
* An instance is reused across every frame of a render: source textures are
|
|
19
|
+
* kept per layer id (re-uploaded only when their pixels change), the
|
|
20
|
+
* precomposite textures per group id, and the readback buffer is allocated
|
|
21
|
+
* once. Everything the GPU holds is owned by the instance and released in
|
|
22
|
+
* `dispose`, so a throw mid-frame leaks nothing.
|
|
23
|
+
*/
|
|
24
|
+
import { blendModeGpuId } from "@nodetool-ai/gpu";
|
|
25
|
+
import { BLIT_FRAGMENT, FULLSCREEN_QUAD_VERTEX, UNPREMULTIPLY_FRAGMENT, WebGPULayerCompositor, forwardClipMatrixToInverseAffine, invertClipPlacement } from "@nodetool-ai/gpu/webgpu";
|
|
26
|
+
import { cropRectPx, hasCrop } from "../crop.js";
|
|
27
|
+
import { parseCssColorOrBlack } from "./color.js";
|
|
28
|
+
import { WebGPUEffectsProcessor } from "./effects.js";
|
|
29
|
+
import { IDENTITY_TRANSFORM, buildTransformMatrix, containBaseScale } from "./transform.js";
|
|
30
|
+
import { transitionTransform } from "./transition.js";
|
|
31
|
+
/** Shader edge codes (see `BLEND_COMPOSITE_FRAGMENT` params2). */
|
|
32
|
+
const WIPE_EDGE = {
|
|
33
|
+
left: 1,
|
|
34
|
+
right: 2,
|
|
35
|
+
up: 3, // reveal from the layer's top edge
|
|
36
|
+
down: 4 // reveal from the layer's bottom edge
|
|
37
|
+
};
|
|
38
|
+
/** Two `vec4f` of mix parameters — see {@link TREATMENT_MIX_FRAGMENT}. */
|
|
39
|
+
const MIX_UNIFORM_BYTES = 32;
|
|
40
|
+
/**
|
|
41
|
+
* Mix an adjustment's treated copy into the accumulation it was taken from, by
|
|
42
|
+
* the treatment's coverage: `mix(accumulation, treated, c)` per premultiplied
|
|
43
|
+
* channel, alpha included.
|
|
44
|
+
*
|
|
45
|
+
* Both textures are frame-sized and land 1:1, so there is no placement to
|
|
46
|
+
* invert — the coverage raster is the one input that can arrive at another
|
|
47
|
+
* size, and it is read at the same normalized point.
|
|
48
|
+
*
|
|
49
|
+
* The wipe is the same profile `BLEND_COMPOSITE_FRAGMENT` evaluates, at the
|
|
50
|
+
* same front position `e = progress * (1 + softness)` and off the same edge
|
|
51
|
+
* codes, because a treatment's wipe and a layer's have to clear the frame at
|
|
52
|
+
* the same progress. It is evaluated here rather than there because the blend
|
|
53
|
+
* shader carries it on a *source alpha*, and a treatment's coverage is not one.
|
|
54
|
+
*/
|
|
55
|
+
const TREATMENT_MIX_FRAGMENT = /* wgsl */ `
|
|
56
|
+
struct MixUniforms {
|
|
57
|
+
// opacity, hasCoverage, wipeEdge, wipeProgress
|
|
58
|
+
params0: vec4f,
|
|
59
|
+
// wipeSoftness, _, _, _
|
|
60
|
+
params1: vec4f,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
@group(0) @binding(0) var<uniform> u: MixUniforms;
|
|
64
|
+
@group(0) @binding(1) var accTexture: texture_2d<f32>;
|
|
65
|
+
@group(0) @binding(2) var treatedTexture: texture_2d<f32>;
|
|
66
|
+
@group(0) @binding(3) var coverageTexture: texture_2d<f32>;
|
|
67
|
+
|
|
68
|
+
fn loadAt(dims: vec2u, uv: vec2f) -> vec2i {
|
|
69
|
+
return vec2i(
|
|
70
|
+
i32(clamp(floor(uv.x * f32(dims.x)), 0.0, f32(dims.x) - 1.0)),
|
|
71
|
+
i32(clamp(floor(uv.y * f32(dims.y)), 0.0, f32(dims.y) - 1.0))
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@fragment
|
|
76
|
+
fn fs_mix(@location(0) uv: vec2f) -> @location(0) vec4f {
|
|
77
|
+
let acc = textureLoad(accTexture, loadAt(textureDimensions(accTexture), uv), 0);
|
|
78
|
+
let treated = textureLoad(
|
|
79
|
+
treatedTexture, loadAt(textureDimensions(treatedTexture), uv), 0
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
var c = u.params0.x;
|
|
83
|
+
if (u.params0.y > 0.5) {
|
|
84
|
+
// The raster carries its coverage in alpha, as every mask upload does.
|
|
85
|
+
let cov = textureLoad(
|
|
86
|
+
coverageTexture, loadAt(textureDimensions(coverageTexture), uv), 0
|
|
87
|
+
);
|
|
88
|
+
c = c * cov.a;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let wipeEdge = u32(u.params0.z);
|
|
92
|
+
if (wipeEdge != 0u) {
|
|
93
|
+
let progress = u.params0.w;
|
|
94
|
+
// A tiny floor keeps smoothstep well-defined; softness 0 stays visually a
|
|
95
|
+
// hard (sub-texel) edge.
|
|
96
|
+
let softness = max(u.params1.x, 1e-4);
|
|
97
|
+
var d = uv.x; // 1u: reveal from the left edge
|
|
98
|
+
if (wipeEdge == 2u) {
|
|
99
|
+
d = 1.0 - uv.x; // from the right edge
|
|
100
|
+
} else if (wipeEdge == 3u) {
|
|
101
|
+
d = uv.y; // from the top edge (row 0)
|
|
102
|
+
} else if (wipeEdge == 4u) {
|
|
103
|
+
d = 1.0 - uv.y; // from the bottom edge
|
|
104
|
+
}
|
|
105
|
+
let e = progress * (1.0 + softness);
|
|
106
|
+
c = c * (1.0 - smoothstep(e - softness, e, d));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return mix(acc, treated, clamp(c, 0.0, 1.0));
|
|
110
|
+
}
|
|
111
|
+
`;
|
|
112
|
+
function wipeParams(mask) {
|
|
113
|
+
if (!mask)
|
|
114
|
+
return undefined;
|
|
115
|
+
return {
|
|
116
|
+
edge: WIPE_EDGE[mask.direction],
|
|
117
|
+
progress: mask.progress,
|
|
118
|
+
softness: mask.softness
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
const isAdjustment = (item) => "kind" in item;
|
|
122
|
+
/**
|
|
123
|
+
* Bottom-up composite order.
|
|
124
|
+
*
|
|
125
|
+
* The sort is stable and the callers push in a deliberate order at equal z: a
|
|
126
|
+
* dip solid before the clip it dips into, an adjustment after the layers it
|
|
127
|
+
* treats, a group's surface at the group's own track rather than on top of
|
|
128
|
+
* everything.
|
|
129
|
+
*/
|
|
130
|
+
const sortStack = (items) => items.sort((a, b) => {
|
|
131
|
+
const z = a.zIndex - b.zIndex;
|
|
132
|
+
if (z !== 0)
|
|
133
|
+
return z;
|
|
134
|
+
const first = "stackOrder" in a ? a.stackOrder : undefined;
|
|
135
|
+
const second = "stackOrder" in b ? b.stackOrder : undefined;
|
|
136
|
+
if (first === second)
|
|
137
|
+
return 0;
|
|
138
|
+
return (first ?? Number.POSITIVE_INFINITY) - (second ?? Number.POSITIVE_INFINITY);
|
|
139
|
+
});
|
|
140
|
+
const TEXTURE_FORMAT = "rgba8unorm";
|
|
141
|
+
export class GpuFrameCompositor {
|
|
142
|
+
device;
|
|
143
|
+
core;
|
|
144
|
+
effects;
|
|
145
|
+
label;
|
|
146
|
+
upload;
|
|
147
|
+
retainSources;
|
|
148
|
+
width;
|
|
149
|
+
height;
|
|
150
|
+
/**
|
|
151
|
+
* The sequence's own resolution — the space `transform.position` and a
|
|
152
|
+
* transition's frame-relative offset are expressed in. Equal to the frame
|
|
153
|
+
* size unless a host says otherwise, which the editor does because its canvas
|
|
154
|
+
* tracks the viewport and the device pixel ratio.
|
|
155
|
+
*/
|
|
156
|
+
refWidth = 0;
|
|
157
|
+
refHeight = 0;
|
|
158
|
+
/**
|
|
159
|
+
* The second compositor pass, built on the first frame that carries a
|
|
160
|
+
* precompositing group and never at all for a document without one. Its own
|
|
161
|
+
* ping-pong pair is what keeps a group's children off the main accumulation.
|
|
162
|
+
*/
|
|
163
|
+
precompCore = null;
|
|
164
|
+
/** One finished, straight-alpha surface per precompositing group, by id. */
|
|
165
|
+
precompTargets = new Map();
|
|
166
|
+
/** One 1×1 texture per colour a `dipToColor` transition fades through. */
|
|
167
|
+
solids = new Map();
|
|
168
|
+
/** One cropped copy per cropped layer, by layer id — see {@link cropSource}. */
|
|
169
|
+
crops = new Map();
|
|
170
|
+
/** Resolves a premultiplied accumulation to the straight alpha the blend
|
|
171
|
+
* shader reads a source as. Built with the second pass. */
|
|
172
|
+
unpremultiply = null;
|
|
173
|
+
/** Mixes an adjustment's treated copy back into the accumulation. */
|
|
174
|
+
mix = null;
|
|
175
|
+
/** One uniform buffer per adjustment id — see {@link mixUniformBuffer}. */
|
|
176
|
+
mixUniforms = new Map();
|
|
177
|
+
constructor(device, width, height, options) {
|
|
178
|
+
this.device = device;
|
|
179
|
+
this.width = Math.max(1, Math.floor(width));
|
|
180
|
+
this.height = Math.max(1, Math.floor(height));
|
|
181
|
+
this.label = options.label ?? "timeline";
|
|
182
|
+
this.upload = options.upload;
|
|
183
|
+
this.retainSources = options.retainSources ?? (() => { });
|
|
184
|
+
this.core = new WebGPULayerCompositor(device, TEXTURE_FORMAT, "linear", this.label);
|
|
185
|
+
this.core.ensureSize(this.width, this.height);
|
|
186
|
+
this.effects = new WebGPUEffectsProcessor(device);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Change the frame size. The intermediates are frame-sized, so they are
|
|
190
|
+
* dropped and rebuilt at the new one; the host's own source textures are
|
|
191
|
+
* source-sized and unaffected.
|
|
192
|
+
*/
|
|
193
|
+
resize(width, height) {
|
|
194
|
+
const w = Math.max(1, Math.floor(width));
|
|
195
|
+
const h = Math.max(1, Math.floor(height));
|
|
196
|
+
if (w === this.width && h === this.height)
|
|
197
|
+
return;
|
|
198
|
+
this.width = w;
|
|
199
|
+
this.height = h;
|
|
200
|
+
this.core.ensureSize(w, h);
|
|
201
|
+
this.precompCore?.ensureSize(w, h);
|
|
202
|
+
for (const texture of this.precompTargets.values())
|
|
203
|
+
texture.destroy();
|
|
204
|
+
this.precompTargets.clear();
|
|
205
|
+
}
|
|
206
|
+
/** Set the sequence resolution a stored transform is expressed against. */
|
|
207
|
+
setReferenceSize(width, height) {
|
|
208
|
+
this.refWidth = width;
|
|
209
|
+
this.refHeight = height;
|
|
210
|
+
}
|
|
211
|
+
/** The reference width in force: the host's, or the frame's. */
|
|
212
|
+
get referenceWidth() {
|
|
213
|
+
return this.refWidth || this.width;
|
|
214
|
+
}
|
|
215
|
+
get referenceHeight() {
|
|
216
|
+
return this.refHeight || this.height;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Copy `from` onto `view` — how a host presents the composited frame to a
|
|
220
|
+
* swap chain it owns and this does not.
|
|
221
|
+
*/
|
|
222
|
+
blit(encoder, from, view) {
|
|
223
|
+
this.core.blit(encoder, from, view);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Composite `layers` over `clearValue` and return the accumulation texture
|
|
227
|
+
* holding the frame, plus how many layers actually drew.
|
|
228
|
+
*
|
|
229
|
+
* A layer naming a group in `precomposites` renders into that group's own
|
|
230
|
+
* texture first, and the texture blends once at the group's z with the
|
|
231
|
+
* group's opacity, blend mode and effect chain. With no precomposites this is
|
|
232
|
+
* the single-pass path: the second compositor is never built.
|
|
233
|
+
*
|
|
234
|
+
* An `adjustments` entry runs at its own z on the target it names — the
|
|
235
|
+
* frame's accumulation, or a group's texture — treating what has accumulated
|
|
236
|
+
* by then and blending the treated copy back over it.
|
|
237
|
+
*
|
|
238
|
+
* The work is submitted before this returns, so a host records whatever it
|
|
239
|
+
* does with the frame — a readback, a blit to a swap chain — in an encoder of
|
|
240
|
+
* its own and submits that after.
|
|
241
|
+
*/
|
|
242
|
+
composite(layers, precomposites = [], clearValue = { r: 0, g: 0, b: 0, a: 1 }, adjustments = []) {
|
|
243
|
+
const ordered = [...layers].sort((a, b) => a.zIndex - b.zIndex);
|
|
244
|
+
this.retainOnly(ordered, precomposites, adjustments);
|
|
245
|
+
const readStart = this.core.textureA;
|
|
246
|
+
const writeStart = this.core.textureB;
|
|
247
|
+
if (!readStart || !writeStart) {
|
|
248
|
+
throw new Error("Compositor failed to allocate accumulation textures");
|
|
249
|
+
}
|
|
250
|
+
// One encoder for the whole frame. Every layer's effects, every mask and
|
|
251
|
+
// matte, and every precomposite record into it, so a frame with M graded
|
|
252
|
+
// layers, P groups and K mattes is one queue submission instead of one per
|
|
253
|
+
// call. Commands inside an encoder execute in the order they were
|
|
254
|
+
// recorded, which is the same ordering the separate submissions gave.
|
|
255
|
+
const encoder = this.device.createCommandEncoder({
|
|
256
|
+
label: `${this.label}-frame`
|
|
257
|
+
});
|
|
258
|
+
this.effects.beginSubmission();
|
|
259
|
+
// Every group and matte in this frame records into `encoder` before one
|
|
260
|
+
// submit, so the precomposite core's uniform ring is reset here, once, and
|
|
261
|
+
// each pass below takes its own slot. Resetting it per group would hand
|
|
262
|
+
// the second group the first group's buffers while those commands are
|
|
263
|
+
// still pending.
|
|
264
|
+
this.precompCore?.beginFrame();
|
|
265
|
+
const { stack, drawn } = this.composePrecomposites(ordered, precomposites, adjustments, encoder);
|
|
266
|
+
const seed = encoder.beginRenderPass({
|
|
267
|
+
colorAttachments: [
|
|
268
|
+
{
|
|
269
|
+
view: readStart.createView(),
|
|
270
|
+
clearValue,
|
|
271
|
+
loadOp: "clear",
|
|
272
|
+
storeOp: "store"
|
|
273
|
+
}
|
|
274
|
+
]
|
|
275
|
+
});
|
|
276
|
+
seed.end();
|
|
277
|
+
this.core.beginFrame();
|
|
278
|
+
const texture = this.blendStack(encoder, this.core, stack, readStart, writeStart);
|
|
279
|
+
this.device.queue.submit([encoder.finish()]);
|
|
280
|
+
return { texture, drawn };
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Blend `items` bottom-up over whatever `read` holds, ping-ponging between
|
|
284
|
+
* the two accumulation textures, and answer the one holding the result. The
|
|
285
|
+
* caller has already called `beginFrame` on `core` and seeded `read`.
|
|
286
|
+
*
|
|
287
|
+
* An adjustment in the stack takes the accumulation as its own source: the
|
|
288
|
+
* chain runs on `readTex` and the treated copy is mixed straight back into
|
|
289
|
+
* it, which is what makes the treatment cover everything below the adjustment
|
|
290
|
+
* and nothing above (T24).
|
|
291
|
+
*/
|
|
292
|
+
blendStack(encoder, core, items, read, write) {
|
|
293
|
+
let readTex = read;
|
|
294
|
+
let writeTex = write;
|
|
295
|
+
for (const item of items) {
|
|
296
|
+
if (isAdjustment(item)) {
|
|
297
|
+
this.mixTreatment(item, readTex, this.treatAccumulation(item, readTex, encoder), writeTex, encoder);
|
|
298
|
+
const swap = readTex;
|
|
299
|
+
readTex = writeTex;
|
|
300
|
+
writeTex = swap;
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
core.renderBlendPass(encoder, readTex, writeTex, {
|
|
304
|
+
source: item.texture,
|
|
305
|
+
opacity: item.opacity,
|
|
306
|
+
blendModeId: blendModeGpuId(item.blendMode),
|
|
307
|
+
canvasW: this.width,
|
|
308
|
+
canvasH: this.height,
|
|
309
|
+
invAffine: item.invAffine,
|
|
310
|
+
borderRadius: item.borderRadius,
|
|
311
|
+
wipe: wipeParams(item.mask),
|
|
312
|
+
iris: item.iris
|
|
313
|
+
});
|
|
314
|
+
const tmp = readTex;
|
|
315
|
+
readTex = writeTex;
|
|
316
|
+
writeTex = tmp;
|
|
317
|
+
}
|
|
318
|
+
return readTex;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Upload a layer's pixels, run its effects and mask, place it, and — when it
|
|
322
|
+
* is matted — replace all of that with the matted composite (D6). Null when
|
|
323
|
+
* the layer has no drawable source.
|
|
324
|
+
*/
|
|
325
|
+
resolveLayer(layer, encoder) {
|
|
326
|
+
const item = this.resolvePlacedLayer(layer, encoder);
|
|
327
|
+
if (!item || !layer.matte)
|
|
328
|
+
return item;
|
|
329
|
+
return this.applyMatte(layer, item, layer.matte, encoder);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Compose a matted layer and its matte source into their own frame-sized
|
|
333
|
+
* textures, read the named channel out of the source, and multiply it into
|
|
334
|
+
* the layer's alpha.
|
|
335
|
+
*
|
|
336
|
+
* Frame-sized rather than source-sized because a matte is positioned by its
|
|
337
|
+
* own clip: where its keyhole falls is only expressible once both layers are
|
|
338
|
+
* placed. The matte source is resolved through {@link resolvePlacedLayer}
|
|
339
|
+
* rather than {@link resolveLayer}, so a matte can never drive a matte.
|
|
340
|
+
*/
|
|
341
|
+
applyMatte(layer, item, matte, encoder) {
|
|
342
|
+
const source = this.resolvePlacedLayer(matte.layer, encoder);
|
|
343
|
+
// No matte source pixels means an empty keyhole. Drawing the layer unmatted
|
|
344
|
+
// would show everything the matte was there to hide, so it draws nothing.
|
|
345
|
+
if (!source)
|
|
346
|
+
return null;
|
|
347
|
+
const composed = this.composeToTexture(`matte:${layer.id}`, [
|
|
348
|
+
// The layer's own opacity and blend mode meet the frame once, when
|
|
349
|
+
// this texture blends; on its own surface it is an opaque source-over
|
|
350
|
+
// draw.
|
|
351
|
+
{ ...item, opacity: 1, blendMode: "normal", zIndex: 0 }
|
|
352
|
+
], [], encoder);
|
|
353
|
+
const keyhole = this.composeToTexture(`mattesrc:${layer.id}`, [{ ...source, blendMode: "normal", zIndex: 0 }], [], encoder);
|
|
354
|
+
const derived = this.effects.deriveMask(`matte-mask:${layer.id}`, keyhole, this.width, this.height, matte.mode, matte.invert, "straight", encoder);
|
|
355
|
+
// A feathered matte is a blur of the keyhole, not of the picture: coverage
|
|
356
|
+
// carries its value in alpha with RGB at zero, which is already valid
|
|
357
|
+
// premultiplied, so the blur pass softens the edge and leaves the colour
|
|
358
|
+
// alone.
|
|
359
|
+
const feather = matte.featherPx ?? 0;
|
|
360
|
+
const coverage = feather > 0
|
|
361
|
+
? this.effects.process(`matte-feather:${layer.id}`, derived, this.width, this.height, [
|
|
362
|
+
{
|
|
363
|
+
id: `matte-feather:${layer.id}`,
|
|
364
|
+
type: "blur",
|
|
365
|
+
enabled: true,
|
|
366
|
+
radius: feather
|
|
367
|
+
}
|
|
368
|
+
], [], "premultiplied", encoder)
|
|
369
|
+
: derived;
|
|
370
|
+
return {
|
|
371
|
+
texture: this.effects.applyMask(`matte-apply:${layer.id}`, composed, this.width, this.height, coverage, this.width, this.height, "straight", encoder),
|
|
372
|
+
// `strength` scales the matte's alpha, and the matted composite meets the
|
|
373
|
+
// frame through this one opacity — so scaling it here is the same
|
|
374
|
+
// multiply, without a pass of its own over the coverage texture.
|
|
375
|
+
opacity: layer.opacity * (matte.strength ?? 1),
|
|
376
|
+
blendMode: layer.blendMode,
|
|
377
|
+
zIndex: layer.zIndex,
|
|
378
|
+
stackOrder: layer.stackOrder,
|
|
379
|
+
// The composite is frame-sized, so it blends 1:1: the layer's placement
|
|
380
|
+
// already ran when it was drawn onto its own texture.
|
|
381
|
+
invAffine: this.framePlacement(undefined),
|
|
382
|
+
borderRadius: 0
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Upload a layer's pixels, run its own effect chain and shape mask, and work
|
|
387
|
+
* out where it sits. Null when the layer has no drawable source, or when
|
|
388
|
+
* its placement covers no area.
|
|
389
|
+
*/
|
|
390
|
+
resolvePlacedLayer(layer, encoder) {
|
|
391
|
+
const uploaded = this.upload(layer.id, layer.source);
|
|
392
|
+
if (!uploaded)
|
|
393
|
+
return null;
|
|
394
|
+
// Crop first: everything below — the effect chain, the shape mask, the
|
|
395
|
+
// contain fit, the border radius — then sees the cropped rectangle as the
|
|
396
|
+
// layer's whole picture, which is what a crop means.
|
|
397
|
+
const src = this.cropSource(layer, uploaded, encoder);
|
|
398
|
+
const invAffine = this.placementOf({
|
|
399
|
+
transform: transitionTransform(layer.transform, layer.transition, this.referenceWidth, this.referenceHeight),
|
|
400
|
+
parentMatrix: layer.parentMatrix
|
|
401
|
+
}, src.width, src.height);
|
|
402
|
+
if (!invAffine)
|
|
403
|
+
return null;
|
|
404
|
+
const clipEffects = layer.transition?.effect
|
|
405
|
+
? [...(layer.effects ?? []), layer.transition.effect]
|
|
406
|
+
: layer.effects ?? [];
|
|
407
|
+
const trackEffects = layer.trackEffects ?? [];
|
|
408
|
+
const graded = clipEffects.length > 0 || trackEffects.length > 0
|
|
409
|
+
? this.effects.process(layer.id, src.texture, src.width, src.height, clipEffects, trackEffects, "straight", encoder)
|
|
410
|
+
: src.texture;
|
|
411
|
+
// Both the upload and the effects chain hand back straight alpha, which is
|
|
412
|
+
// what `applyMask` bridges from and what the blend shader reads a source
|
|
413
|
+
// as — so a layer with effects, a mask, both or neither reaches the blend
|
|
414
|
+
// in one convention.
|
|
415
|
+
const coverage = layer.shapeMask
|
|
416
|
+
? this.upload(`${layer.id}#mask`, layer.shapeMask)
|
|
417
|
+
: null;
|
|
418
|
+
const texture = coverage
|
|
419
|
+
? this.effects.applyMask(`mask:${layer.id}`, graded, src.width, src.height, coverage.texture, coverage.width, coverage.height, "straight", encoder)
|
|
420
|
+
: graded;
|
|
421
|
+
const radiusPx = layer.borderRadius ?? 0;
|
|
422
|
+
return {
|
|
423
|
+
texture,
|
|
424
|
+
opacity: layer.opacity,
|
|
425
|
+
blendMode: layer.blendMode,
|
|
426
|
+
zIndex: layer.zIndex,
|
|
427
|
+
stackOrder: layer.stackOrder,
|
|
428
|
+
invAffine,
|
|
429
|
+
borderRadius: radiusPx > 0
|
|
430
|
+
? Math.min(0.5, radiusPx / Math.min(src.width, src.height))
|
|
431
|
+
: 0,
|
|
432
|
+
// An animated wipe on the clip and a wipe transition both reduce to one
|
|
433
|
+
// reveal; the clip's own wins, because it is the motion the author put
|
|
434
|
+
// there.
|
|
435
|
+
mask: layer.mask ?? layer.transition?.mask,
|
|
436
|
+
iris: layer.transition?.iris
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* The placement of a frame-sized texture: 1:1, or moved by a transition's
|
|
441
|
+
* transform. A transition never scales to zero, so this is never empty.
|
|
442
|
+
*/
|
|
443
|
+
framePlacement(transform) {
|
|
444
|
+
return forwardClipMatrixToInverseAffine(buildTransformMatrix(transform ?? IDENTITY_TRANSFORM, containBaseScale(this.width, this.height, this.width, this.height), this.referenceWidth, this.referenceHeight), this.width, this.height, this.width, this.height);
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Where a source of this size lands on the frame, as the shader's affine.
|
|
448
|
+
* Null when the placement covers no area, such as a scale of 0 on either
|
|
449
|
+
* axis: that layer draws nothing.
|
|
450
|
+
*/
|
|
451
|
+
placementOf(layer, sourceWidth, sourceHeight) {
|
|
452
|
+
const matrix = buildTransformMatrix(layer.transform ?? IDENTITY_TRANSFORM, containBaseScale(sourceWidth, sourceHeight, this.width, this.height), this.referenceWidth, this.referenceHeight, layer.parentMatrix);
|
|
453
|
+
return invertClipPlacement(matrix, sourceWidth, sourceHeight, this.width, this.height);
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* The full-frame solid a layer's `dipToColor` fades through, as a layer
|
|
457
|
+
* sitting immediately beneath it. Null when the layer names no dip, or when
|
|
458
|
+
* the colour is one the GPU path cannot read.
|
|
459
|
+
*
|
|
460
|
+
* One texel stretched over the frame: the source size only decides how the
|
|
461
|
+
* inverse affine maps screen pixels to texels, and every pixel of a solid
|
|
462
|
+
* samples the same one.
|
|
463
|
+
*/
|
|
464
|
+
dipSolidFor(layer) {
|
|
465
|
+
const solid = layer.transition?.solid;
|
|
466
|
+
if (!solid || solid.opacity <= 0)
|
|
467
|
+
return null;
|
|
468
|
+
const texture = this.solidTexture(solid.color);
|
|
469
|
+
if (!texture)
|
|
470
|
+
return null;
|
|
471
|
+
return {
|
|
472
|
+
texture,
|
|
473
|
+
opacity: Math.min(1, solid.opacity),
|
|
474
|
+
blendMode: "normal",
|
|
475
|
+
zIndex: layer.zIndex,
|
|
476
|
+
stackOrder: layer.stackOrder,
|
|
477
|
+
// The identity base makes the single texel cover clip space [-1,1]².
|
|
478
|
+
invAffine: forwardClipMatrixToInverseAffine(buildTransformMatrix(IDENTITY_TRANSFORM, { x: 1, y: 1 }, this.referenceWidth, this.referenceHeight), 1, 1, this.width, this.height),
|
|
479
|
+
borderRadius: 0
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* The layer's pixels narrowed to its crop rectangle, as a texture of exactly
|
|
484
|
+
* that size. Returns the upload untouched when there is no usable crop, which
|
|
485
|
+
* is every layer of a document nobody has cropped — that path allocates
|
|
486
|
+
* nothing and copies nothing.
|
|
487
|
+
*
|
|
488
|
+
* A plain texture-to-texture copy, not a shader pass: the crop is an axis
|
|
489
|
+
* aligned region of whole texels, so there is nothing to filter and a copy is
|
|
490
|
+
* both exact and cheaper than a render pass. The copy is recorded into the
|
|
491
|
+
* frame's own encoder, so it costs no extra submit.
|
|
492
|
+
*/
|
|
493
|
+
cropSource(layer, uploaded, encoder) {
|
|
494
|
+
if (!hasCrop(layer.crop)) {
|
|
495
|
+
// A clip that was cropped and is not any more must not keep drawing the
|
|
496
|
+
// stale copy, and holding the texture for a layer with no crop would leak
|
|
497
|
+
// it until the layer left the frame.
|
|
498
|
+
const stale = this.crops.get(layer.id);
|
|
499
|
+
if (stale) {
|
|
500
|
+
stale.texture.destroy();
|
|
501
|
+
this.crops.delete(layer.id);
|
|
502
|
+
}
|
|
503
|
+
return uploaded;
|
|
504
|
+
}
|
|
505
|
+
const rect = cropRectPx(layer.crop, uploaded.width, uploaded.height);
|
|
506
|
+
let entry = this.crops.get(layer.id);
|
|
507
|
+
if (!entry || entry.width !== rect.width || entry.height !== rect.height) {
|
|
508
|
+
entry?.texture.destroy();
|
|
509
|
+
entry = {
|
|
510
|
+
texture: this.device.createTexture({
|
|
511
|
+
label: `${this.label}-crop-${layer.id}`,
|
|
512
|
+
size: { width: rect.width, height: rect.height },
|
|
513
|
+
format: TEXTURE_FORMAT,
|
|
514
|
+
usage: GPUTextureUsage.TEXTURE_BINDING |
|
|
515
|
+
GPUTextureUsage.COPY_DST |
|
|
516
|
+
GPUTextureUsage.COPY_SRC |
|
|
517
|
+
GPUTextureUsage.RENDER_ATTACHMENT
|
|
518
|
+
}),
|
|
519
|
+
width: rect.width,
|
|
520
|
+
height: rect.height
|
|
521
|
+
};
|
|
522
|
+
this.crops.set(layer.id, entry);
|
|
523
|
+
}
|
|
524
|
+
// Re-copied every frame rather than versioned: the upload underneath is
|
|
525
|
+
// itself re-written whenever the pixels change, and a video layer's change
|
|
526
|
+
// every frame, so a version check here would only add a field to get wrong.
|
|
527
|
+
encoder.copyTextureToTexture({ texture: uploaded.texture, origin: { x: rect.x, y: rect.y } }, { texture: entry.texture }, { width: rect.width, height: rect.height });
|
|
528
|
+
return entry;
|
|
529
|
+
}
|
|
530
|
+
/** A 1×1 opaque texture of `color`, kept for the life of the compositor. */
|
|
531
|
+
solidTexture(color) {
|
|
532
|
+
const cached = this.solids.get(color);
|
|
533
|
+
if (cached)
|
|
534
|
+
return cached;
|
|
535
|
+
const rgb = dipColorBytes(color);
|
|
536
|
+
const texture = this.device.createTexture({
|
|
537
|
+
label: `${this.label}-solid-${color}`,
|
|
538
|
+
size: { width: 1, height: 1 },
|
|
539
|
+
format: TEXTURE_FORMAT,
|
|
540
|
+
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST
|
|
541
|
+
});
|
|
542
|
+
this.device.queue.writeTexture({ texture }, new Uint8Array([rgb.r, rgb.g, rgb.b, 255]), { bytesPerRow: 4, rowsPerImage: 1 }, { width: 1, height: 1 });
|
|
543
|
+
this.solids.set(color, texture);
|
|
544
|
+
return texture;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Render each precompositing group into its own texture and return the main
|
|
548
|
+
* stack: the layers belonging to no group, plus one entry per group whose
|
|
549
|
+
* texture blends onto the frame.
|
|
550
|
+
*
|
|
551
|
+
* `precomposites` arrives innermost first, so a nested group's finished
|
|
552
|
+
* texture is already in hand when the group above renders. Every group's work
|
|
553
|
+
* is submitted before the next one starts, which is what orders a nested
|
|
554
|
+
* texture ahead of the read that consumes it.
|
|
555
|
+
*/
|
|
556
|
+
composePrecomposites(layers, precomposites, adjustments, encoder) {
|
|
557
|
+
let drawn = 0;
|
|
558
|
+
if (precomposites.length === 0) {
|
|
559
|
+
const stack = [];
|
|
560
|
+
for (const layer of layers) {
|
|
561
|
+
const item = this.resolveLayer(layer, encoder);
|
|
562
|
+
if (!item)
|
|
563
|
+
continue;
|
|
564
|
+
drawn += 1;
|
|
565
|
+
const solid = this.dipSolidFor(layer);
|
|
566
|
+
if (solid)
|
|
567
|
+
stack.push(solid);
|
|
568
|
+
stack.push(item);
|
|
569
|
+
}
|
|
570
|
+
// An adjustment at a layer's own z treats it, so it is appended after
|
|
571
|
+
// every layer and the sort below is stable.
|
|
572
|
+
for (const adjustment of adjustments) {
|
|
573
|
+
stack.push(this.resolveAdjustment(adjustment));
|
|
574
|
+
}
|
|
575
|
+
return { stack: sortStack(stack), drawn };
|
|
576
|
+
}
|
|
577
|
+
const stack = [];
|
|
578
|
+
const byGroup = new Map();
|
|
579
|
+
const assign = (groupId, item) => {
|
|
580
|
+
if (!groupId) {
|
|
581
|
+
stack.push(item);
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
const bucket = byGroup.get(groupId);
|
|
585
|
+
if (bucket)
|
|
586
|
+
bucket.push(item);
|
|
587
|
+
else
|
|
588
|
+
byGroup.set(groupId, [item]);
|
|
589
|
+
};
|
|
590
|
+
for (const layer of layers) {
|
|
591
|
+
const item = this.resolveLayer(layer, encoder);
|
|
592
|
+
if (!item)
|
|
593
|
+
continue;
|
|
594
|
+
drawn += 1;
|
|
595
|
+
// The solid shares the layer's z and is pushed first, so the stable sort
|
|
596
|
+
// that orders the stack keeps it beneath the clip it dips into.
|
|
597
|
+
const solid = this.dipSolidFor(layer);
|
|
598
|
+
if (solid)
|
|
599
|
+
assign(layer.precomposeGroupId, solid);
|
|
600
|
+
assign(layer.precomposeGroupId, item);
|
|
601
|
+
}
|
|
602
|
+
// After the layers, so an adjustment sharing a z with one treats it.
|
|
603
|
+
for (const adjustment of adjustments) {
|
|
604
|
+
assign(adjustment.precomposeGroupId, this.resolveAdjustment(adjustment));
|
|
605
|
+
}
|
|
606
|
+
for (const group of precomposites) {
|
|
607
|
+
const children = byGroup.get(group.id) ?? [];
|
|
608
|
+
// A group whose only content is an adjustment composites nothing, so
|
|
609
|
+
// there is nothing to treat and no texture worth allocating.
|
|
610
|
+
if (children.length === 0 || children.every(isAdjustment))
|
|
611
|
+
continue;
|
|
612
|
+
const texture = this.renderPrecomposite(group, children, encoder);
|
|
613
|
+
const solid = this.dipSolidFor(group);
|
|
614
|
+
if (solid)
|
|
615
|
+
assign(group.precomposeGroupId, solid);
|
|
616
|
+
assign(group.precomposeGroupId, {
|
|
617
|
+
texture,
|
|
618
|
+
opacity: group.opacity,
|
|
619
|
+
blendMode: group.blendMode,
|
|
620
|
+
zIndex: group.zIndex,
|
|
621
|
+
stackOrder: group.stackOrder,
|
|
622
|
+
// The texture is frame-sized, so it composites 1:1: the group's own
|
|
623
|
+
// matrix already rode into each child through `parentMatrix`.
|
|
624
|
+
invAffine: this.framePlacement(transitionTransform(undefined, group.transition, this.referenceWidth, this.referenceHeight)),
|
|
625
|
+
borderRadius: 0,
|
|
626
|
+
mask: group.transition?.mask,
|
|
627
|
+
iris: group.transition?.iris
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
return { stack: sortStack(stack), drawn };
|
|
631
|
+
}
|
|
632
|
+
/** One adjustment with its coverage raster uploaded, ready for the stack. */
|
|
633
|
+
resolveAdjustment(adjustment) {
|
|
634
|
+
const item = {
|
|
635
|
+
kind: "adjustment",
|
|
636
|
+
key: adjustment.id,
|
|
637
|
+
opacity: adjustment.opacity,
|
|
638
|
+
zIndex: adjustment.zIndex,
|
|
639
|
+
effects: (adjustment.effects ?? []).filter((effect) => effect.enabled),
|
|
640
|
+
coverage: adjustment.shapeMask
|
|
641
|
+
? this.upload(`${adjustment.id}#adjustmask`, adjustment.shapeMask)
|
|
642
|
+
: null
|
|
643
|
+
};
|
|
644
|
+
if (adjustment.wipe)
|
|
645
|
+
item.mask = adjustment.wipe;
|
|
646
|
+
return item;
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Composite one group's children over transparency, run the group's effects
|
|
650
|
+
* on the result, and leave it in the group's own texture as straight alpha —
|
|
651
|
+
* which is how the blend shader reads a source.
|
|
652
|
+
*/
|
|
653
|
+
renderPrecomposite(group, children, encoder) {
|
|
654
|
+
return this.composeToTexture(group.id, children, group.transition?.effect
|
|
655
|
+
? [...(group.effects ?? []), group.transition.effect]
|
|
656
|
+
: group.effects ?? [], encoder);
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Run one adjustment's chain on the accumulation it sits on and answer the
|
|
660
|
+
* treated copy, premultiplied — the convention the accumulation is already in
|
|
661
|
+
* and the one {@link mixTreatment} mixes in, so an adjustment converts alpha
|
|
662
|
+
* no times where a precomposite converts it once.
|
|
663
|
+
*
|
|
664
|
+
* The adjustment's mask does *not* run here: it is coverage, not picture, and
|
|
665
|
+
* multiplying it into the treated copy's alpha would leave the mix unable to
|
|
666
|
+
* tell "the treatment reaches this pixel a quarter of the way" from "the
|
|
667
|
+
* treated picture is a quarter opaque here".
|
|
668
|
+
*/
|
|
669
|
+
treatAccumulation(item, accumulation, encoder) {
|
|
670
|
+
return this.effects.process(`adjust:${item.key}`, accumulation, this.width, this.height, item.effects, [], "premultiplied", encoder);
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Mix one adjustment's treated copy back into the accumulation it was taken
|
|
674
|
+
* from, into `target`: `out = accumulation * (1 - c) + treated * c` on every
|
|
675
|
+
* premultiplied channel, alpha included, with `c` the adjustment's opacity
|
|
676
|
+
* times its mask coverage times its wipe.
|
|
677
|
+
*
|
|
678
|
+
* A pass of its own rather than a blend pass, because the blend shader
|
|
679
|
+
* composites a source *over* the accumulation, and the treated copy carries
|
|
680
|
+
* the accumulation's own alpha: laying it back over its origin added that
|
|
681
|
+
* alpha to itself, so a fully applied neutral chain took a 50%-opaque pixel to
|
|
682
|
+
* 75% and thickened every softened edge in a group surface or an alpha export
|
|
683
|
+
* (F3). A treatment replaces what it covers, which is a mix by coverage and
|
|
684
|
+
* not a composite — the same rule, and the same formula, the Canvas 2D path's
|
|
685
|
+
* `mixTreatment` applies.
|
|
686
|
+
*/
|
|
687
|
+
mixTreatment(item, accumulation, treated, target, encoder) {
|
|
688
|
+
const wipe = wipeParams(item.mask);
|
|
689
|
+
const coverage = item.coverage;
|
|
690
|
+
const uniforms = this.mixUniformBuffer(item.key);
|
|
691
|
+
this.device.queue.writeBuffer(uniforms, 0, new Float32Array([
|
|
692
|
+
item.opacity,
|
|
693
|
+
coverage ? 1 : 0,
|
|
694
|
+
wipe ? wipe.edge : 0,
|
|
695
|
+
wipe ? wipe.progress : 0,
|
|
696
|
+
wipe ? wipe.softness : 0,
|
|
697
|
+
0,
|
|
698
|
+
0,
|
|
699
|
+
0
|
|
700
|
+
]));
|
|
701
|
+
const pipeline = this.mixPipeline();
|
|
702
|
+
const pass = encoder.beginRenderPass({
|
|
703
|
+
colorAttachments: [
|
|
704
|
+
{ view: target.createView(), loadOp: "clear", storeOp: "store" }
|
|
705
|
+
]
|
|
706
|
+
});
|
|
707
|
+
pass.setPipeline(pipeline);
|
|
708
|
+
pass.setBindGroup(0, this.device.createBindGroup({
|
|
709
|
+
layout: pipeline.getBindGroupLayout(0),
|
|
710
|
+
entries: [
|
|
711
|
+
{ binding: 0, resource: { buffer: uniforms } },
|
|
712
|
+
{ binding: 1, resource: accumulation.createView() },
|
|
713
|
+
{ binding: 2, resource: treated.createView() },
|
|
714
|
+
// Every binding has to be filled whether or not the shader reads it;
|
|
715
|
+
// with no mask the flag is off and this view is never sampled.
|
|
716
|
+
{
|
|
717
|
+
binding: 3,
|
|
718
|
+
resource: (coverage?.texture ?? treated).createView()
|
|
719
|
+
}
|
|
720
|
+
]
|
|
721
|
+
}));
|
|
722
|
+
pass.draw(4);
|
|
723
|
+
pass.end();
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Composite `children` over transparency into the texture `key` names, run
|
|
727
|
+
* `effects` on the result, and leave it there as straight alpha — which is
|
|
728
|
+
* how the blend shader reads a source.
|
|
729
|
+
*/
|
|
730
|
+
composeToTexture(key, children, effects = [], frameEncoder) {
|
|
731
|
+
const core = this.precompositeCore();
|
|
732
|
+
const read = core.textureA;
|
|
733
|
+
const write = core.textureB;
|
|
734
|
+
if (!read || !write) {
|
|
735
|
+
throw new Error("Compositor failed to allocate precomposite textures");
|
|
736
|
+
}
|
|
737
|
+
const composeEncoder = frameEncoder ??
|
|
738
|
+
this.device.createCommandEncoder({
|
|
739
|
+
label: `${this.label}-precomp-${key}`
|
|
740
|
+
});
|
|
741
|
+
// Transparent, not black: the group's own pixels have to blend over what is
|
|
742
|
+
// already on the frame, and a black seed would knock it out.
|
|
743
|
+
const seed = composeEncoder.beginRenderPass({
|
|
744
|
+
colorAttachments: [
|
|
745
|
+
{
|
|
746
|
+
view: read.createView(),
|
|
747
|
+
clearValue: { r: 0, g: 0, b: 0, a: 0 },
|
|
748
|
+
loadOp: "clear",
|
|
749
|
+
storeOp: "store"
|
|
750
|
+
}
|
|
751
|
+
]
|
|
752
|
+
});
|
|
753
|
+
seed.end();
|
|
754
|
+
// With a frame encoder the ring was reset once at the top of the frame
|
|
755
|
+
// (see `composite`); resetting here would alias this pass's uniforms
|
|
756
|
+
// with the previous group's.
|
|
757
|
+
if (!frameEncoder)
|
|
758
|
+
core.beginFrame();
|
|
759
|
+
const composed = this.blendStack(composeEncoder, core, sortStack([...children]), read, write);
|
|
760
|
+
// Without a frame encoder this has to be submitted here, because the
|
|
761
|
+
// effects pass below and a group above read this texture through their own
|
|
762
|
+
// submissions and only submit order puts the write first. With one, record
|
|
763
|
+
// order does the same job and the frame submits once.
|
|
764
|
+
if (!frameEncoder)
|
|
765
|
+
this.device.queue.submit([composeEncoder.finish()]);
|
|
766
|
+
// The accumulation is premultiplied. Saying so lets the effects chain run
|
|
767
|
+
// on it directly, and one resolve at the end is then the only alpha
|
|
768
|
+
// conversion in the whole precomposite.
|
|
769
|
+
const graded = this.effects.process(`precomp:${key}`, composed, this.width, this.height, effects, [], "premultiplied", frameEncoder);
|
|
770
|
+
const target = this.precompositeTarget(key);
|
|
771
|
+
const resolveEncoder = frameEncoder ??
|
|
772
|
+
this.device.createCommandEncoder({
|
|
773
|
+
label: `${this.label}-precomp-resolve-${key}`
|
|
774
|
+
});
|
|
775
|
+
const pass = resolveEncoder.beginRenderPass({
|
|
776
|
+
colorAttachments: [
|
|
777
|
+
{
|
|
778
|
+
view: target.createView(),
|
|
779
|
+
clearValue: { r: 0, g: 0, b: 0, a: 0 },
|
|
780
|
+
loadOp: "clear",
|
|
781
|
+
storeOp: "store"
|
|
782
|
+
}
|
|
783
|
+
]
|
|
784
|
+
});
|
|
785
|
+
const pipeline = this.unpremultiplyPipeline();
|
|
786
|
+
pass.setPipeline(pipeline);
|
|
787
|
+
pass.setBindGroup(0, this.device.createBindGroup({
|
|
788
|
+
layout: pipeline.getBindGroupLayout(0),
|
|
789
|
+
entries: [{ binding: 0, resource: graded.createView() }]
|
|
790
|
+
}));
|
|
791
|
+
pass.draw(4);
|
|
792
|
+
pass.end();
|
|
793
|
+
if (!frameEncoder)
|
|
794
|
+
this.device.queue.submit([resolveEncoder.finish()]);
|
|
795
|
+
return target;
|
|
796
|
+
}
|
|
797
|
+
precompositeCore() {
|
|
798
|
+
let core = this.precompCore;
|
|
799
|
+
if (!core) {
|
|
800
|
+
core = new WebGPULayerCompositor(this.device, TEXTURE_FORMAT, "linear", `${this.label}-precomp`);
|
|
801
|
+
core.ensureSize(this.width, this.height);
|
|
802
|
+
this.precompCore = core;
|
|
803
|
+
}
|
|
804
|
+
return core;
|
|
805
|
+
}
|
|
806
|
+
precompositeTarget(id) {
|
|
807
|
+
let target = this.precompTargets.get(id);
|
|
808
|
+
if (!target) {
|
|
809
|
+
target = this.device.createTexture({
|
|
810
|
+
label: `${this.label}-precomp-target-${id}`,
|
|
811
|
+
size: { width: this.width, height: this.height },
|
|
812
|
+
format: TEXTURE_FORMAT,
|
|
813
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
|
|
814
|
+
});
|
|
815
|
+
this.precompTargets.set(id, target);
|
|
816
|
+
}
|
|
817
|
+
return target;
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* The uniform buffer one adjustment's mix pass reads, kept per adjustment.
|
|
821
|
+
*
|
|
822
|
+
* One shared buffer would not do: every pass of a frame is recorded into one
|
|
823
|
+
* encoder and submitted once, so a second `writeBuffer` before that submit
|
|
824
|
+
* would hand the first adjustment the second one's coverage.
|
|
825
|
+
*/
|
|
826
|
+
mixUniformBuffer(key) {
|
|
827
|
+
let buffer = this.mixUniforms.get(key);
|
|
828
|
+
if (!buffer) {
|
|
829
|
+
buffer = this.device.createBuffer({
|
|
830
|
+
label: `${this.label}-adjust-mix-${key}`,
|
|
831
|
+
size: MIX_UNIFORM_BYTES,
|
|
832
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
833
|
+
});
|
|
834
|
+
this.mixUniforms.set(key, buffer);
|
|
835
|
+
}
|
|
836
|
+
return buffer;
|
|
837
|
+
}
|
|
838
|
+
mixPipeline() {
|
|
839
|
+
let pipeline = this.mix;
|
|
840
|
+
if (!pipeline) {
|
|
841
|
+
const module = this.device.createShaderModule({
|
|
842
|
+
label: `${this.label}-adjust-mix`,
|
|
843
|
+
code: `${FULLSCREEN_QUAD_VERTEX}\n${TREATMENT_MIX_FRAGMENT}`
|
|
844
|
+
});
|
|
845
|
+
pipeline = this.device.createRenderPipeline({
|
|
846
|
+
label: `${this.label}-adjust-mix`,
|
|
847
|
+
layout: "auto",
|
|
848
|
+
vertex: { module, entryPoint: "vs_main" },
|
|
849
|
+
fragment: {
|
|
850
|
+
module,
|
|
851
|
+
entryPoint: "fs_mix",
|
|
852
|
+
targets: [{ format: TEXTURE_FORMAT }]
|
|
853
|
+
},
|
|
854
|
+
primitive: { topology: "triangle-strip" }
|
|
855
|
+
});
|
|
856
|
+
this.mix = pipeline;
|
|
857
|
+
}
|
|
858
|
+
return pipeline;
|
|
859
|
+
}
|
|
860
|
+
unpremultiplyPipeline() {
|
|
861
|
+
let pipeline = this.unpremultiply;
|
|
862
|
+
if (!pipeline) {
|
|
863
|
+
const module = this.device.createShaderModule({
|
|
864
|
+
label: `${this.label}-unpremultiply`,
|
|
865
|
+
code: `${FULLSCREEN_QUAD_VERTEX}\n${UNPREMULTIPLY_FRAGMENT}`
|
|
866
|
+
});
|
|
867
|
+
pipeline = this.device.createRenderPipeline({
|
|
868
|
+
label: `${this.label}-unpremultiply`,
|
|
869
|
+
layout: "auto",
|
|
870
|
+
vertex: { module, entryPoint: "vs_main" },
|
|
871
|
+
fragment: {
|
|
872
|
+
module,
|
|
873
|
+
entryPoint: "fs_unpremultiply",
|
|
874
|
+
targets: [{ format: TEXTURE_FORMAT }]
|
|
875
|
+
},
|
|
876
|
+
primitive: { topology: "triangle-strip" }
|
|
877
|
+
});
|
|
878
|
+
this.unpremultiply = pipeline;
|
|
879
|
+
}
|
|
880
|
+
return pipeline;
|
|
881
|
+
}
|
|
882
|
+
retainOnly(layers, precomposites, adjustments = []) {
|
|
883
|
+
// A matte source never appears in `layers`, and its textures are keyed off
|
|
884
|
+
// the layer it mattes, so the sweep walks both.
|
|
885
|
+
const live = new Set();
|
|
886
|
+
const liveTargets = new Set(precomposites.map((p) => p.id));
|
|
887
|
+
const effectKeys = new Set();
|
|
888
|
+
const visit = (layer) => {
|
|
889
|
+
live.add(layer.id);
|
|
890
|
+
effectKeys.add(layer.id);
|
|
891
|
+
if (layer.shapeMask) {
|
|
892
|
+
live.add(`${layer.id}#mask`);
|
|
893
|
+
effectKeys.add(`mask:${layer.id}`);
|
|
894
|
+
}
|
|
895
|
+
if (!layer.matte)
|
|
896
|
+
return;
|
|
897
|
+
liveTargets.add(`matte:${layer.id}`);
|
|
898
|
+
liveTargets.add(`mattesrc:${layer.id}`);
|
|
899
|
+
effectKeys.add(`matte-mask:${layer.id}`);
|
|
900
|
+
effectKeys.add(`matte-apply:${layer.id}`);
|
|
901
|
+
effectKeys.add(`matte-feather:${layer.id}`);
|
|
902
|
+
visit(layer.matte.layer);
|
|
903
|
+
};
|
|
904
|
+
for (const layer of layers)
|
|
905
|
+
visit(layer);
|
|
906
|
+
// An adjustment holds a treated texture, a mix uniform buffer and a
|
|
907
|
+
// coverage upload of its own, all keyed by its clip id, and none of them is
|
|
908
|
+
// reachable from any layer.
|
|
909
|
+
const liveMixes = new Set();
|
|
910
|
+
for (const adjustment of adjustments) {
|
|
911
|
+
effectKeys.add(`adjust:${adjustment.id}`);
|
|
912
|
+
liveMixes.add(adjustment.id);
|
|
913
|
+
if (adjustment.shapeMask)
|
|
914
|
+
live.add(`${adjustment.id}#adjustmask`);
|
|
915
|
+
}
|
|
916
|
+
for (const [id, buffer] of this.mixUniforms) {
|
|
917
|
+
if (!liveMixes.has(id)) {
|
|
918
|
+
buffer.destroy();
|
|
919
|
+
this.mixUniforms.delete(id);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
this.retainSources(live);
|
|
923
|
+
for (const [id, entry] of this.crops) {
|
|
924
|
+
if (!live.has(id)) {
|
|
925
|
+
entry.texture.destroy();
|
|
926
|
+
this.crops.delete(id);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
for (const [id, texture] of this.precompTargets) {
|
|
930
|
+
if (!liveTargets.has(id)) {
|
|
931
|
+
texture.destroy();
|
|
932
|
+
this.precompTargets.delete(id);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
// The effects processor is keyed by layer id for a clip's own chain and by
|
|
936
|
+
// `precomp:<id>` for every composed texture, so both sets have to survive.
|
|
937
|
+
for (const id of liveTargets)
|
|
938
|
+
effectKeys.add(`precomp:${id}`);
|
|
939
|
+
this.effects.retainOnly(effectKeys);
|
|
940
|
+
}
|
|
941
|
+
dispose() {
|
|
942
|
+
for (const texture of this.precompTargets.values())
|
|
943
|
+
texture.destroy();
|
|
944
|
+
this.precompTargets.clear();
|
|
945
|
+
for (const buffer of this.mixUniforms.values())
|
|
946
|
+
buffer.destroy();
|
|
947
|
+
this.mixUniforms.clear();
|
|
948
|
+
for (const texture of this.solids.values())
|
|
949
|
+
texture.destroy();
|
|
950
|
+
this.solids.clear();
|
|
951
|
+
this.effects.dispose();
|
|
952
|
+
for (const entry of this.crops.values())
|
|
953
|
+
entry.texture.destroy();
|
|
954
|
+
this.crops.clear();
|
|
955
|
+
this.core.dispose();
|
|
956
|
+
this.precompCore?.dispose();
|
|
957
|
+
this.precompCore = null;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
/** `copyTextureToBuffer` requires a 256-byte-aligned `bytesPerRow`. */
|
|
961
|
+
const ROW_ALIGNMENT = 256;
|
|
962
|
+
/**
|
|
963
|
+
* The accumulation format for a motion-blurred frame.
|
|
964
|
+
*
|
|
965
|
+
* `rgba16float` and not `rgba8unorm`: a sample contributes 1/N of its value, and
|
|
966
|
+
* at N = 8 that is 1/8 of a byte-quantized channel — under an 8-bit target every
|
|
967
|
+
* sample below 8/255 would round to nothing and the smear would develop banding
|
|
968
|
+
* at its faint end, which is exactly where a blur lives.
|
|
969
|
+
*/
|
|
970
|
+
const BLUR_ACCUMULATION_FORMAT = "rgba16float";
|
|
971
|
+
/**
|
|
972
|
+
* Composite one timeline frame without a canvas: CPU pixels in, straight-alpha
|
|
973
|
+
* RGBA8 out.
|
|
974
|
+
*
|
|
975
|
+
* The server-side host of {@link GpuFrameCompositor}. Everything about what a
|
|
976
|
+
* frame looks like is the compositor's; what is here is the boundary — a
|
|
977
|
+
* texture cache keyed by layer id and versioned by the pixels, and the readback
|
|
978
|
+
* buffer the finished frame is copied through.
|
|
979
|
+
*/
|
|
980
|
+
export class HeadlessFrameCompositor {
|
|
981
|
+
device;
|
|
982
|
+
compositor;
|
|
983
|
+
width;
|
|
984
|
+
height;
|
|
985
|
+
bytesPerRow;
|
|
986
|
+
/**
|
|
987
|
+
* Two readback buffers, used in turn.
|
|
988
|
+
*
|
|
989
|
+
* With one buffer a frame's copy cannot be recorded until the previous
|
|
990
|
+
* frame's map has resolved and the buffer is unmapped, so the copy of frame
|
|
991
|
+
* k+1 is serialized behind the CPU-side mapping of frame k. Alternating
|
|
992
|
+
* means the buffer a frame copies into is never the one still mapped, so the
|
|
993
|
+
* copy and the composite behind it can be submitted while the previous
|
|
994
|
+
* frame's map is still in flight. The pixels are unchanged: each frame still
|
|
995
|
+
* reads back the buffer it wrote.
|
|
996
|
+
*/
|
|
997
|
+
readbacks;
|
|
998
|
+
readbackIndex = 0;
|
|
999
|
+
sources = new Map();
|
|
1000
|
+
/** Accumulation is allocated only when motion blur uses multiple samples. */
|
|
1001
|
+
blurAccumulation = null;
|
|
1002
|
+
blurAccumulatePipeline = null;
|
|
1003
|
+
/** Shared straight-alpha resolve target and pipeline for both render paths. */
|
|
1004
|
+
resolveTarget = null;
|
|
1005
|
+
resolvePipeline = null;
|
|
1006
|
+
constructor(device, width, height) {
|
|
1007
|
+
this.device = device;
|
|
1008
|
+
this.width = Math.max(1, Math.floor(width));
|
|
1009
|
+
this.height = Math.max(1, Math.floor(height));
|
|
1010
|
+
this.compositor = new GpuFrameCompositor(device, this.width, this.height, {
|
|
1011
|
+
label: "timeline-headless",
|
|
1012
|
+
upload: (id, pixels) => this.uploadPixels(id, pixels),
|
|
1013
|
+
retainSources: (live) => {
|
|
1014
|
+
for (const [id, entry] of this.sources) {
|
|
1015
|
+
if (live.has(id))
|
|
1016
|
+
continue;
|
|
1017
|
+
entry.texture.destroy();
|
|
1018
|
+
this.sources.delete(id);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
});
|
|
1022
|
+
this.bytesPerRow =
|
|
1023
|
+
Math.ceil((this.width * 4) / ROW_ALIGNMENT) * ROW_ALIGNMENT;
|
|
1024
|
+
const makeReadback = (index) => device.createBuffer({
|
|
1025
|
+
label: `timeline-headless-readback-${index}`,
|
|
1026
|
+
size: this.bytesPerRow * this.height,
|
|
1027
|
+
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
|
|
1028
|
+
});
|
|
1029
|
+
this.readbacks = [makeReadback(0), makeReadback(1)];
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* Set the sequence resolution a stored transform is expressed against, for
|
|
1033
|
+
* a frame smaller or larger than the sequence. Unset, it is the frame size.
|
|
1034
|
+
*/
|
|
1035
|
+
setReferenceSize(width, height) {
|
|
1036
|
+
this.compositor.setReferenceSize(width, height);
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Composite `layers` and return the frame as straight-alpha RGBA8 at the
|
|
1040
|
+
* compositor's resolution.
|
|
1041
|
+
*
|
|
1042
|
+
* The ground is opaque black unless `options.alpha` is set, which seeds the
|
|
1043
|
+
* frame fully transparent instead — what an alpha export needs, and the same
|
|
1044
|
+
* seed `drawTimelineFrame` takes on the Canvas 2D side.
|
|
1045
|
+
*/
|
|
1046
|
+
async renderFrame(layers, precomposites = [], options = {}, adjustments = []) {
|
|
1047
|
+
const alpha = options.alpha === true;
|
|
1048
|
+
const { texture } = this.compositor.composite(layers, precomposites, { r: 0, g: 0, b: 0, a: alpha ? 0 : 1 }, adjustments);
|
|
1049
|
+
// Chroma key and other effects can lower alpha even over the opaque seed.
|
|
1050
|
+
// Resolve both export modes to straight alpha before copying to the CPU.
|
|
1051
|
+
const readback = this.nextReadback();
|
|
1052
|
+
const encoder = this.device.createCommandEncoder({
|
|
1053
|
+
label: "timeline-headless-readback"
|
|
1054
|
+
});
|
|
1055
|
+
const resolved = this.resolvePremultiplied(texture, encoder);
|
|
1056
|
+
encoder.copyTextureToBuffer({ texture: resolved }, {
|
|
1057
|
+
buffer: readback,
|
|
1058
|
+
bytesPerRow: this.bytesPerRow,
|
|
1059
|
+
rowsPerImage: this.height
|
|
1060
|
+
}, { width: this.width, height: this.height });
|
|
1061
|
+
this.device.queue.submit([encoder.finish()]);
|
|
1062
|
+
return this.readMapped(readback);
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Composite every instant of one shutter window and return their average as
|
|
1066
|
+
* straight-alpha RGBA8 — a motion-blurred frame (D10).
|
|
1067
|
+
*
|
|
1068
|
+
* A sample is the whole scene resolved at a sub-frame time
|
|
1069
|
+
* ({@link motionBlurSampleTimes} decides which), so the caller builds N layer
|
|
1070
|
+
* sets and this composites and folds each in turn. One sample takes the
|
|
1071
|
+
* unblurred path exactly, byte for byte: blur off must render what it rendered
|
|
1072
|
+
* before blur existed.
|
|
1073
|
+
*
|
|
1074
|
+
* **Premultiplied throughout, un-premultiplied once at the end.** Each sample
|
|
1075
|
+
* leaves the compositor's accumulation premultiplied, and the mean of N
|
|
1076
|
+
* premultiplied samples *is* the premultiplied mean — averaging colours that
|
|
1077
|
+
* had already been divided by their own alphas would weight a nearly
|
|
1078
|
+
* transparent sample's colour as heavily as an opaque one's and lighten the
|
|
1079
|
+
* leading edge of every smear. So the fold adds premultiplied values, and the
|
|
1080
|
+
* resolve pass divides the summed colour by the summed alpha once. Over an
|
|
1081
|
+
* opaque ground the summed alpha is 1 and that division is the identity, which
|
|
1082
|
+
* is why one resolve pipeline serves both grounds.
|
|
1083
|
+
*/
|
|
1084
|
+
async renderFrameSamples(samples, options = {}) {
|
|
1085
|
+
if (samples.length === 0) {
|
|
1086
|
+
throw new Error("A frame needs at least one sample to composite");
|
|
1087
|
+
}
|
|
1088
|
+
if (samples.length === 1) {
|
|
1089
|
+
return this.renderFrame(samples[0].layers, samples[0].precomposites ?? [], options, samples[0].adjustments ?? []);
|
|
1090
|
+
}
|
|
1091
|
+
const alpha = options.alpha === true;
|
|
1092
|
+
const clearValue = { r: 0, g: 0, b: 0, a: alpha ? 0 : 1 };
|
|
1093
|
+
const accumulation = this.blurAccumulationTexture();
|
|
1094
|
+
const weight = 1 / samples.length;
|
|
1095
|
+
for (let i = 0; i < samples.length; i++) {
|
|
1096
|
+
const { texture } = this.compositor.composite(samples[i].layers, samples[i].precomposites ?? [], clearValue, samples[i].adjustments ?? []);
|
|
1097
|
+
// Folded per sample rather than batched: the compositor hands back its
|
|
1098
|
+
// own ping-pong texture, and the next sample overwrites it.
|
|
1099
|
+
this.foldBlurSample(accumulation, texture, weight, i === 0);
|
|
1100
|
+
}
|
|
1101
|
+
const readback = this.nextReadback();
|
|
1102
|
+
const encoder = this.device.createCommandEncoder({
|
|
1103
|
+
label: "timeline-headless-blur-readback"
|
|
1104
|
+
});
|
|
1105
|
+
const resolved = this.resolvePremultiplied(accumulation, encoder);
|
|
1106
|
+
encoder.copyTextureToBuffer({ texture: resolved }, {
|
|
1107
|
+
buffer: readback,
|
|
1108
|
+
bytesPerRow: this.bytesPerRow,
|
|
1109
|
+
rowsPerImage: this.height
|
|
1110
|
+
}, { width: this.width, height: this.height });
|
|
1111
|
+
this.device.queue.submit([encoder.finish()]);
|
|
1112
|
+
return this.readMapped(readback);
|
|
1113
|
+
}
|
|
1114
|
+
/** Add one composited sample into the accumulation at `weight`. */
|
|
1115
|
+
foldBlurSample(accumulation, texture, weight, first) {
|
|
1116
|
+
const pipeline = this.buildBlurPipeline();
|
|
1117
|
+
const encoder = this.device.createCommandEncoder({
|
|
1118
|
+
label: "timeline-headless-blur-fold"
|
|
1119
|
+
});
|
|
1120
|
+
const pass = encoder.beginRenderPass({
|
|
1121
|
+
colorAttachments: [
|
|
1122
|
+
{
|
|
1123
|
+
view: accumulation.createView(),
|
|
1124
|
+
clearValue: { r: 0, g: 0, b: 0, a: 0 },
|
|
1125
|
+
// Only the first sample clears: every later one adds to what is there.
|
|
1126
|
+
loadOp: first ? "clear" : "load",
|
|
1127
|
+
storeOp: "store"
|
|
1128
|
+
}
|
|
1129
|
+
]
|
|
1130
|
+
});
|
|
1131
|
+
pass.setPipeline(pipeline);
|
|
1132
|
+
// `src × constant + dst`, so the weight rides in the blend constant and the
|
|
1133
|
+
// fragment shader stays a plain texel read.
|
|
1134
|
+
pass.setBlendConstant({ r: weight, g: weight, b: weight, a: weight });
|
|
1135
|
+
pass.setBindGroup(0, this.device.createBindGroup({
|
|
1136
|
+
layout: pipeline.getBindGroupLayout(0),
|
|
1137
|
+
entries: [{ binding: 0, resource: texture.createView() }]
|
|
1138
|
+
}));
|
|
1139
|
+
pass.draw(4);
|
|
1140
|
+
pass.end();
|
|
1141
|
+
this.device.queue.submit([encoder.finish()]);
|
|
1142
|
+
}
|
|
1143
|
+
/** Divide premultiplied colour by alpha into a readable RGBA8 texture. */
|
|
1144
|
+
resolvePremultiplied(source, encoder) {
|
|
1145
|
+
const target = this.resolvedTexture();
|
|
1146
|
+
const pipeline = this.buildResolvePipeline();
|
|
1147
|
+
const pass = encoder.beginRenderPass({
|
|
1148
|
+
colorAttachments: [
|
|
1149
|
+
{
|
|
1150
|
+
view: target.createView(),
|
|
1151
|
+
clearValue: { r: 0, g: 0, b: 0, a: 0 },
|
|
1152
|
+
loadOp: "clear",
|
|
1153
|
+
storeOp: "store"
|
|
1154
|
+
}
|
|
1155
|
+
]
|
|
1156
|
+
});
|
|
1157
|
+
pass.setPipeline(pipeline);
|
|
1158
|
+
pass.setBindGroup(0, this.device.createBindGroup({
|
|
1159
|
+
layout: pipeline.getBindGroupLayout(0),
|
|
1160
|
+
entries: [{ binding: 0, resource: source.createView() }]
|
|
1161
|
+
}));
|
|
1162
|
+
pass.draw(4);
|
|
1163
|
+
pass.end();
|
|
1164
|
+
return target;
|
|
1165
|
+
}
|
|
1166
|
+
blurAccumulationTexture() {
|
|
1167
|
+
let texture = this.blurAccumulation;
|
|
1168
|
+
if (!texture) {
|
|
1169
|
+
texture = this.device.createTexture({
|
|
1170
|
+
label: "timeline-headless-blur-accumulation",
|
|
1171
|
+
size: { width: this.width, height: this.height },
|
|
1172
|
+
format: BLUR_ACCUMULATION_FORMAT,
|
|
1173
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
|
|
1174
|
+
});
|
|
1175
|
+
this.blurAccumulation = texture;
|
|
1176
|
+
}
|
|
1177
|
+
return texture;
|
|
1178
|
+
}
|
|
1179
|
+
resolvedTexture() {
|
|
1180
|
+
let texture = this.resolveTarget;
|
|
1181
|
+
if (!texture) {
|
|
1182
|
+
texture = this.device.createTexture({
|
|
1183
|
+
label: "timeline-headless-resolve",
|
|
1184
|
+
size: { width: this.width, height: this.height },
|
|
1185
|
+
format: TEXTURE_FORMAT,
|
|
1186
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC
|
|
1187
|
+
});
|
|
1188
|
+
this.resolveTarget = texture;
|
|
1189
|
+
}
|
|
1190
|
+
return texture;
|
|
1191
|
+
}
|
|
1192
|
+
/** The accumulation pipeline, built on the first blurred frame. */
|
|
1193
|
+
buildBlurPipeline() {
|
|
1194
|
+
if (!this.blurAccumulatePipeline) {
|
|
1195
|
+
const module = this.device.createShaderModule({
|
|
1196
|
+
label: "timeline-headless-blur-fold",
|
|
1197
|
+
code: `${FULLSCREEN_QUAD_VERTEX}\n${BLIT_FRAGMENT}`
|
|
1198
|
+
});
|
|
1199
|
+
this.blurAccumulatePipeline = this.device.createRenderPipeline({
|
|
1200
|
+
label: "timeline-headless-blur-fold",
|
|
1201
|
+
layout: "auto",
|
|
1202
|
+
vertex: { module, entryPoint: "vs_main" },
|
|
1203
|
+
fragment: {
|
|
1204
|
+
module,
|
|
1205
|
+
entryPoint: "fs_blit",
|
|
1206
|
+
targets: [
|
|
1207
|
+
{
|
|
1208
|
+
format: BLUR_ACCUMULATION_FORMAT,
|
|
1209
|
+
blend: {
|
|
1210
|
+
color: {
|
|
1211
|
+
srcFactor: "constant",
|
|
1212
|
+
dstFactor: "one",
|
|
1213
|
+
operation: "add"
|
|
1214
|
+
},
|
|
1215
|
+
alpha: {
|
|
1216
|
+
srcFactor: "constant",
|
|
1217
|
+
dstFactor: "one",
|
|
1218
|
+
operation: "add"
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
]
|
|
1223
|
+
},
|
|
1224
|
+
primitive: { topology: "triangle-strip" }
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
return this.blurAccumulatePipeline;
|
|
1228
|
+
}
|
|
1229
|
+
buildResolvePipeline() {
|
|
1230
|
+
if (!this.resolvePipeline) {
|
|
1231
|
+
const module = this.device.createShaderModule({
|
|
1232
|
+
label: "timeline-headless-resolve",
|
|
1233
|
+
code: `${FULLSCREEN_QUAD_VERTEX}\n${UNPREMULTIPLY_FRAGMENT}`
|
|
1234
|
+
});
|
|
1235
|
+
this.resolvePipeline = this.device.createRenderPipeline({
|
|
1236
|
+
label: "timeline-headless-resolve",
|
|
1237
|
+
layout: "auto",
|
|
1238
|
+
vertex: { module, entryPoint: "vs_main" },
|
|
1239
|
+
fragment: {
|
|
1240
|
+
module,
|
|
1241
|
+
entryPoint: "fs_unpremultiply",
|
|
1242
|
+
targets: [{ format: TEXTURE_FORMAT }]
|
|
1243
|
+
},
|
|
1244
|
+
primitive: { topology: "triangle-strip" }
|
|
1245
|
+
});
|
|
1246
|
+
}
|
|
1247
|
+
return this.resolvePipeline;
|
|
1248
|
+
}
|
|
1249
|
+
/** The buffer this frame reads back through — the one the last frame did not. */
|
|
1250
|
+
nextReadback() {
|
|
1251
|
+
const buffer = this.readbacks[this.readbackIndex];
|
|
1252
|
+
this.readbackIndex = this.readbackIndex === 0 ? 1 : 0;
|
|
1253
|
+
return buffer;
|
|
1254
|
+
}
|
|
1255
|
+
async readMapped(readback) {
|
|
1256
|
+
await readback.mapAsync(GPUMapMode.READ);
|
|
1257
|
+
try {
|
|
1258
|
+
const mapped = new Uint8Array(readback.getMappedRange());
|
|
1259
|
+
const rgba = new Uint8Array(this.width * this.height * 4);
|
|
1260
|
+
const rowBytes = this.width * 4;
|
|
1261
|
+
for (let row = 0; row < this.height; row++) {
|
|
1262
|
+
rgba.set(mapped.subarray(row * this.bytesPerRow, row * this.bytesPerRow + rowBytes), row * rowBytes);
|
|
1263
|
+
}
|
|
1264
|
+
return rgba;
|
|
1265
|
+
}
|
|
1266
|
+
finally {
|
|
1267
|
+
readback.unmap();
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
uploadPixels(id, pixels) {
|
|
1271
|
+
const { rgba, width, height } = pixels;
|
|
1272
|
+
if (width <= 0 || height <= 0)
|
|
1273
|
+
return null;
|
|
1274
|
+
if (rgba.length < width * height * 4)
|
|
1275
|
+
return null;
|
|
1276
|
+
let entry = this.sources.get(id);
|
|
1277
|
+
if (!entry || entry.width !== width || entry.height !== height) {
|
|
1278
|
+
entry?.texture.destroy();
|
|
1279
|
+
entry = {
|
|
1280
|
+
texture: this.device.createTexture({
|
|
1281
|
+
label: `timeline-headless-source-${id}`,
|
|
1282
|
+
size: { width, height },
|
|
1283
|
+
format: TEXTURE_FORMAT,
|
|
1284
|
+
usage: GPUTextureUsage.TEXTURE_BINDING |
|
|
1285
|
+
GPUTextureUsage.COPY_DST |
|
|
1286
|
+
GPUTextureUsage.COPY_SRC |
|
|
1287
|
+
GPUTextureUsage.RENDER_ATTACHMENT
|
|
1288
|
+
}),
|
|
1289
|
+
width,
|
|
1290
|
+
height,
|
|
1291
|
+
version: ""
|
|
1292
|
+
};
|
|
1293
|
+
this.sources.set(id, entry);
|
|
1294
|
+
}
|
|
1295
|
+
const version = pixels.version;
|
|
1296
|
+
if (version === undefined || entry.version !== version) {
|
|
1297
|
+
// Re-wrap as an ArrayBuffer-backed view: `writeTexture` rejects
|
|
1298
|
+
// SharedArrayBuffer-backed sources under the DOM WebGPU typings.
|
|
1299
|
+
const data = new Uint8Array(rgba.buffer, rgba.byteOffset, rgba.byteLength);
|
|
1300
|
+
this.device.queue.writeTexture({ texture: entry.texture }, data, { bytesPerRow: width * 4, rowsPerImage: height }, { width, height });
|
|
1301
|
+
entry.version = version ?? "";
|
|
1302
|
+
}
|
|
1303
|
+
return entry;
|
|
1304
|
+
}
|
|
1305
|
+
dispose() {
|
|
1306
|
+
for (const entry of this.sources.values())
|
|
1307
|
+
entry.texture.destroy();
|
|
1308
|
+
this.sources.clear();
|
|
1309
|
+
this.blurAccumulation?.destroy();
|
|
1310
|
+
this.blurAccumulation = null;
|
|
1311
|
+
this.resolveTarget?.destroy();
|
|
1312
|
+
this.resolveTarget = null;
|
|
1313
|
+
this.compositor.dispose();
|
|
1314
|
+
for (const readback of this.readbacks)
|
|
1315
|
+
readback.destroy();
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* A dip colour to bytes. The GPU path needs the channels a Canvas 2D
|
|
1320
|
+
* `fillStyle` would parse for it, so it reads the same CSS grammar the 2D path
|
|
1321
|
+
* gets for free; an unparseable string dips to black rather than not at all.
|
|
1322
|
+
*/
|
|
1323
|
+
function dipColorBytes(color) {
|
|
1324
|
+
const { r, g, b } = parseCssColorOrBlack(color);
|
|
1325
|
+
return {
|
|
1326
|
+
r: Math.round(r * 255),
|
|
1327
|
+
g: Math.round(g * 255),
|
|
1328
|
+
b: Math.round(b * 255)
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
//# sourceMappingURL=frameCompositor.js.map
|