@vfx-js/effects 1.4.4 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/THIRD_PARTY_NOTICES.md +61 -0
- package/lib/cjs/_bloom-common.d.ts +31 -0
- package/lib/cjs/_bloom-common.js +101 -0
- package/lib/cjs/_bloom-common.js.map +1 -0
- package/lib/cjs/_bubble-fill.d.ts +126 -0
- package/lib/cjs/_bubble-fill.js +1044 -0
- package/lib/cjs/_bubble-fill.js.map +1 -0
- package/lib/cjs/_bubble-kernel-source.d.ts +2 -0
- package/lib/cjs/_bubble-kernel-source.js +8 -0
- package/lib/cjs/_bubble-kernel-source.js.map +1 -0
- package/lib/cjs/_holo/data/kernels.d.ts +4 -0
- package/lib/cjs/_holo/data/kernels.js +10 -0
- package/lib/cjs/_holo/data/kernels.js.map +1 -0
- package/lib/cjs/_holo/data/looks.d.ts +2 -0
- package/lib/cjs/_holo/data/looks.js +595 -0
- package/lib/cjs/_holo/data/looks.js.map +1 -0
- package/lib/cjs/_holo/data/ltc.d.ts +2 -0
- package/lib/cjs/_holo/data/ltc.js +11 -0
- package/lib/cjs/_holo/data/ltc.js.map +1 -0
- package/lib/cjs/_holo/data/material-presets.d.ts +3 -0
- package/lib/cjs/_holo/data/material-presets.js +75 -0
- package/lib/cjs/_holo/data/material-presets.js.map +1 -0
- package/lib/cjs/_holo/data/not-ported.d.ts +5 -0
- package/lib/cjs/_holo/data/not-ported.js +190 -0
- package/lib/cjs/_holo/data/not-ported.js.map +1 -0
- package/lib/cjs/_holo/data/params.d.ts +4 -0
- package/lib/cjs/_holo/data/params.js +1641 -0
- package/lib/cjs/_holo/data/params.js.map +1 -0
- package/lib/cjs/_holo/data/starting-points.d.ts +199 -0
- package/lib/cjs/_holo/data/starting-points.js +193 -0
- package/lib/cjs/_holo/data/starting-points.js.map +1 -0
- package/lib/cjs/_holo/data/studio-presets.d.ts +2 -0
- package/lib/cjs/_holo/data/studio-presets.js +177 -0
- package/lib/cjs/_holo/data/studio-presets.js.map +1 -0
- package/lib/cjs/_holo/emboss-assets.d.ts +55 -0
- package/lib/cjs/_holo/emboss-assets.js +155 -0
- package/lib/cjs/_holo/emboss-assets.js.map +1 -0
- package/lib/cjs/_holo/glare.d.ts +15 -0
- package/lib/cjs/_holo/glare.js +125 -0
- package/lib/cjs/_holo/glare.js.map +1 -0
- package/lib/cjs/_holo/glsl/coat.d.ts +2 -0
- package/lib/cjs/_holo/glsl/coat.js +32 -0
- package/lib/cjs/_holo/glsl/coat.js.map +1 -0
- package/lib/cjs/_holo/glsl/common.d.ts +2 -0
- package/lib/cjs/_holo/glsl/common.js +141 -0
- package/lib/cjs/_holo/glsl/common.js.map +1 -0
- package/lib/cjs/_holo/glsl/emboss.d.ts +2 -0
- package/lib/cjs/_holo/glsl/emboss.js +246 -0
- package/lib/cjs/_holo/glsl/emboss.js.map +1 -0
- package/lib/cjs/_holo/glsl/env.d.ts +2 -0
- package/lib/cjs/_holo/glsl/env.js +52 -0
- package/lib/cjs/_holo/glsl/env.js.map +1 -0
- package/lib/cjs/_holo/glsl/glare-down.d.ts +2 -0
- package/lib/cjs/_holo/glsl/glare-down.js +65 -0
- package/lib/cjs/_holo/glsl/glare-down.js.map +1 -0
- package/lib/cjs/_holo/glsl/glare-up.d.ts +2 -0
- package/lib/cjs/_holo/glsl/glare-up.js +18 -0
- package/lib/cjs/_holo/glsl/glare-up.js.map +1 -0
- package/lib/cjs/_holo/glsl/glitter.d.ts +2 -0
- package/lib/cjs/_holo/glsl/glitter.js +325 -0
- package/lib/cjs/_holo/glsl/glitter.js.map +1 -0
- package/lib/cjs/_holo/glsl/grating.d.ts +2 -0
- package/lib/cjs/_holo/glsl/grating.js +240 -0
- package/lib/cjs/_holo/glsl/grating.js.map +1 -0
- package/lib/cjs/_holo/glsl/holo-emboss.d.ts +2 -0
- package/lib/cjs/_holo/glsl/holo-emboss.js +296 -0
- package/lib/cjs/_holo/glsl/holo-emboss.js.map +1 -0
- package/lib/cjs/_holo/glsl/holo-nebula.d.ts +2 -0
- package/lib/cjs/_holo/glsl/holo-nebula.js +186 -0
- package/lib/cjs/_holo/glsl/holo-nebula.js.map +1 -0
- package/lib/cjs/_holo/glsl/holo-prism.d.ts +2 -0
- package/lib/cjs/_holo/glsl/holo-prism.js +183 -0
- package/lib/cjs/_holo/glsl/holo-prism.js.map +1 -0
- package/lib/cjs/_holo/glsl/holo-shatter.d.ts +2 -0
- package/lib/cjs/_holo/glsl/holo-shatter.js +328 -0
- package/lib/cjs/_holo/glsl/holo-shatter.js.map +1 -0
- package/lib/cjs/_holo/glsl/holo-sparkle.d.ts +2 -0
- package/lib/cjs/_holo/glsl/holo-sparkle.js +235 -0
- package/lib/cjs/_holo/glsl/holo-sparkle.js.map +1 -0
- package/lib/cjs/_holo/glsl/holo-vortex.d.ts +2 -0
- package/lib/cjs/_holo/glsl/holo-vortex.js +201 -0
- package/lib/cjs/_holo/glsl/holo-vortex.js.map +1 -0
- package/lib/cjs/_holo/glsl/ibl.d.ts +2 -0
- package/lib/cjs/_holo/glsl/ibl.js +79 -0
- package/lib/cjs/_holo/glsl/ibl.js.map +1 -0
- package/lib/cjs/_holo/glsl/lights.d.ts +2 -0
- package/lib/cjs/_holo/glsl/lights.js +125 -0
- package/lib/cjs/_holo/glsl/lights.js.map +1 -0
- package/lib/cjs/_holo/glsl/ltc.d.ts +2 -0
- package/lib/cjs/_holo/glsl/ltc.js +66 -0
- package/lib/cjs/_holo/glsl/ltc.js.map +1 -0
- package/lib/cjs/_holo/glsl/output.d.ts +2 -0
- package/lib/cjs/_holo/glsl/output.js +113 -0
- package/lib/cjs/_holo/glsl/output.js.map +1 -0
- package/lib/cjs/_holo/glsl/paper.d.ts +2 -0
- package/lib/cjs/_holo/glsl/paper.js +165 -0
- package/lib/cjs/_holo/glsl/paper.js.map +1 -0
- package/lib/cjs/_holo/glsl/relief.d.ts +2 -0
- package/lib/cjs/_holo/glsl/relief.js +103 -0
- package/lib/cjs/_holo/glsl/relief.js.map +1 -0
- package/lib/cjs/_holo/glsl/sparkle.d.ts +2 -0
- package/lib/cjs/_holo/glsl/sparkle.js +279 -0
- package/lib/cjs/_holo/glsl/sparkle.js.map +1 -0
- package/lib/cjs/_holo/glsl/spectral.d.ts +2 -0
- package/lib/cjs/_holo/glsl/spectral.js +60 -0
- package/lib/cjs/_holo/glsl/spectral.js.map +1 -0
- package/lib/cjs/_holo/glsl/wear.d.ts +2 -0
- package/lib/cjs/_holo/glsl/wear.js +107 -0
- package/lib/cjs/_holo/glsl/wear.js.map +1 -0
- package/lib/cjs/_holo/ltc.d.ts +9 -0
- package/lib/cjs/_holo/ltc.js +56 -0
- package/lib/cjs/_holo/ltc.js.map +1 -0
- package/lib/cjs/_holo/materials/build.d.ts +32 -0
- package/lib/cjs/_holo/materials/build.js +36 -0
- package/lib/cjs/_holo/materials/build.js.map +1 -0
- package/lib/cjs/_holo/materials/emboss.d.ts +22 -0
- package/lib/cjs/_holo/materials/emboss.js +205 -0
- package/lib/cjs/_holo/materials/emboss.js.map +1 -0
- package/lib/cjs/_holo/materials/nebula.d.ts +4 -0
- package/lib/cjs/_holo/materials/nebula.js +105 -0
- package/lib/cjs/_holo/materials/nebula.js.map +1 -0
- package/lib/cjs/_holo/materials/prism.d.ts +2 -0
- package/lib/cjs/_holo/materials/prism.js +69 -0
- package/lib/cjs/_holo/materials/prism.js.map +1 -0
- package/lib/cjs/_holo/materials/registry.d.ts +11 -0
- package/lib/cjs/_holo/materials/registry.js +88 -0
- package/lib/cjs/_holo/materials/registry.js.map +1 -0
- package/lib/cjs/_holo/materials/shatter.d.ts +2 -0
- package/lib/cjs/_holo/materials/shatter.js +80 -0
- package/lib/cjs/_holo/materials/shatter.js.map +1 -0
- package/lib/cjs/_holo/materials/sparkle.d.ts +2 -0
- package/lib/cjs/_holo/materials/sparkle.js +108 -0
- package/lib/cjs/_holo/materials/sparkle.js.map +1 -0
- package/lib/cjs/_holo/materials/vortex.d.ts +2 -0
- package/lib/cjs/_holo/materials/vortex.js +85 -0
- package/lib/cjs/_holo/materials/vortex.js.map +1 -0
- package/lib/cjs/_holo/physics/emboss.d.ts +39 -0
- package/lib/cjs/_holo/physics/emboss.js +95 -0
- package/lib/cjs/_holo/physics/emboss.js.map +1 -0
- package/lib/cjs/_holo/physics/geometry.d.ts +109 -0
- package/lib/cjs/_holo/physics/geometry.js +252 -0
- package/lib/cjs/_holo/physics/geometry.js.map +1 -0
- package/lib/cjs/_holo/physics/grating.d.ts +86 -0
- package/lib/cjs/_holo/physics/grating.js +328 -0
- package/lib/cjs/_holo/physics/grating.js.map +1 -0
- package/lib/cjs/_holo/physics/sparkle.d.ts +143 -0
- package/lib/cjs/_holo/physics/sparkle.js +388 -0
- package/lib/cjs/_holo/physics/sparkle.js.map +1 -0
- package/lib/cjs/_holo/scene/env.d.ts +17 -0
- package/lib/cjs/_holo/scene/env.js +151 -0
- package/lib/cjs/_holo/scene/env.js.map +1 -0
- package/lib/cjs/_holo/scene/lights.d.ts +13 -0
- package/lib/cjs/_holo/scene/lights.js +211 -0
- package/lib/cjs/_holo/scene/lights.js.map +1 -0
- package/lib/cjs/_holo/scene/logo.d.ts +87 -0
- package/lib/cjs/_holo/scene/logo.js +655 -0
- package/lib/cjs/_holo/scene/logo.js.map +1 -0
- package/lib/cjs/_holo/scene/paper-maps.d.ts +26 -0
- package/lib/cjs/_holo/scene/paper-maps.js +391 -0
- package/lib/cjs/_holo/scene/paper-maps.js.map +1 -0
- package/lib/cjs/_holo/scene/pose.d.ts +31 -0
- package/lib/cjs/_holo/scene/pose.js +77 -0
- package/lib/cjs/_holo/scene/pose.js.map +1 -0
- package/lib/cjs/_holo/scene/relief.d.ts +24 -0
- package/lib/cjs/_holo/scene/relief.js +148 -0
- package/lib/cjs/_holo/scene/relief.js.map +1 -0
- package/lib/cjs/_holo/settings-types.d.ts +20 -0
- package/lib/cjs/_holo/settings-types.js +3 -0
- package/lib/cjs/_holo/settings-types.js.map +1 -0
- package/lib/cjs/_holo/settings.d.ts +83 -0
- package/lib/cjs/_holo/settings.js +375 -0
- package/lib/cjs/_holo/settings.js.map +1 -0
- package/lib/cjs/_holo/shader.d.ts +23 -0
- package/lib/cjs/_holo/shader.js +219 -0
- package/lib/cjs/_holo/shader.js.map +1 -0
- package/lib/cjs/_holo/spectral/atlas.d.ts +36 -0
- package/lib/cjs/_holo/spectral/atlas.js +114 -0
- package/lib/cjs/_holo/spectral/atlas.js.map +1 -0
- package/lib/cjs/_holo/spectral/cmf.d.ts +67 -0
- package/lib/cjs/_holo/spectral/cmf.js +244 -0
- package/lib/cjs/_holo/spectral/cmf.js.map +1 -0
- package/lib/cjs/_holo/spectral/float24.d.ts +8 -0
- package/lib/cjs/_holo/spectral/float24.js +70 -0
- package/lib/cjs/_holo/spectral/float24.js.map +1 -0
- package/lib/cjs/_holo/spectral/spd.d.ts +22 -0
- package/lib/cjs/_holo/spectral/spd.js +139 -0
- package/lib/cjs/_holo/spectral/spd.js.map +1 -0
- package/lib/cjs/_holo/spectral/tables.d.ts +62 -0
- package/lib/cjs/_holo/spectral/tables.js +386 -0
- package/lib/cjs/_holo/spectral/tables.js.map +1 -0
- package/lib/cjs/_holo/tier.d.ts +4 -0
- package/lib/cjs/_holo/tier.js +110 -0
- package/lib/cjs/_holo/tier.js.map +1 -0
- package/lib/cjs/_holo/types.d.ts +148 -0
- package/lib/cjs/_holo/types.js +14 -0
- package/lib/cjs/_holo/types.js.map +1 -0
- package/lib/cjs/_kernel-worker.d.ts +22 -0
- package/lib/cjs/_kernel-worker.js +174 -0
- package/lib/cjs/_kernel-worker.js.map +1 -0
- package/lib/cjs/_orbit-camera.d.ts +175 -0
- package/lib/cjs/_orbit-camera.js +366 -0
- package/lib/cjs/_orbit-camera.js.map +1 -0
- package/lib/cjs/_pad.d.ts +2 -0
- package/lib/cjs/_pad.js +11 -0
- package/lib/cjs/_pad.js.map +1 -1
- package/lib/cjs/_scene3d.d.ts +101 -0
- package/lib/cjs/_scene3d.js +794 -0
- package/lib/cjs/_scene3d.js.map +1 -0
- package/lib/cjs/_shape-kernel-source.d.ts +2 -0
- package/lib/cjs/_shape-kernel-source.js +8 -0
- package/lib/cjs/_shape-kernel-source.js.map +1 -0
- package/lib/cjs/_shape-worker.d.ts +8 -0
- package/lib/cjs/_shape-worker.js +27 -0
- package/lib/cjs/_shape-worker.js.map +1 -0
- package/lib/cjs/_silhouette.d.ts +88 -0
- package/lib/cjs/_silhouette.js +441 -0
- package/lib/cjs/_silhouette.js.map +1 -0
- package/lib/cjs/_simplex3.d.ts +2 -0
- package/lib/cjs/_simplex3.js +160 -0
- package/lib/cjs/_simplex3.js.map +1 -0
- package/lib/cjs/_source.d.ts +80 -0
- package/lib/cjs/_source.js +192 -0
- package/lib/cjs/_source.js.map +1 -0
- package/lib/cjs/_sphere-foam.d.ts +34 -0
- package/lib/cjs/_sphere-foam.js +135 -0
- package/lib/cjs/_sphere-foam.js.map +1 -0
- package/lib/cjs/_thin-film.d.ts +26 -0
- package/lib/cjs/_thin-film.js +146 -0
- package/lib/cjs/_thin-film.js.map +1 -0
- package/lib/cjs/bloom.js +40 -106
- package/lib/cjs/bloom.js.map +1 -1
- package/lib/cjs/bubble.d.ts +284 -0
- package/lib/cjs/bubble.js +1820 -0
- package/lib/cjs/bubble.js.map +1 -0
- package/lib/cjs/glass.d.ts +254 -0
- package/lib/cjs/glass.js +981 -0
- package/lib/cjs/glass.js.map +1 -0
- package/lib/cjs/holo-static.d.ts +3 -0
- package/lib/cjs/holo-static.js +29 -0
- package/lib/cjs/holo-static.js.map +1 -0
- package/lib/cjs/holo.d.ts +401 -0
- package/lib/cjs/holo.js +1613 -0
- package/lib/cjs/holo.js.map +1 -0
- package/lib/cjs/index.d.ts +18 -9
- package/lib/cjs/index.js +12 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/jpeg-glitch.js +32 -29
- package/lib/cjs/jpeg-glitch.js.map +1 -1
- package/lib/cjs/matrix.d.ts +1 -1
- package/lib/cjs/package.json +20 -5
- package/lib/cjs/swirl-particle.d.ts +257 -0
- package/lib/cjs/swirl-particle.js +2346 -0
- package/lib/cjs/swirl-particle.js.map +1 -0
- package/lib/cjs/voronoi.js +2 -75
- package/lib/cjs/voronoi.js.map +1 -1
- package/lib/esm/_bloom-common.d.ts +31 -0
- package/lib/esm/_bloom-common.js +95 -0
- package/lib/esm/_bloom-common.js.map +1 -0
- package/lib/esm/_bubble-fill.d.ts +126 -0
- package/lib/esm/_bubble-fill.js +1039 -0
- package/lib/esm/_bubble-fill.js.map +1 -0
- package/lib/esm/_bubble-kernel-source.d.ts +2 -0
- package/lib/esm/_bubble-kernel-source.js +5 -0
- package/lib/esm/_bubble-kernel-source.js.map +1 -0
- package/lib/esm/_holo/data/kernels.d.ts +4 -0
- package/lib/esm/_holo/data/kernels.js +7 -0
- package/lib/esm/_holo/data/kernels.js.map +1 -0
- package/lib/esm/_holo/data/looks.d.ts +2 -0
- package/lib/esm/_holo/data/looks.js +592 -0
- package/lib/esm/_holo/data/looks.js.map +1 -0
- package/lib/esm/_holo/data/ltc.d.ts +2 -0
- package/lib/esm/_holo/data/ltc.js +8 -0
- package/lib/esm/_holo/data/ltc.js.map +1 -0
- package/lib/esm/_holo/data/material-presets.d.ts +3 -0
- package/lib/esm/_holo/data/material-presets.js +72 -0
- package/lib/esm/_holo/data/material-presets.js.map +1 -0
- package/lib/esm/_holo/data/not-ported.d.ts +5 -0
- package/lib/esm/_holo/data/not-ported.js +187 -0
- package/lib/esm/_holo/data/not-ported.js.map +1 -0
- package/lib/esm/_holo/data/params.d.ts +4 -0
- package/lib/esm/_holo/data/params.js +1638 -0
- package/lib/esm/_holo/data/params.js.map +1 -0
- package/lib/esm/_holo/data/starting-points.d.ts +199 -0
- package/lib/esm/_holo/data/starting-points.js +190 -0
- package/lib/esm/_holo/data/starting-points.js.map +1 -0
- package/lib/esm/_holo/data/studio-presets.d.ts +2 -0
- package/lib/esm/_holo/data/studio-presets.js +174 -0
- package/lib/esm/_holo/data/studio-presets.js.map +1 -0
- package/lib/esm/_holo/emboss-assets.d.ts +55 -0
- package/lib/esm/_holo/emboss-assets.js +150 -0
- package/lib/esm/_holo/emboss-assets.js.map +1 -0
- package/lib/esm/_holo/glare.d.ts +15 -0
- package/lib/esm/_holo/glare.js +117 -0
- package/lib/esm/_holo/glare.js.map +1 -0
- package/lib/esm/_holo/glsl/coat.d.ts +2 -0
- package/lib/esm/_holo/glsl/coat.js +30 -0
- package/lib/esm/_holo/glsl/coat.js.map +1 -0
- package/lib/esm/_holo/glsl/common.d.ts +2 -0
- package/lib/esm/_holo/glsl/common.js +139 -0
- package/lib/esm/_holo/glsl/common.js.map +1 -0
- package/lib/esm/_holo/glsl/emboss.d.ts +2 -0
- package/lib/esm/_holo/glsl/emboss.js +244 -0
- package/lib/esm/_holo/glsl/emboss.js.map +1 -0
- package/lib/esm/_holo/glsl/env.d.ts +2 -0
- package/lib/esm/_holo/glsl/env.js +50 -0
- package/lib/esm/_holo/glsl/env.js.map +1 -0
- package/lib/esm/_holo/glsl/glare-down.d.ts +2 -0
- package/lib/esm/_holo/glsl/glare-down.js +63 -0
- package/lib/esm/_holo/glsl/glare-down.js.map +1 -0
- package/lib/esm/_holo/glsl/glare-up.d.ts +2 -0
- package/lib/esm/_holo/glsl/glare-up.js +16 -0
- package/lib/esm/_holo/glsl/glare-up.js.map +1 -0
- package/lib/esm/_holo/glsl/glitter.d.ts +2 -0
- package/lib/esm/_holo/glsl/glitter.js +323 -0
- package/lib/esm/_holo/glsl/glitter.js.map +1 -0
- package/lib/esm/_holo/glsl/grating.d.ts +2 -0
- package/lib/esm/_holo/glsl/grating.js +238 -0
- package/lib/esm/_holo/glsl/grating.js.map +1 -0
- package/lib/esm/_holo/glsl/holo-emboss.d.ts +2 -0
- package/lib/esm/_holo/glsl/holo-emboss.js +294 -0
- package/lib/esm/_holo/glsl/holo-emboss.js.map +1 -0
- package/lib/esm/_holo/glsl/holo-nebula.d.ts +2 -0
- package/lib/esm/_holo/glsl/holo-nebula.js +184 -0
- package/lib/esm/_holo/glsl/holo-nebula.js.map +1 -0
- package/lib/esm/_holo/glsl/holo-prism.d.ts +2 -0
- package/lib/esm/_holo/glsl/holo-prism.js +181 -0
- package/lib/esm/_holo/glsl/holo-prism.js.map +1 -0
- package/lib/esm/_holo/glsl/holo-shatter.d.ts +2 -0
- package/lib/esm/_holo/glsl/holo-shatter.js +326 -0
- package/lib/esm/_holo/glsl/holo-shatter.js.map +1 -0
- package/lib/esm/_holo/glsl/holo-sparkle.d.ts +2 -0
- package/lib/esm/_holo/glsl/holo-sparkle.js +233 -0
- package/lib/esm/_holo/glsl/holo-sparkle.js.map +1 -0
- package/lib/esm/_holo/glsl/holo-vortex.d.ts +2 -0
- package/lib/esm/_holo/glsl/holo-vortex.js +199 -0
- package/lib/esm/_holo/glsl/holo-vortex.js.map +1 -0
- package/lib/esm/_holo/glsl/ibl.d.ts +2 -0
- package/lib/esm/_holo/glsl/ibl.js +77 -0
- package/lib/esm/_holo/glsl/ibl.js.map +1 -0
- package/lib/esm/_holo/glsl/lights.d.ts +2 -0
- package/lib/esm/_holo/glsl/lights.js +123 -0
- package/lib/esm/_holo/glsl/lights.js.map +1 -0
- package/lib/esm/_holo/glsl/ltc.d.ts +2 -0
- package/lib/esm/_holo/glsl/ltc.js +64 -0
- package/lib/esm/_holo/glsl/ltc.js.map +1 -0
- package/lib/esm/_holo/glsl/output.d.ts +2 -0
- package/lib/esm/_holo/glsl/output.js +111 -0
- package/lib/esm/_holo/glsl/output.js.map +1 -0
- package/lib/esm/_holo/glsl/paper.d.ts +2 -0
- package/lib/esm/_holo/glsl/paper.js +163 -0
- package/lib/esm/_holo/glsl/paper.js.map +1 -0
- package/lib/esm/_holo/glsl/relief.d.ts +2 -0
- package/lib/esm/_holo/glsl/relief.js +101 -0
- package/lib/esm/_holo/glsl/relief.js.map +1 -0
- package/lib/esm/_holo/glsl/sparkle.d.ts +2 -0
- package/lib/esm/_holo/glsl/sparkle.js +277 -0
- package/lib/esm/_holo/glsl/sparkle.js.map +1 -0
- package/lib/esm/_holo/glsl/spectral.d.ts +2 -0
- package/lib/esm/_holo/glsl/spectral.js +58 -0
- package/lib/esm/_holo/glsl/spectral.js.map +1 -0
- package/lib/esm/_holo/glsl/wear.d.ts +2 -0
- package/lib/esm/_holo/glsl/wear.js +105 -0
- package/lib/esm/_holo/glsl/wear.js.map +1 -0
- package/lib/esm/_holo/ltc.d.ts +9 -0
- package/lib/esm/_holo/ltc.js +52 -0
- package/lib/esm/_holo/ltc.js.map +1 -0
- package/lib/esm/_holo/materials/build.d.ts +32 -0
- package/lib/esm/_holo/materials/build.js +30 -0
- package/lib/esm/_holo/materials/build.js.map +1 -0
- package/lib/esm/_holo/materials/emboss.d.ts +22 -0
- package/lib/esm/_holo/materials/emboss.js +198 -0
- package/lib/esm/_holo/materials/emboss.js.map +1 -0
- package/lib/esm/_holo/materials/nebula.d.ts +4 -0
- package/lib/esm/_holo/materials/nebula.js +98 -0
- package/lib/esm/_holo/materials/nebula.js.map +1 -0
- package/lib/esm/_holo/materials/prism.d.ts +2 -0
- package/lib/esm/_holo/materials/prism.js +63 -0
- package/lib/esm/_holo/materials/prism.js.map +1 -0
- package/lib/esm/_holo/materials/registry.d.ts +11 -0
- package/lib/esm/_holo/materials/registry.js +48 -0
- package/lib/esm/_holo/materials/registry.js.map +1 -0
- package/lib/esm/_holo/materials/shatter.d.ts +2 -0
- package/lib/esm/_holo/materials/shatter.js +74 -0
- package/lib/esm/_holo/materials/shatter.js.map +1 -0
- package/lib/esm/_holo/materials/sparkle.d.ts +2 -0
- package/lib/esm/_holo/materials/sparkle.js +102 -0
- package/lib/esm/_holo/materials/sparkle.js.map +1 -0
- package/lib/esm/_holo/materials/vortex.d.ts +2 -0
- package/lib/esm/_holo/materials/vortex.js +79 -0
- package/lib/esm/_holo/materials/vortex.js.map +1 -0
- package/lib/esm/_holo/physics/emboss.d.ts +39 -0
- package/lib/esm/_holo/physics/emboss.js +89 -0
- package/lib/esm/_holo/physics/emboss.js.map +1 -0
- package/lib/esm/_holo/physics/geometry.d.ts +109 -0
- package/lib/esm/_holo/physics/geometry.js +228 -0
- package/lib/esm/_holo/physics/geometry.js.map +1 -0
- package/lib/esm/_holo/physics/grating.d.ts +86 -0
- package/lib/esm/_holo/physics/grating.js +313 -0
- package/lib/esm/_holo/physics/grating.js.map +1 -0
- package/lib/esm/_holo/physics/sparkle.d.ts +143 -0
- package/lib/esm/_holo/physics/sparkle.js +360 -0
- package/lib/esm/_holo/physics/sparkle.js.map +1 -0
- package/lib/esm/_holo/scene/env.d.ts +17 -0
- package/lib/esm/_holo/scene/env.js +141 -0
- package/lib/esm/_holo/scene/env.js.map +1 -0
- package/lib/esm/_holo/scene/lights.d.ts +13 -0
- package/lib/esm/_holo/scene/lights.js +204 -0
- package/lib/esm/_holo/scene/lights.js.map +1 -0
- package/lib/esm/_holo/scene/logo.d.ts +87 -0
- package/lib/esm/_holo/scene/logo.js +645 -0
- package/lib/esm/_holo/scene/logo.js.map +1 -0
- package/lib/esm/_holo/scene/paper-maps.d.ts +26 -0
- package/lib/esm/_holo/scene/paper-maps.js +387 -0
- package/lib/esm/_holo/scene/paper-maps.js.map +1 -0
- package/lib/esm/_holo/scene/pose.d.ts +31 -0
- package/lib/esm/_holo/scene/pose.js +71 -0
- package/lib/esm/_holo/scene/pose.js.map +1 -0
- package/lib/esm/_holo/scene/relief.d.ts +24 -0
- package/lib/esm/_holo/scene/relief.js +142 -0
- package/lib/esm/_holo/scene/relief.js.map +1 -0
- package/lib/esm/_holo/settings-types.d.ts +20 -0
- package/lib/esm/_holo/settings-types.js +2 -0
- package/lib/esm/_holo/settings-types.js.map +1 -0
- package/lib/esm/_holo/settings.d.ts +83 -0
- package/lib/esm/_holo/settings.js +358 -0
- package/lib/esm/_holo/settings.js.map +1 -0
- package/lib/esm/_holo/shader.d.ts +23 -0
- package/lib/esm/_holo/shader.js +211 -0
- package/lib/esm/_holo/shader.js.map +1 -0
- package/lib/esm/_holo/spectral/atlas.d.ts +36 -0
- package/lib/esm/_holo/spectral/atlas.js +110 -0
- package/lib/esm/_holo/spectral/atlas.js.map +1 -0
- package/lib/esm/_holo/spectral/cmf.d.ts +67 -0
- package/lib/esm/_holo/spectral/cmf.js +230 -0
- package/lib/esm/_holo/spectral/cmf.js.map +1 -0
- package/lib/esm/_holo/spectral/float24.d.ts +8 -0
- package/lib/esm/_holo/spectral/float24.js +64 -0
- package/lib/esm/_holo/spectral/float24.js.map +1 -0
- package/lib/esm/_holo/spectral/spd.d.ts +22 -0
- package/lib/esm/_holo/spectral/spd.js +130 -0
- package/lib/esm/_holo/spectral/spd.js.map +1 -0
- package/lib/esm/_holo/spectral/tables.d.ts +62 -0
- package/lib/esm/_holo/spectral/tables.js +372 -0
- package/lib/esm/_holo/spectral/tables.js.map +1 -0
- package/lib/esm/_holo/tier.d.ts +4 -0
- package/lib/esm/_holo/tier.js +106 -0
- package/lib/esm/_holo/tier.js.map +1 -0
- package/lib/esm/_holo/types.d.ts +148 -0
- package/lib/esm/_holo/types.js +11 -0
- package/lib/esm/_holo/types.js.map +1 -0
- package/lib/esm/_kernel-worker.d.ts +22 -0
- package/lib/esm/_kernel-worker.js +169 -0
- package/lib/esm/_kernel-worker.js.map +1 -0
- package/lib/esm/_orbit-camera.d.ts +175 -0
- package/lib/esm/_orbit-camera.js +360 -0
- package/lib/esm/_orbit-camera.js.map +1 -0
- package/lib/esm/_pad.d.ts +2 -0
- package/lib/esm/_pad.js +10 -0
- package/lib/esm/_pad.js.map +1 -1
- package/lib/esm/_scene3d.d.ts +101 -0
- package/lib/esm/_scene3d.js +783 -0
- package/lib/esm/_scene3d.js.map +1 -0
- package/lib/esm/_shape-kernel-source.d.ts +2 -0
- package/lib/esm/_shape-kernel-source.js +5 -0
- package/lib/esm/_shape-kernel-source.js.map +1 -0
- package/lib/esm/_shape-worker.d.ts +8 -0
- package/lib/esm/_shape-worker.js +23 -0
- package/lib/esm/_shape-worker.js.map +1 -0
- package/lib/esm/_silhouette.d.ts +88 -0
- package/lib/esm/_silhouette.js +436 -0
- package/lib/esm/_silhouette.js.map +1 -0
- package/lib/esm/_simplex3.d.ts +2 -0
- package/lib/esm/_simplex3.js +157 -0
- package/lib/esm/_simplex3.js.map +1 -0
- package/lib/esm/_source.d.ts +80 -0
- package/lib/esm/_source.js +187 -0
- package/lib/esm/_source.js.map +1 -0
- package/lib/esm/_sphere-foam.d.ts +34 -0
- package/lib/esm/_sphere-foam.js +131 -0
- package/lib/esm/_sphere-foam.js.map +1 -0
- package/lib/esm/_thin-film.d.ts +26 -0
- package/lib/esm/_thin-film.js +140 -0
- package/lib/esm/_thin-film.js.map +1 -0
- package/lib/esm/bloom.js +40 -106
- package/lib/esm/bloom.js.map +1 -1
- package/lib/esm/bubble.d.ts +284 -0
- package/lib/esm/bubble.js +1816 -0
- package/lib/esm/bubble.js.map +1 -0
- package/lib/esm/glass.d.ts +254 -0
- package/lib/esm/glass.js +977 -0
- package/lib/esm/glass.js.map +1 -0
- package/lib/esm/holo-static.d.ts +3 -0
- package/lib/esm/holo-static.js +13 -0
- package/lib/esm/holo-static.js.map +1 -0
- package/lib/esm/holo.d.ts +401 -0
- package/lib/esm/holo.js +1606 -0
- package/lib/esm/holo.js.map +1 -0
- package/lib/esm/index.d.ts +18 -9
- package/lib/esm/index.js +7 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/jpeg-glitch.js +32 -29
- package/lib/esm/jpeg-glitch.js.map +1 -1
- package/lib/esm/matrix.d.ts +1 -1
- package/lib/esm/package.json +20 -5
- package/lib/esm/swirl-particle.d.ts +257 -0
- package/lib/esm/swirl-particle.js +2342 -0
- package/lib/esm/swirl-particle.js.map +1 -0
- package/lib/esm/voronoi.js +2 -75
- package/lib/esm/voronoi.js.map +1 -1
- package/package.json +38 -11
package/lib/cjs/holo.js
ADDED
|
@@ -0,0 +1,1613 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HoloEffect = void 0;
|
|
7
|
+
const _capture_js_1 = require("./_capture.js");
|
|
8
|
+
const looks_js_1 = require("./_holo/data/looks.js");
|
|
9
|
+
const material_presets_js_1 = require("./_holo/data/material-presets.js");
|
|
10
|
+
const params_js_1 = require("./_holo/data/params.js");
|
|
11
|
+
const starting_points_js_1 = require("./_holo/data/starting-points.js");
|
|
12
|
+
const studio_presets_js_1 = require("./_holo/data/studio-presets.js");
|
|
13
|
+
const glare_js_1 = require("./_holo/glare.js");
|
|
14
|
+
const output_js_1 = __importDefault(require("./_holo/glsl/output.js"));
|
|
15
|
+
const ltc_js_1 = require("./_holo/ltc.js");
|
|
16
|
+
const registry_js_1 = require("./_holo/materials/registry.js");
|
|
17
|
+
const geometry_js_1 = require("./_holo/physics/geometry.js");
|
|
18
|
+
const grating_js_1 = require("./_holo/physics/grating.js");
|
|
19
|
+
const env_js_1 = require("./_holo/scene/env.js");
|
|
20
|
+
const lights_js_1 = require("./_holo/scene/lights.js");
|
|
21
|
+
const pose_js_1 = require("./_holo/scene/pose.js");
|
|
22
|
+
const relief_js_1 = require("./_holo/scene/relief.js");
|
|
23
|
+
const settings_js_1 = require("./_holo/settings.js");
|
|
24
|
+
const shader_js_1 = require("./_holo/shader.js");
|
|
25
|
+
const atlas_js_1 = require("./_holo/spectral/atlas.js");
|
|
26
|
+
const float24_js_1 = require("./_holo/spectral/float24.js");
|
|
27
|
+
const tier_js_1 = require("./_holo/tier.js");
|
|
28
|
+
const types_js_1 = require("./_holo/types.js");
|
|
29
|
+
const DEFAULT_COMPOSED = {
|
|
30
|
+
material: "prism",
|
|
31
|
+
settings: {},
|
|
32
|
+
quality: "medium",
|
|
33
|
+
structureScale: 1,
|
|
34
|
+
};
|
|
35
|
+
const DEFAULT_PARAMS = {
|
|
36
|
+
holo: [],
|
|
37
|
+
sourceChannel: "alpha",
|
|
38
|
+
ink: 0,
|
|
39
|
+
flat: false,
|
|
40
|
+
sizeMm: null,
|
|
41
|
+
antialias: true,
|
|
42
|
+
};
|
|
43
|
+
const COMPOSED_KEYS = new Set(["material", "quality", "structureScale"]);
|
|
44
|
+
// Keys that are not params, e.g. `pointer` given as in the other effects:
|
|
45
|
+
// it goes in `holo`.
|
|
46
|
+
function warnUnknownParams(p) {
|
|
47
|
+
for (const k of Object.keys(p)) {
|
|
48
|
+
if (Object.hasOwn(DEFAULT_PARAMS, k)) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
(0, settings_js_1.warnOnce)(COMPOSED_KEYS.has(k) || SCENE_KEYS.has(k) || k === "settings"
|
|
52
|
+
? `HoloEffect: "${k}" goes in \`holo\`: { holo: { ${k} } }; ignored.`
|
|
53
|
+
: `HoloEffect: unknown param "${k}"; ignored.`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const SCENE_KEYS = new Set([
|
|
57
|
+
"exposure",
|
|
58
|
+
"tone",
|
|
59
|
+
"glare",
|
|
60
|
+
"grain",
|
|
61
|
+
"studio",
|
|
62
|
+
"background",
|
|
63
|
+
"bow",
|
|
64
|
+
"pose",
|
|
65
|
+
"lens",
|
|
66
|
+
"pointer",
|
|
67
|
+
"tiltRange",
|
|
68
|
+
"wobble",
|
|
69
|
+
"wobbleAmp",
|
|
70
|
+
]);
|
|
71
|
+
/** Composes `holo` over holo.spot's parameter defaults. */
|
|
72
|
+
function compose(holo) {
|
|
73
|
+
const st = { ...DEFAULT_COMPOSED };
|
|
74
|
+
const list = (Array.isArray(holo) ? holo : holo ? [holo] : []);
|
|
75
|
+
for (const input of list) {
|
|
76
|
+
if (input && typeof input === "object") {
|
|
77
|
+
applyInput(st, input);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return st;
|
|
81
|
+
}
|
|
82
|
+
/** holo.spot entities whose blobs HoloEffect draws as they are meant (the rest are drawn as the flat card). */
|
|
83
|
+
const BLOB_ENTITIES = new Set(["card", "object", "image", "plain"]);
|
|
84
|
+
/** The emboss logo's placement: CSS px here, mm on holo.spot's card in a Copy settings blob. */
|
|
85
|
+
const MM_PLACEMENT = new Set(["emboss.x", "emboss.y", "emboss.width"]);
|
|
86
|
+
/** The ids a scene shorthand writes (`null` for each removes it). */
|
|
87
|
+
function sceneWrites(p) {
|
|
88
|
+
const o = {};
|
|
89
|
+
const set = (v, ...ids) => {
|
|
90
|
+
if (v !== undefined) {
|
|
91
|
+
for (const id of ids) {
|
|
92
|
+
o[id] = v;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
set(p.exposure, "display.ev");
|
|
97
|
+
set(p.tone, "display.tone");
|
|
98
|
+
set(p.glare, "display.glare");
|
|
99
|
+
if (p.grain !== undefined) {
|
|
100
|
+
o["grain.amount"] = p.grain;
|
|
101
|
+
o["grain.on"] = p.grain === null ? null : p.grain > 0;
|
|
102
|
+
}
|
|
103
|
+
set(p.studio, "studio.preset");
|
|
104
|
+
if (p.background !== undefined) {
|
|
105
|
+
const b = p.background?.trim() ?? null;
|
|
106
|
+
if (b === null || b === "black" || b === "white") {
|
|
107
|
+
o["scene.background"] = b;
|
|
108
|
+
o["scene.bgColor"] = null;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
o["scene.background"] = "colour";
|
|
112
|
+
o["scene.bgColor"] = b;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
set(p.bow, "card.bow");
|
|
116
|
+
set(p.pose && { x: p.pose.x, y: p.pose.y }, "motion.pose");
|
|
117
|
+
set(p.lens, "dof.lens");
|
|
118
|
+
set(p.pointer, "motion.pointer");
|
|
119
|
+
set(p.tiltRange, "motion.tiltRange");
|
|
120
|
+
set(p.wobble, "motion.wobble");
|
|
121
|
+
set(p.wobbleAmp, "motion.wobbleAmp");
|
|
122
|
+
return o;
|
|
123
|
+
}
|
|
124
|
+
/** FNV-1a hash of bytes (32 bit, hex). */
|
|
125
|
+
function fnv1a(b) {
|
|
126
|
+
let h = 0x811c9dc5;
|
|
127
|
+
for (let i = 0; i < b.length; i++) {
|
|
128
|
+
h ^= b[i];
|
|
129
|
+
h = Math.imul(h, 0x01000193);
|
|
130
|
+
}
|
|
131
|
+
return (h >>> 0).toString(16);
|
|
132
|
+
}
|
|
133
|
+
/** An <img> (false where the DOM has none, such as a worker or a test). */
|
|
134
|
+
const isImgElement = (v) => typeof HTMLImageElement !== "undefined" && v instanceof HTMLImageElement;
|
|
135
|
+
/** An image setting that is set: a non-empty URL, or an image object. */
|
|
136
|
+
const givenImage = (v) => (typeof v === "string" && v.trim() !== "") ||
|
|
137
|
+
(!!v && typeof v === "object");
|
|
138
|
+
const isSettingValue = (v) => typeof v === "number" ||
|
|
139
|
+
typeof v === "boolean" ||
|
|
140
|
+
typeof v === "string" ||
|
|
141
|
+
(!!v &&
|
|
142
|
+
typeof v === "object" &&
|
|
143
|
+
typeof v.x === "number" &&
|
|
144
|
+
typeof v.y === "number");
|
|
145
|
+
/**
|
|
146
|
+
* Applies one input of `holo`, in place. A Copy settings blob replaces the settings (it is a whole scene) and brings
|
|
147
|
+
* its material, pose and structure scale; settings by id merge by id. A light rig (`studio.preset`) or a material
|
|
148
|
+
* preset select (`emboss.stock`) writes its values where it is given, so ids given after it win and ids given before
|
|
149
|
+
* it lose.
|
|
150
|
+
*/
|
|
151
|
+
function applyInput(st, input) {
|
|
152
|
+
const writes = {};
|
|
153
|
+
let next = { ...st.settings };
|
|
154
|
+
if ((0, settings_js_1.isCopyBlob)(input)) {
|
|
155
|
+
next = {};
|
|
156
|
+
const m = input.material;
|
|
157
|
+
if (m !== undefined) {
|
|
158
|
+
if ((0, registry_js_1.isMaterialName)(m)) {
|
|
159
|
+
st.material = m;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
(0, settings_js_1.warnOnce)(`HoloEffect: the Copy settings' material "${m}" is not supported (one of ${registry_js_1.MATERIAL_NAMES.join(", ")}); keeping "${st.material}".`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const entity = input.entity;
|
|
166
|
+
if (entity !== undefined && !BLOB_ENTITIES.has(String(entity))) {
|
|
167
|
+
(0, settings_js_1.warnOnce)(`HoloEffect: a holo.spot Copy settings of the "${String(entity)}" object is drawn as a flat card (HoloEffect draws holo.spot's card, 3D object look and paper card, not its cloth, stickers or flag).`);
|
|
168
|
+
}
|
|
169
|
+
for (const [id, v] of Object.entries(input.values)) {
|
|
170
|
+
if ((id === "emboss.logo" || id === "emboss.print") &&
|
|
171
|
+
typeof v === "string" &&
|
|
172
|
+
/^(\/logos\/|asset:)/.test(v.trim())) {
|
|
173
|
+
// holo.spot's own logo marks and its uploaded images do not come with a blob
|
|
174
|
+
(0, settings_js_1.warnOnce)(`HoloEffect: ${id} "${v}" of a holo.spot Copy settings is holo.spot's own image, which HoloEffect does not include; ignored. Set ${id} to an image or a URL.`);
|
|
175
|
+
}
|
|
176
|
+
else if (MM_PLACEMENT.has(id)) {
|
|
177
|
+
// mm on holo.spot's 63 × 88 mm card; the port's are px of the element
|
|
178
|
+
(0, settings_js_1.warnOnce)(`HoloEffect: ${id} of a holo.spot Copy settings is in mm on holo.spot's card; ignored (HoloEffect's is in CSS px).`);
|
|
179
|
+
}
|
|
180
|
+
else if (isSettingValue(v)) {
|
|
181
|
+
writes[id] = v;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const pose = input.pose;
|
|
185
|
+
if (pose &&
|
|
186
|
+
typeof pose.rx === "number" &&
|
|
187
|
+
typeof pose.ry === "number") {
|
|
188
|
+
writes["motion.pose"] = { x: pose.ry, y: pose.rx };
|
|
189
|
+
}
|
|
190
|
+
const ss = input.values["object.structureScale"];
|
|
191
|
+
if (typeof ss === "number") {
|
|
192
|
+
st.structureScale = ss;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
const { settings, ...rest } = input;
|
|
197
|
+
if ((0, settings_js_1.isCopyBlob)(settings)) {
|
|
198
|
+
(0, settings_js_1.warnOnce)("HoloEffect: a holo.spot Copy settings blob goes in `holo` itself (`holo: blob`, or an element of the list), not in `settings`; ignored.");
|
|
199
|
+
}
|
|
200
|
+
else if (settings) {
|
|
201
|
+
Object.assign(writes, settings);
|
|
202
|
+
}
|
|
203
|
+
Object.assign(writes, sceneWrites(rest));
|
|
204
|
+
for (const [k, v] of Object.entries(rest)) {
|
|
205
|
+
if (COMPOSED_KEYS.has(k)) {
|
|
206
|
+
if (k === "material" && v !== undefined && !(0, registry_js_1.isMaterialName)(v)) {
|
|
207
|
+
(0, settings_js_1.warnOnce)(`HoloEffect: unknown material "${String(v)}" (one of ${registry_js_1.MATERIAL_NAMES.join(", ")}); keeping "${st.material}".`);
|
|
208
|
+
}
|
|
209
|
+
else if (v !== undefined) {
|
|
210
|
+
st[k] = v;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else if (!SCENE_KEYS.has(k)) {
|
|
214
|
+
(0, settings_js_1.warnOnce)(`HoloEffect: unknown key "${k}" in holo; ignored.${k in DEFAULT_PARAMS ? ` ${k} is a param of its own: { holo, ${k} }.` : ""}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// presets first, so the ids given with them win
|
|
219
|
+
const rig = writes["studio.preset"];
|
|
220
|
+
if (typeof rig === "string" && studio_presets_js_1.STUDIO_PRESETS[rig]) {
|
|
221
|
+
Object.assign(next, studio_presets_js_1.STUDIO_PRESETS[rig]);
|
|
222
|
+
}
|
|
223
|
+
for (const [id, options] of Object.entries(material_presets_js_1.MATERIAL_PRESETS)) {
|
|
224
|
+
const choice = writes[id];
|
|
225
|
+
if (typeof choice === "string" && options[choice]) {
|
|
226
|
+
Object.assign(next, options[choice]);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
for (const [id, v] of Object.entries(writes)) {
|
|
230
|
+
if (v === null) {
|
|
231
|
+
delete next[id];
|
|
232
|
+
}
|
|
233
|
+
else if (v !== undefined) {
|
|
234
|
+
next[id] = v;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
st.settings = Object.freeze(next);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* A look holo.spot ships, as params: all of it in `settings` (lights `studio.*`, exposure, glare, grain, card finish,
|
|
241
|
+
* pose, material values) plus its quality, so whatever comes after it wins.
|
|
242
|
+
*/
|
|
243
|
+
function lookParams(entries, quality, material) {
|
|
244
|
+
const values = {};
|
|
245
|
+
for (const [, e] of entries) {
|
|
246
|
+
Object.assign(values, e.values);
|
|
247
|
+
}
|
|
248
|
+
// the look's rest pose as holo.spot's motion.pose (x = ry, y = rx)
|
|
249
|
+
const pose = entries[0][1].pose;
|
|
250
|
+
values["motion.pose"] = { x: pose.ry, y: pose.rx };
|
|
251
|
+
return Object.freeze({
|
|
252
|
+
...(material ? { material } : {}),
|
|
253
|
+
quality,
|
|
254
|
+
settings: Object.freeze(values),
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
/** A look's entries: the foils share its scene values, each adds its own material values. */
|
|
258
|
+
const lookEntries = (name) => Object.entries(looks_js_1.LOOKS[name]).filter(([m]) => m !== "emboss");
|
|
259
|
+
const MM_PER_CSS_PX = 25.4 / 96;
|
|
260
|
+
const MATERIAL_PREFIXES = new Set(registry_js_1.MATERIAL_NAMES);
|
|
261
|
+
/** holospot's framing: the card at rest fills this share of the view (camera FOV 22°). */
|
|
262
|
+
const FRAMING = 0.7;
|
|
263
|
+
/** Vertical field of view [deg] of a focal length (holospot physics/lens.ts lensFovDeg: exactly 22° at 62 mm). */
|
|
264
|
+
function lensFovDeg(fMm) {
|
|
265
|
+
if (!(fMm > 0) || fMm === 62) {
|
|
266
|
+
return 22;
|
|
267
|
+
}
|
|
268
|
+
return (2 * Math.atan(12 / fMm) * 180) / Math.PI;
|
|
269
|
+
}
|
|
270
|
+
/** Perspective-mode margin [physical px] on each side of the element. */
|
|
271
|
+
function perspectiveMargin(w, h) {
|
|
272
|
+
const k = (1 / FRAMING - 1) / 2;
|
|
273
|
+
return [Math.ceil(w * k), Math.ceil(h * k)];
|
|
274
|
+
}
|
|
275
|
+
const SOURCE_CHANNELS = {
|
|
276
|
+
alpha: 0,
|
|
277
|
+
luminance: 1,
|
|
278
|
+
none: 2,
|
|
279
|
+
};
|
|
280
|
+
/** uWave without relief waves. */
|
|
281
|
+
const NO_WAVES = new Float32Array(128);
|
|
282
|
+
const TONES = { neutral: 0, agx: 1, clamp: 2 };
|
|
283
|
+
/** The output pass's grain uniforms (holospot render/grain.ts): off at amount 0. */
|
|
284
|
+
function grainUniforms(g, dpr, timeS) {
|
|
285
|
+
if (!g.on || !(g.amount > 0)) {
|
|
286
|
+
return {
|
|
287
|
+
uGrain: 0,
|
|
288
|
+
uGrainCell: 1,
|
|
289
|
+
uGrainSeed: 0,
|
|
290
|
+
uGrainRgb: 0,
|
|
291
|
+
uGrainBg: 0,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
const seed = g.animated ? (((timeS * 120) % 512) + 512) % 512 : 0;
|
|
295
|
+
return {
|
|
296
|
+
uGrain: g.amount,
|
|
297
|
+
uGrainCell: Math.max(g.sizePx * (dpr > 0 ? dpr : 1), 1),
|
|
298
|
+
uGrainSeed: Number.isFinite(seed) ? seed : 0,
|
|
299
|
+
uGrainRgb: g.colour === "rgb" ? 1 : 0,
|
|
300
|
+
uGrainBg: g.onBackground ? 1 : 0,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/** Row-major Mat3 → column-major Float32Array (GLSL mat3). */
|
|
304
|
+
function colMajor(m, out = new Float32Array(9)) {
|
|
305
|
+
out[0] = m[0];
|
|
306
|
+
out[1] = m[3];
|
|
307
|
+
out[2] = m[6];
|
|
308
|
+
out[3] = m[1];
|
|
309
|
+
out[4] = m[4];
|
|
310
|
+
out[5] = m[7];
|
|
311
|
+
out[6] = m[2];
|
|
312
|
+
out[7] = m[5];
|
|
313
|
+
out[8] = m[8];
|
|
314
|
+
return out;
|
|
315
|
+
}
|
|
316
|
+
const FRAG_DECODE = `#version 300 es
|
|
317
|
+
precision highp float;
|
|
318
|
+
precision highp int;
|
|
319
|
+
precision highp sampler2D;
|
|
320
|
+
uniform sampler2D uBytes;
|
|
321
|
+
uniform int uRowOffset;
|
|
322
|
+
out vec4 outColor;
|
|
323
|
+
${float24_js_1.GLSL_DECODE_FLOAT24}
|
|
324
|
+
void main() {
|
|
325
|
+
ivec2 t = ivec2(gl_FragCoord.xy);
|
|
326
|
+
int y = t.y + uRowOffset;
|
|
327
|
+
outColor = vec4(
|
|
328
|
+
decodeFloat24(texelFetch(uBytes, ivec2(3 * t.x, y), 0).rgb),
|
|
329
|
+
decodeFloat24(texelFetch(uBytes, ivec2(3 * t.x + 1, y), 0).rgb),
|
|
330
|
+
decodeFloat24(texelFetch(uBytes, ivec2(3 * t.x + 2, y), 0).rgb),
|
|
331
|
+
1.0);
|
|
332
|
+
}
|
|
333
|
+
`;
|
|
334
|
+
/** Decodes a float24 byte image (4 values per output texel) into an RGBA float target: the LTC tables, the logo and the paper maps. */
|
|
335
|
+
const FRAG_DECODE_RGBA = `#version 300 es
|
|
336
|
+
precision highp float;
|
|
337
|
+
precision highp int;
|
|
338
|
+
precision highp sampler2D;
|
|
339
|
+
${float24_js_1.GLSL_DECODE_FLOAT24}
|
|
340
|
+
${ltc_js_1.FRAG_DECODE_RGBA_MAIN}`;
|
|
341
|
+
const FRAG_ZERO = `#version 300 es
|
|
342
|
+
precision highp float;
|
|
343
|
+
out vec4 outColor;
|
|
344
|
+
void main() { outColor = vec4(0.0); }
|
|
345
|
+
`;
|
|
346
|
+
// output.frag's helpers (tone curves, gamut map, sRGB transfer, dither, grain) with a main for the element: decode
|
|
347
|
+
// the card target, expose, tone-map, encode, then composite with the element by the foil mask.
|
|
348
|
+
const OUTPUT_HELPERS = output_js_1.default
|
|
349
|
+
.slice(0, output_js_1.default.indexOf("void main()"))
|
|
350
|
+
.replace("varying vec2 vUv;\n", "");
|
|
351
|
+
const FRAG_OUTPUT = `${shader_js_1.FRAG_PREFIX}
|
|
352
|
+
${shader_js_1.GLSL_COMMON}
|
|
353
|
+
${OUTPUT_HELPERS}
|
|
354
|
+
in vec2 uv;
|
|
355
|
+
in vec2 uvContent;
|
|
356
|
+
in vec2 uvSrc;
|
|
357
|
+
uniform sampler2D src;
|
|
358
|
+
uniform sampler2D uBase; // 3d view: the element mapped onto the card
|
|
359
|
+
uniform int uMask;
|
|
360
|
+
uniform int uPersp;
|
|
361
|
+
void main() {
|
|
362
|
+
// flat view: the card target covers the element; 3d view: the whole (grown) output
|
|
363
|
+
vec2 hu = uPersp == 1 ? uv : uvContent;
|
|
364
|
+
vec4 s = uPersp == 1 ? (uMask == 1 ? texture(uBase, uv) : vec4(0.0)) : texture(src, uvSrc);
|
|
365
|
+
if (uPersp == 0 && (uvContent.x < 0.0 || uvContent.x > 1.0 || uvContent.y < 0.0 || uvContent.y > 1.0)) {
|
|
366
|
+
gl_FragColor = s;
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
vec4 P = textureLod(tHdr, clamp(hu, 0.0, 1.0), 0.0);
|
|
370
|
+
float a = clamp(P.a, 0.0, 1.0); vec3 c = vec3(0.0);
|
|
371
|
+
if (a > 1e-5) { vec3 cu = P.rgb / a; c = cu / (ENC_S * max(1.0 - max(max3(cu), 0.0), 1e-4)); }
|
|
372
|
+
vec3 G = uGW0 * textureLod(tG0, hu * uG0Scale, 0.0).rgb; // premultiplied linear glare
|
|
373
|
+
vec3 card = toDisplay(((1.0 - uGlare) * c + uGlare * G) * uExposure);
|
|
374
|
+
vec3 spill = toDisplay(uGlare * G * uExposure);
|
|
375
|
+
// The foil's coverage (the mask, applied by the material pass) is the card target's alpha, then the foil goes over
|
|
376
|
+
// what is left of the element (luma mask) with the glare spill on it. holospot screens the spill onto the page: in
|
|
377
|
+
// premultiplied output that is the spill with alpha = its largest channel (exact on black, invisible on white).
|
|
378
|
+
float cov = a;
|
|
379
|
+
vec4 base = uMask == 1 ? s : vec4(0.0);
|
|
380
|
+
vec3 se = srgbOETF(spill);
|
|
381
|
+
vec4 spillP = vec4(se, max3(se));
|
|
382
|
+
base = spillP + (1.0 - spillP.a) * base;
|
|
383
|
+
vec3 enc = srgbOETF(card);
|
|
384
|
+
// A4.1 film grain in display space, after the tone curve and before the dither (output.frag).
|
|
385
|
+
if (uGrain > 0.0) {
|
|
386
|
+
vec2 fc = gl_FragCoord.xy;
|
|
387
|
+
vec3 n = uGrainRgb == 1
|
|
388
|
+
? vec3(grainNoise(fc, uGrainSeed), grainNoise(fc, uGrainSeed + 171.0), grainNoise(fc, uGrainSeed + 342.0))
|
|
389
|
+
: vec3(grainNoise(fc, uGrainSeed));
|
|
390
|
+
enc += uGrain * n;
|
|
391
|
+
if (uGrainBg == 1) base.rgb = clamp(base.rgb + uGrain * n * base.a, 0.0, 1.0);
|
|
392
|
+
}
|
|
393
|
+
if (cov > 0.0 || max3(spill) > 1e-4) enc += triangularDither(gl_FragCoord.xy) / 255.0;
|
|
394
|
+
gl_FragColor = vec4(clamp(enc, 0.0, 1.0), 1.0) * cov + base * (1.0 - cov);
|
|
395
|
+
}
|
|
396
|
+
`;
|
|
397
|
+
/**
|
|
398
|
+
* Holographic foil: the diffraction foils of holo.spot (Prism Rainbow and friends) on an element, ported from
|
|
399
|
+
* [holospot](https://github.com/dmitrykurash/holospot) (MIT). The element is lit as a card by holo.spot's spectral
|
|
400
|
+
* studio lights and tilts toward the pointer. Settings use holo.spot's ids, so a look copied from holo.spot carries
|
|
401
|
+
* over.
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```ts
|
|
405
|
+
* vfx.add(el, {
|
|
406
|
+
* effect: new HoloEffect({
|
|
407
|
+
* holo: [
|
|
408
|
+
* HoloEffect.looks.card,
|
|
409
|
+
* { material: "prism", settings: { "prism.pitch": 1200, "prism.pattern": "radial" } },
|
|
410
|
+
* ],
|
|
411
|
+
* }),
|
|
412
|
+
* });
|
|
413
|
+
* ```
|
|
414
|
+
*
|
|
415
|
+
* @remarks
|
|
416
|
+
* ### The model
|
|
417
|
+
*
|
|
418
|
+
* The element is a card of real size (`sizeMm`, else its CSS size at 96 dpi), lit by holo.spot's studio rig and
|
|
419
|
+
* seen by holospot's camera (`lens`). By default the card turns in 3D with the pose (pointer tilt, idle wobble,
|
|
420
|
+
* `pose`), and the output grows by about 21 % per side so the turned card and its glare fit. With `flat: true` the
|
|
421
|
+
* card stays in place and the light rig turns the other way instead.
|
|
422
|
+
*
|
|
423
|
+
* holospot's physics is kept: the grating equation, order efficiencies, η renormalisation, material- and
|
|
424
|
+
* SPD-convolved spectral tables, LTC rect lights, the studio environment, coat, wear, glare, grain and tone curves.
|
|
425
|
+
* Its GLSL is used as is, without comments. What differs:
|
|
426
|
+
*
|
|
427
|
+
* - The environment is a prefiltered octahedral atlas (an importance-sampled GGX lobe per level) instead of three's
|
|
428
|
+
* PMREM.
|
|
429
|
+
* - The pose is the port's: a spring toward the rest pose plus the pointer tilt, and an idle wobble.
|
|
430
|
+
* - The foil's shape comes from the element (`sourceChannel`), and `ink` tints the foil with its colours.
|
|
431
|
+
*
|
|
432
|
+
* ### Params
|
|
433
|
+
*
|
|
434
|
+
* The params are the holo.spot side, `holo`, and how the element becomes the card: `sourceChannel`, `ink`, `flat`,
|
|
435
|
+
* `sizeMm` and `antialias`. `setParams` assigns params as other effects do, and so does writing `effect.params`
|
|
436
|
+
* (`effect.params.flat = true`); a new `holo` (not one changed in place) applies on the next frame.
|
|
437
|
+
*
|
|
438
|
+
* `holo` takes what holo.spot's "Copy settings" button copies, holo.spot settings by id with the kit's options and
|
|
439
|
+
* the scene shorthands, or a list of them: `{ holo: [HoloEffect.looks.card, { exposure: 1 }], flat: true }`. A list
|
|
440
|
+
* applies in order over holo.spot's parameter defaults, and later values win. `settings` are holo.spot ids
|
|
441
|
+
* (`HoloSettingId`), merged by id. `null` removes an id, so the default or the look's value applies again.
|
|
442
|
+
*
|
|
443
|
+
* - **Looks:** `HoloEffect.looks` are the looks holo.spot ships: their scene in `settings`, and the quality holospot
|
|
444
|
+
* ships each with. Put a look in the list as its own element, not spread into an object that has its own
|
|
445
|
+
* `settings`.
|
|
446
|
+
* - **Starting points:** `HoloEffect.startingPoints` are holospot's material starting points.
|
|
447
|
+
* - **Presets:** a light rig (`studio.preset`) or `emboss.stock` writes its values where it is given. Ids given
|
|
448
|
+
* after it win; ids given before it lose.
|
|
449
|
+
* - **Copy settings:** a holo.spot "Copy settings" blob (`HoloCopyBlob`) replaces the settings given before it and
|
|
450
|
+
* brings its material, pose and structure scale.
|
|
451
|
+
* - **Checks:** values are checked against holo.spot's ranges. Out-of-range values are clamped, and bad values
|
|
452
|
+
* and unknown ids are dropped, each with one console warning. holo.spot ids the port does not render (depth of
|
|
453
|
+
* field blur, bump maps, card borders) warn when set away from holospot's default.
|
|
454
|
+
*
|
|
455
|
+
* The scene shorthands write holo.spot ids with holospot's units and ranges:
|
|
456
|
+
*
|
|
457
|
+
* | Shorthand | holo.spot id |
|
|
458
|
+
* | --- | --- |
|
|
459
|
+
* | `exposure` (EV, ±3), `tone` | `display.ev`, `display.tone` |
|
|
460
|
+
* | `glare` (0–0.1), `grain` (0–0.6, 0 = off) | `display.glare`, `grain.amount` |
|
|
461
|
+
* | `studio` | `studio.preset` |
|
|
462
|
+
* | `background` (`black`, `white`, `#rgb`, `#rrggbb`) | `scene.background`, `scene.bgColor` |
|
|
463
|
+
* | `bow` (mm, 0–2), `pose` (±35°) | `card.bow`, `motion.pose` |
|
|
464
|
+
* | `lens` (mm, 24–200: the field of view, no blur) | `dof.lens` |
|
|
465
|
+
* | `pointer`, `tiltRange` (5–35°) | `motion.pointer`, `motion.tiltRange` |
|
|
466
|
+
* | `wobble`, `wobbleAmp` (0–25°) | `motion.wobble`, `motion.wobbleAmp` |
|
|
467
|
+
*
|
|
468
|
+
* ### Foil Emboss
|
|
469
|
+
*
|
|
470
|
+
* `material: "emboss"` is a paper card with a foil logo pressed into it, and the whole element is the paper.
|
|
471
|
+
*
|
|
472
|
+
* - **Logo:** `emboss.logo` takes a URL, an `<img>`, a canvas or an `ImageBitmap`. Without one there is no logo.
|
|
473
|
+
* The logo is cut into foil / no foil: `sourceChannel` picks how the image is read (`"alpha"` or `"luminance"`), and
|
|
474
|
+
* `emboss.threshold` sets where it is cut. A photo becomes a one-tone stamp.
|
|
475
|
+
* - **Placement:** in CSS px of the element. `emboss.x` and `emboss.y` are the logo's centre from the top left,
|
|
476
|
+
* and `emboss.width` its width. Unset, the logo is centred at 36/63 of the element's width.
|
|
477
|
+
* - **Print:** by default the element is printed on the paper. `emboss.print` prints an image instead, fitted like
|
|
478
|
+
* `background-size: cover`. While it loads, and if it fails, the paper is plain.
|
|
479
|
+
* - **The element as the logo:** `"emboss.logo": "element"` presses the element itself in foil, 1:1. It is read
|
|
480
|
+
* back once, and again on a resize or when `holo` is set again, so it suits a still element. The ground
|
|
481
|
+
* is `emboss.print` or `emboss.paperColour`, and transparent without both, so CSS can show what is behind.
|
|
482
|
+
* - **Loading:** the logo, paper and print load in the background. `ready` resolves after a frame with them, and
|
|
483
|
+
* `errors` lists what failed (a cross-origin image needs CORS).
|
|
484
|
+
*
|
|
485
|
+
* ### Code loading
|
|
486
|
+
*
|
|
487
|
+
* Each material's code (its shaders; for `emboss` also the logo and paper builders) is a separate chunk, loaded
|
|
488
|
+
* when the material is first used. `init` waits for it. After `holo` changes the material, the effect keeps drawing
|
|
489
|
+
* the previous material until the new one has loaded, and `ready` waits for it. `HoloEffect.preload(...)` loads
|
|
490
|
+
* materials ahead. `@vfx-js/effects/holo/static` exports the same class with every material built in: one file,
|
|
491
|
+
* and a material change never waits for code.
|
|
492
|
+
*
|
|
493
|
+
* ### Differences from holo.spot
|
|
494
|
+
*
|
|
495
|
+
* - **Port-only:** `sourceChannel`, `ink`, `flat`, `sizeMm`, `antialias`, the `"none"` pointer,
|
|
496
|
+
* `emboss.threshold` and the element as the emboss logo.
|
|
497
|
+
* - **Changed defaults:** grain is 0.07 (the value holo.spot's looks use), and there is no default emboss logo
|
|
498
|
+
* (holo.spot's marks are not included). A blob's references to holo.spot's marks or uploaded images
|
|
499
|
+
* (`emboss.logo`, `emboss.print`) are ignored with a warning.
|
|
500
|
+
* - **Changed units:** the emboss placement is in px, not mm on holo.spot's 63 × 88 mm card. A blob's mm placement
|
|
501
|
+
* is ignored.
|
|
502
|
+
* - **Different names:** `studio` instead of `lights`, `startingPoints`, and `flat`, because holospot uses
|
|
503
|
+
* `lights` and `View` for other things.
|
|
504
|
+
* - **Not ported:** the Volume Hologram and the emboss hologram stickers, multi-element emboss cards
|
|
505
|
+
* (`emboss.doc`), depth of field blur, bump maps, and card borders and thickness. holo.spot's cloth, stickers and
|
|
506
|
+
* flag objects are not either: a Copy settings blob of one is drawn as the flat card, with a warning.
|
|
507
|
+
*
|
|
508
|
+
* Rendered next to holospot in Chromium, the foils differ by about 1 per channel (0–255) on average. Glitter
|
|
509
|
+
* glints differ per pixel, but match within 1 after a slight blur. holospot's and three.js's MIT notices ship in
|
|
510
|
+
* the package's `THIRD_PARTY_NOTICES.md`.
|
|
511
|
+
*/
|
|
512
|
+
class HoloEffect {
|
|
513
|
+
/** The params; see `HoloParams`. */
|
|
514
|
+
params;
|
|
515
|
+
/** `params.holo` composed, and what it was composed from. */
|
|
516
|
+
#p = { ...DEFAULT_COMPOSED };
|
|
517
|
+
#holoSeen = Symbol("unseen");
|
|
518
|
+
#channelSeen = null;
|
|
519
|
+
#resolved = null;
|
|
520
|
+
#scene = null;
|
|
521
|
+
#dirty = true;
|
|
522
|
+
#atlas = null;
|
|
523
|
+
#atlasUploaded = -1;
|
|
524
|
+
#bytesCanvas = null;
|
|
525
|
+
#bytesTex = null;
|
|
526
|
+
#conv = null;
|
|
527
|
+
#cum = null;
|
|
528
|
+
#hdr = null;
|
|
529
|
+
#base = null;
|
|
530
|
+
#viewProj = new Float32Array(16);
|
|
531
|
+
#black = null;
|
|
532
|
+
#env = null;
|
|
533
|
+
#ltcTex = null;
|
|
534
|
+
#ltc1 = null;
|
|
535
|
+
#ltc2 = null;
|
|
536
|
+
#ltcReady = false;
|
|
537
|
+
#glare = new glare_js_1.HoloGlare();
|
|
538
|
+
// Foil Emboss: the logo distance field and the paper maps (built on demand)
|
|
539
|
+
#emboss = null;
|
|
540
|
+
#logoRt = null;
|
|
541
|
+
#logoMap = [1.28, 1.28, 1 / 800, 1];
|
|
542
|
+
#logoUp = -1;
|
|
543
|
+
#paperRt = null;
|
|
544
|
+
#paperUp = -1;
|
|
545
|
+
#envDrawn = null;
|
|
546
|
+
#blobs = (0, env_js_1.cameraSideBlobs)();
|
|
547
|
+
#waves = null;
|
|
548
|
+
#blackReady = false;
|
|
549
|
+
#pose = new pose_js_1.PoseSpring();
|
|
550
|
+
#lights = (0, lights_js_1.emptyLightSet)();
|
|
551
|
+
#prevLightPos = new Float32Array(12);
|
|
552
|
+
#cardRot = new Float32Array(9);
|
|
553
|
+
#prevCardRot = new Float32Array(9);
|
|
554
|
+
#camPos = [0, 0, 0.4];
|
|
555
|
+
#cardSizeMm = [63, 88];
|
|
556
|
+
/** The element's CSS size [px] (the emboss logo's placement frame). */
|
|
557
|
+
#elemCss = [238, 333];
|
|
558
|
+
/** The card's surface domain [mm]: its size × `structureScale` (the structure's frame, not the geometry's). */
|
|
559
|
+
#domainMm = [63, 88];
|
|
560
|
+
/** The drawn card's rotation (3d view: the pose; flat: identity). */
|
|
561
|
+
#visRot = new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
|
562
|
+
/** Flat view: the inverse of the light rig's rotation (= the pose), row-major; null in 3d. */
|
|
563
|
+
#rigInv = null;
|
|
564
|
+
#eta = null;
|
|
565
|
+
#matUniforms = {};
|
|
566
|
+
/** Per-frame uniform buffers, reused. */
|
|
567
|
+
#binLam = new Float32Array(8);
|
|
568
|
+
#binW = new Float32Array(72);
|
|
569
|
+
#frag = "";
|
|
570
|
+
#mouseStart = null;
|
|
571
|
+
#pointerSeen = false;
|
|
572
|
+
#started = false;
|
|
573
|
+
/**
|
|
574
|
+
* @example
|
|
575
|
+
* ```ts
|
|
576
|
+
* new HoloEffect({ holo: copiedFromHoloSpot });
|
|
577
|
+
* new HoloEffect({
|
|
578
|
+
* holo: [HoloEffect.looks.card, HoloEffect.startingPoints.prism.compactDisc, { exposure: 1 }],
|
|
579
|
+
* flat: true,
|
|
580
|
+
* });
|
|
581
|
+
* ```
|
|
582
|
+
*/
|
|
583
|
+
constructor(initial = {}) {
|
|
584
|
+
warnUnknownParams(initial);
|
|
585
|
+
this.params = { ...DEFAULT_PARAMS, ...initial };
|
|
586
|
+
this.#sync(); // check holo now, so its warnings point here
|
|
587
|
+
}
|
|
588
|
+
/** Assigns params, as other effects do. A new `holo` replaces the whole holo.spot side. */
|
|
589
|
+
setParams(updates) {
|
|
590
|
+
warnUnknownParams(updates);
|
|
591
|
+
Object.assign(this.params, updates);
|
|
592
|
+
this.#sync();
|
|
593
|
+
}
|
|
594
|
+
/** The material in effect: the last one `holo` sets, else `"prism"`. */
|
|
595
|
+
get material() {
|
|
596
|
+
this.#sync();
|
|
597
|
+
return this.#p.material;
|
|
598
|
+
}
|
|
599
|
+
/** Takes up a new `params.holo` or `params.sourceChannel`: composes `holo` again, and resolves again. */
|
|
600
|
+
#sync() {
|
|
601
|
+
const holo = this.params.holo;
|
|
602
|
+
if (holo !== this.#holoSeen) {
|
|
603
|
+
this.#holoSeen = holo;
|
|
604
|
+
this.#p = compose(holo);
|
|
605
|
+
this.#dirty = true;
|
|
606
|
+
this.#defFailed = null; // a material that failed to load is tried again
|
|
607
|
+
this.#defError = null;
|
|
608
|
+
this.#capGen++; // the element as the logo is read again (it may have changed)
|
|
609
|
+
}
|
|
610
|
+
if (this.params.sourceChannel !== this.#channelSeen) {
|
|
611
|
+
this.#channelSeen = this.params.sourceChannel;
|
|
612
|
+
this.#dirty = true; // the emboss logo is read again
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Resolves once the effect has drawn a frame with everything it loads in place: the material's code, and for
|
|
617
|
+
* `emboss` the logo, the paper maps and `emboss.print`, which load in the background (until then the card is
|
|
618
|
+
* drawn without them). A load that fails does not reject it; see `errors`. It also resolves when the effect is
|
|
619
|
+
* disposed.
|
|
620
|
+
*/
|
|
621
|
+
get ready() {
|
|
622
|
+
this.#sync();
|
|
623
|
+
if (this.#readyNow()) {
|
|
624
|
+
return Promise.resolve();
|
|
625
|
+
}
|
|
626
|
+
return new Promise((resolve) => this.#readyWaiters.push(resolve));
|
|
627
|
+
}
|
|
628
|
+
/** Loading errors (a logo that could not be fetched or read, …), newest last; cleared when the input changes. */
|
|
629
|
+
get errors() {
|
|
630
|
+
return [
|
|
631
|
+
...(this.#defError ? [this.#defError] : []),
|
|
632
|
+
...(this.#emboss?.errors ?? []),
|
|
633
|
+
...(this.#printError ? [this.#printError] : []),
|
|
634
|
+
];
|
|
635
|
+
}
|
|
636
|
+
#readyWaiters = [];
|
|
637
|
+
#drawnOnce = false;
|
|
638
|
+
#disposed = false;
|
|
639
|
+
#readyNow() {
|
|
640
|
+
if (this.#disposed) {
|
|
641
|
+
return true;
|
|
642
|
+
}
|
|
643
|
+
if (this.#defFailed === this.#p.material && !this.#renderDef) {
|
|
644
|
+
return true; // nothing to draw: the first material failed to load
|
|
645
|
+
}
|
|
646
|
+
return (this.#drawnOnce &&
|
|
647
|
+
!this.#dirty &&
|
|
648
|
+
// the material asked for is drawn, or failed to load (see errors)
|
|
649
|
+
(this.#renderDef?.id === this.#p.material ||
|
|
650
|
+
this.#defFailed === this.#p.material) &&
|
|
651
|
+
(this.#p.material !== "emboss" ||
|
|
652
|
+
(!this.#emboss?.busy && !this.#printBusy && !this.#capPending)));
|
|
653
|
+
}
|
|
654
|
+
#settleReady() {
|
|
655
|
+
if (this.#readyWaiters.length > 0 && this.#readyNow()) {
|
|
656
|
+
const w = this.#readyWaiters;
|
|
657
|
+
this.#readyWaiters = [];
|
|
658
|
+
for (const f of w) {
|
|
659
|
+
f();
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* The looks holo.spot ships, as inputs: `card` (its holographic card), `object` (its 3D object), `image` (its
|
|
665
|
+
* Foil Emboss paper card; sets `material: "emboss"`). Each sets the scene (lights, pose, exposure, …, all in
|
|
666
|
+
* `settings`) and the `quality` holospot ships it with. Without one, the effect starts from holo.spot's parameter
|
|
667
|
+
* defaults. Put a look in `holo` as its own element, not spread, so the `settings` after it merge by id.
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* ```ts
|
|
671
|
+
* new HoloEffect({ holo: [HoloEffect.looks.card, { material: "shatter", studio: "softbox" }] });
|
|
672
|
+
* ```
|
|
673
|
+
*/
|
|
674
|
+
static looks = Object.freeze({
|
|
675
|
+
card: lookParams(lookEntries("card"), "medium"),
|
|
676
|
+
object: lookParams(lookEntries("object"), "low"),
|
|
677
|
+
image: lookParams([
|
|
678
|
+
[
|
|
679
|
+
"emboss",
|
|
680
|
+
looks_js_1.LOOKS.card.emboss,
|
|
681
|
+
],
|
|
682
|
+
], "medium", "emboss"),
|
|
683
|
+
});
|
|
684
|
+
/**
|
|
685
|
+
* The "Starting points" of holospot's material docs, as inputs (`material` and `settings`). They set the material
|
|
686
|
+
* only, not the lights or the pose, so combine them with a look:
|
|
687
|
+
* `new HoloEffect({ holo: [HoloEffect.looks.card, HoloEffect.startingPoints.prism.compactDisc] })`.
|
|
688
|
+
*/
|
|
689
|
+
static startingPoints = Object.freeze(Object.fromEntries(Object.entries(starting_points_js_1.STARTING_POINTS).map(([m, ps]) => [
|
|
690
|
+
m,
|
|
691
|
+
Object.freeze(Object.fromEntries(Object.entries(ps).map(([name, settings]) => [
|
|
692
|
+
name,
|
|
693
|
+
Object.freeze({
|
|
694
|
+
material: m,
|
|
695
|
+
settings: Object.freeze({
|
|
696
|
+
...settings,
|
|
697
|
+
}),
|
|
698
|
+
}),
|
|
699
|
+
]))),
|
|
700
|
+
])));
|
|
701
|
+
/**
|
|
702
|
+
* The holo.spot settings a material understands (its own ids, then the scene's), for building controls. Ids, ranges
|
|
703
|
+
* and meanings follow holospot's docs (`docs/materials/<material>.md`, `docs/scene-settings.md`).
|
|
704
|
+
*/
|
|
705
|
+
static settingSpecs(material) {
|
|
706
|
+
const own = (id) => id.startsWith(`${material}.`);
|
|
707
|
+
const scene = (id) => !MATERIAL_PREFIXES.has(id.split(".")[0]);
|
|
708
|
+
const specs = params_js_1.PARAM_SPECS.filter((p) => own(p.id) || scene(p.id));
|
|
709
|
+
return [
|
|
710
|
+
...specs.filter((p) => own(p.id)),
|
|
711
|
+
...specs.filter((p) => !own(p.id)),
|
|
712
|
+
];
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* The settings in effect, by holo.spot id: holo.spot's defaults with `settings` over them, checked (clamped to
|
|
716
|
+
* the ranges, invalid values dropped). Useful to show a control's current value.
|
|
717
|
+
*/
|
|
718
|
+
resolvedSettings() {
|
|
719
|
+
// the settings alone: no material code is needed (it may not be loaded yet)
|
|
720
|
+
this.#sync();
|
|
721
|
+
const r = (0, settings_js_1.resolveSettings)(this.#p.material, "plain", this.#p.settings);
|
|
722
|
+
// the rest pose in effect (motion.pose / pose when given): x = ry, y = rx
|
|
723
|
+
return { ...r.values, "motion.pose": { x: r.pose.ry, y: r.pose.rx } };
|
|
724
|
+
}
|
|
725
|
+
/** The tier `quality: "auto"` picks, detected once from the GL context. */
|
|
726
|
+
#autoTier = null;
|
|
727
|
+
#tier() {
|
|
728
|
+
const q = this.#p.quality;
|
|
729
|
+
const t = q === "auto" ? (this.#autoTier ?? "medium") : q;
|
|
730
|
+
return tier_js_1.TIERS[t] ?? tier_js_1.TIERS.medium;
|
|
731
|
+
}
|
|
732
|
+
#restoreUnsub = null;
|
|
733
|
+
/**
|
|
734
|
+
* Loads materials' code ahead of use, so switching `material` later draws at once. HoloEffect loads a material's
|
|
735
|
+
* code (its shaders, and for `emboss` the logo and paper builders) when it is first used; `@vfx-js/effects/holo/static`
|
|
736
|
+
* has every material built in instead.
|
|
737
|
+
*/
|
|
738
|
+
static preload(...materials) {
|
|
739
|
+
return Promise.all(materials.map(registry_js_1.loadMaterial)).then(() => { });
|
|
740
|
+
}
|
|
741
|
+
/** Counts init / dispose, so an init that awaited across a dispose stops. */
|
|
742
|
+
#life = 0;
|
|
743
|
+
async init(ctx) {
|
|
744
|
+
const life = ++this.#life;
|
|
745
|
+
this.#disposed = false;
|
|
746
|
+
this.#sync();
|
|
747
|
+
// the material's code, before the first frame
|
|
748
|
+
await this.#requestDef(this.#p.material);
|
|
749
|
+
if (life !== this.#life) {
|
|
750
|
+
return; // disposed (or initialised again) while loading
|
|
751
|
+
}
|
|
752
|
+
// after a context loss the render targets come back empty (wrapped canvases are re-uploaded): fill them
|
|
753
|
+
// again from the CPU-side data, which survives
|
|
754
|
+
this.#restoreUnsub = ctx.onContextRestored(() => {
|
|
755
|
+
this.#autoTier = (0, tier_js_1.detectTier)(ctx.gl);
|
|
756
|
+
this.#atlasUploaded = -1;
|
|
757
|
+
this.#ltcReady = false;
|
|
758
|
+
this.#blackReady = false;
|
|
759
|
+
this.#envDrawn = null;
|
|
760
|
+
this.#logoUp = this.#paperUp = -1;
|
|
761
|
+
this.#capKey = "";
|
|
762
|
+
this.#capInFlight = false;
|
|
763
|
+
this.#capToken++;
|
|
764
|
+
});
|
|
765
|
+
this.#setup(ctx);
|
|
766
|
+
}
|
|
767
|
+
#setup(ctx) {
|
|
768
|
+
this.#autoTier = (0, tier_js_1.detectTier)(ctx.gl);
|
|
769
|
+
this.#dirty = true; // resolve again: the new atlas takes the material's tint
|
|
770
|
+
this.#atlas = new atlas_js_1.SpectralAtlas();
|
|
771
|
+
const canvas = this.#makeCanvas(atlas_js_1.ATLAS.imageWidth, atlas_js_1.ATLAS.imageHeight);
|
|
772
|
+
this.#bytesCanvas = canvas;
|
|
773
|
+
this.#bytesTex = ctx.wrapTexture(canvas, {
|
|
774
|
+
autoUpdate: false,
|
|
775
|
+
filter: "nearest",
|
|
776
|
+
});
|
|
777
|
+
const tableOpts = {
|
|
778
|
+
size: [atlas_js_1.ATLAS.width, atlas_js_1.ATLAS.height],
|
|
779
|
+
float: true,
|
|
780
|
+
filter: "linear",
|
|
781
|
+
};
|
|
782
|
+
this.#conv = ctx.createRenderTarget(tableOpts);
|
|
783
|
+
this.#cum = ctx.createRenderTarget(tableOpts);
|
|
784
|
+
this.#ensureHdr(ctx);
|
|
785
|
+
this.#black = ctx.createRenderTarget({ size: [1, 1], float: true });
|
|
786
|
+
const ltcCanvas = this.#makeCanvas(ltc_js_1.LTC_IMAGE.width, ltc_js_1.LTC_IMAGE.height);
|
|
787
|
+
this.#ctx2d(ltcCanvas)?.putImageData(new ImageData((0, ltc_js_1.ltcImageBytes)(), ltc_js_1.LTC_IMAGE.width, ltc_js_1.LTC_IMAGE.height), 0, 0);
|
|
788
|
+
this.#ltcTex = ctx.wrapTexture(ltcCanvas, {
|
|
789
|
+
autoUpdate: false,
|
|
790
|
+
filter: "nearest",
|
|
791
|
+
});
|
|
792
|
+
const ltcOpts = {
|
|
793
|
+
size: [ltc_js_1.LTC_SIZE, ltc_js_1.LTC_SIZE],
|
|
794
|
+
float: true,
|
|
795
|
+
filter: "linear",
|
|
796
|
+
};
|
|
797
|
+
this.#ltc1 = ctx.createRenderTarget(ltcOpts);
|
|
798
|
+
this.#ltc2 = ctx.createRenderTarget(ltcOpts);
|
|
799
|
+
this.#env = ctx.createRenderTarget({
|
|
800
|
+
size: [env_js_1.ENV_SIZE, env_js_1.ENV_SIZE * env_js_1.ENV_LEVELS],
|
|
801
|
+
float: true,
|
|
802
|
+
filter: "linear",
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
#samples = 1;
|
|
806
|
+
/** The card target (float, the output's size) and the 3d view's base layer, with `antialias` (4× half float). */
|
|
807
|
+
#ensureHdr(ctx) {
|
|
808
|
+
const samples = this.params.antialias ? 4 : 1;
|
|
809
|
+
if (this.#hdr && this.#samples === samples) {
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
this.#hdr?.dispose();
|
|
813
|
+
this.#base?.dispose();
|
|
814
|
+
this.#base = null;
|
|
815
|
+
this.#hdr = ctx.createRenderTarget({
|
|
816
|
+
float: true,
|
|
817
|
+
filter: "nearest",
|
|
818
|
+
samples,
|
|
819
|
+
});
|
|
820
|
+
this.#samples = samples;
|
|
821
|
+
}
|
|
822
|
+
#ensureBase(ctx) {
|
|
823
|
+
this.#base ??= ctx.createRenderTarget({ samples: this.#samples });
|
|
824
|
+
return this.#base;
|
|
825
|
+
}
|
|
826
|
+
/** Perspective mode grows the output so the tilted card and its glare fit. */
|
|
827
|
+
outputRect(dims) {
|
|
828
|
+
if (this.params.flat) {
|
|
829
|
+
return undefined;
|
|
830
|
+
}
|
|
831
|
+
const [w, h] = dims.elementPixel;
|
|
832
|
+
const [mx, my] = perspectiveMargin(w, h);
|
|
833
|
+
return [-mx, -my, w + 2 * mx, h + 2 * my];
|
|
834
|
+
}
|
|
835
|
+
#makeCanvas(w, h) {
|
|
836
|
+
const c = typeof document !== "undefined"
|
|
837
|
+
? document.createElement("canvas")
|
|
838
|
+
: new OffscreenCanvas(w, h);
|
|
839
|
+
c.width = w;
|
|
840
|
+
c.height = h;
|
|
841
|
+
return c;
|
|
842
|
+
}
|
|
843
|
+
#ctx2d(c) {
|
|
844
|
+
return c.getContext("2d");
|
|
845
|
+
}
|
|
846
|
+
/** The material code the current render state was built with. */
|
|
847
|
+
#renderDef = null;
|
|
848
|
+
#defError = null;
|
|
849
|
+
/** The material whose code is loading, and the one that failed to load (tried again when `holo` changes). */
|
|
850
|
+
#defPending = null;
|
|
851
|
+
#defFailed = null;
|
|
852
|
+
/** Loads a material's code once; a failure warns once, is listed in `errors`, and the effect keeps drawing what it drew. */
|
|
853
|
+
#requestDef(m) {
|
|
854
|
+
if (this.#defPending?.m === m) {
|
|
855
|
+
return this.#defPending.p;
|
|
856
|
+
}
|
|
857
|
+
const p = (0, registry_js_1.loadMaterial)(m)
|
|
858
|
+
.then(() => {
|
|
859
|
+
this.#defError = null;
|
|
860
|
+
this.#defFailed = null;
|
|
861
|
+
}, (e) => {
|
|
862
|
+
this.#defFailed = m;
|
|
863
|
+
this.#defError = `HoloEffect: could not load the "${m}" material: ${e instanceof Error ? e.message : String(e)}`;
|
|
864
|
+
console.warn(this.#defError);
|
|
865
|
+
})
|
|
866
|
+
.finally(() => {
|
|
867
|
+
if (this.#defPending?.p === p) {
|
|
868
|
+
this.#defPending = null;
|
|
869
|
+
}
|
|
870
|
+
this.#dirty = true; // resolve again: with the new material, or settle on the failure
|
|
871
|
+
this.#settleReady();
|
|
872
|
+
});
|
|
873
|
+
this.#defPending = { m, p };
|
|
874
|
+
return p;
|
|
875
|
+
}
|
|
876
|
+
#resolve() {
|
|
877
|
+
const p = this.#p;
|
|
878
|
+
let def = (0, registry_js_1.loadedMaterial)(p.material);
|
|
879
|
+
if (!def) {
|
|
880
|
+
// not loaded yet (or failed): load it, and meanwhile draw the material drawn so far with the current settings
|
|
881
|
+
if (this.#defFailed !== p.material) {
|
|
882
|
+
void this.#requestDef(p.material);
|
|
883
|
+
}
|
|
884
|
+
def = this.#renderDef ?? undefined;
|
|
885
|
+
if (!def) {
|
|
886
|
+
return; // nothing drawn yet
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
this.#renderDef = def;
|
|
890
|
+
this.#resolved = (0, settings_js_1.resolveSettings)(def.id, "plain", p.settings);
|
|
891
|
+
this.#scene = (0, settings_js_1.sceneStateFrom)(this.#resolved.values);
|
|
892
|
+
this.#matUniforms = def.uniforms(this.#resolved.values);
|
|
893
|
+
this.#atlas?.setTint(def.gratingSummary(this.#resolved.values).tint);
|
|
894
|
+
const tier = this.#tier();
|
|
895
|
+
const c = this.#scene.card;
|
|
896
|
+
this.#waves = (0, relief_js_1.buildWaves)(def.relief(this.#resolved.values), {
|
|
897
|
+
emboss: c.emboss,
|
|
898
|
+
pitchMm: c.embossPitchMm,
|
|
899
|
+
heightUm: c.embossHeightUm,
|
|
900
|
+
layer: c.embossLayer,
|
|
901
|
+
}, tier.waves);
|
|
902
|
+
this.#frag = (0, shader_js_1.assembleMaterial)({
|
|
903
|
+
...tier.defines,
|
|
904
|
+
...def.defines(tier),
|
|
905
|
+
[`MATERIAL_${def.id.toUpperCase()}`]: 1,
|
|
906
|
+
...(this.#clearPaper() ? { HOLO_CLEAR_PAPER: 1 } : {}),
|
|
907
|
+
NSPD: 5,
|
|
908
|
+
MAX_LIGHTS: 4,
|
|
909
|
+
DEBUG_VIEW: 0,
|
|
910
|
+
}, def.extraChunks, def.fragmentMain);
|
|
911
|
+
this.#dirty = false;
|
|
912
|
+
}
|
|
913
|
+
/** holospot's camera: vertical FOV from the lens, at (0, 0, D) looking down −Z (column-major projection × view). */
|
|
914
|
+
#setViewProj(aspect, D, tanHalf) {
|
|
915
|
+
const f = 1 / tanHalf;
|
|
916
|
+
const near = 0.1 * D;
|
|
917
|
+
const far = 10 * D;
|
|
918
|
+
const a = (far + near) / (near - far);
|
|
919
|
+
const b = (2 * far * near) / (near - far);
|
|
920
|
+
const m = this.#viewProj;
|
|
921
|
+
m.fill(0);
|
|
922
|
+
m[0] = f / aspect;
|
|
923
|
+
m[5] = f;
|
|
924
|
+
m[10] = a;
|
|
925
|
+
m[11] = -1;
|
|
926
|
+
m[14] = a * -D + b; // view = translate(0, 0, −D)
|
|
927
|
+
m[15] = D;
|
|
928
|
+
}
|
|
929
|
+
update(ctx) {
|
|
930
|
+
this.#sync();
|
|
931
|
+
if (this.#dirty || !this.#resolved) {
|
|
932
|
+
this.#resolve();
|
|
933
|
+
}
|
|
934
|
+
const r = this.#resolved;
|
|
935
|
+
const s = this.#scene;
|
|
936
|
+
if (!r || !s) {
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
const [ew, eh] = ctx.dims.element;
|
|
940
|
+
// a zero-size element (not laid out yet, display: none) is treated as 1 px, so the geometry stays finite
|
|
941
|
+
const pw = Math.max(ctx.dims.elementPixel[0], 1);
|
|
942
|
+
const ph = Math.max(ctx.dims.elementPixel[1], 1);
|
|
943
|
+
const w = Math.max(ew, 1);
|
|
944
|
+
const h = Math.max(eh, 1);
|
|
945
|
+
const given = this.params.sizeMm;
|
|
946
|
+
const largest = given !== null && Number.isFinite(given) && given > 0
|
|
947
|
+
? given
|
|
948
|
+
: Math.max(w, h) * MM_PER_CSS_PX;
|
|
949
|
+
const k = largest / Math.max(w, h);
|
|
950
|
+
this.#cardSizeMm = [w * k, h * k];
|
|
951
|
+
this.#elemCss = [w, h];
|
|
952
|
+
// the surface's domain, as holospot's models.ts: size × structureScale (a larger one lays more structure over the card)
|
|
953
|
+
const ss = Math.min(Math.max(this.#p.structureScale || 1, 0.25), 4);
|
|
954
|
+
this.#domainMm = [w * k * ss, h * k * ss];
|
|
955
|
+
const fov = lensFovDeg(s.lensMm);
|
|
956
|
+
const tanHalf = Math.tan((fov * Math.PI) / 360);
|
|
957
|
+
const view3d = !this.params.flat;
|
|
958
|
+
let D = (0, geometry_js_1.framingDistance)(w / h, this.#cardSizeMm[0] / 2000, this.#cardSizeMm[1] / 2000, fov);
|
|
959
|
+
if (view3d) {
|
|
960
|
+
// the card at rest maps exactly onto the element inside the grown output
|
|
961
|
+
const [mx, my] = perspectiveMargin(pw, ph);
|
|
962
|
+
const oh = ph + 2 * my;
|
|
963
|
+
D = (this.#cardSizeMm[1] / 2000 / tanHalf) * (oh / Math.max(ph, 1));
|
|
964
|
+
this.#setViewProj((pw + 2 * mx) / Math.max(oh, 1), D, tanHalf);
|
|
965
|
+
}
|
|
966
|
+
this.#camPos = [0, 0, D];
|
|
967
|
+
// pointer: normalised element position, active once the pointer has moved and while it is over the element
|
|
968
|
+
if (!this.#mouseStart) {
|
|
969
|
+
this.#mouseStart = ctx.mouseViewport;
|
|
970
|
+
}
|
|
971
|
+
else if (ctx.mouseViewport[0] !== this.#mouseStart[0] ||
|
|
972
|
+
ctx.mouseViewport[1] !== this.#mouseStart[1]) {
|
|
973
|
+
this.#pointerSeen = true;
|
|
974
|
+
}
|
|
975
|
+
const nx = (ctx.mouse[0] / Math.max(pw, 1)) * 2 - 1;
|
|
976
|
+
const ny = (ctx.mouse[1] / Math.max(ph, 1)) * 2 - 1;
|
|
977
|
+
const over = this.#pointerSeen && Math.abs(nx) <= 1 && Math.abs(ny) <= 1;
|
|
978
|
+
const m = s.motion;
|
|
979
|
+
const dt = Math.min(Math.max(ctx.deltaTime, 0), 0.1);
|
|
980
|
+
let target = { rx: r.pose.rx, ry: r.pose.ry };
|
|
981
|
+
if (m.pointer === "tilt" && over) {
|
|
982
|
+
target = {
|
|
983
|
+
rx: r.pose.rx - ny * m.tiltRangeDeg,
|
|
984
|
+
ry: r.pose.ry + nx * m.tiltRangeDeg,
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
else if (m.wobble) {
|
|
988
|
+
const o = (0, pose_js_1.wobbleOffset)(ctx.time, m.wobbleAmpDeg);
|
|
989
|
+
target = { rx: r.pose.rx + o.rx, ry: r.pose.ry + o.ry };
|
|
990
|
+
}
|
|
991
|
+
this.#pose.step(target, dt);
|
|
992
|
+
// 3d: the card turns. flat: the card stays and the light rig turns the other way (holospot's Q_L).
|
|
993
|
+
const pose = (0, geometry_js_1.eulerXYZ)(this.#pose.rx, this.#pose.ry, 0);
|
|
994
|
+
const rot = view3d ? pose : [1, 0, 0, 0, 1, 0, 0, 0, 1];
|
|
995
|
+
const rig = view3d
|
|
996
|
+
? { x: 0, y: 0, z: 0, w: 1 }
|
|
997
|
+
: (0, pose_js_1.inversePoseQuat)(this.#pose.rx, this.#pose.ry);
|
|
998
|
+
this.#rigInv = view3d ? null : pose; // mat3(conj(Q_L)) for the environment
|
|
999
|
+
if (this.#started) {
|
|
1000
|
+
this.#prevCardRot.set(this.#cardRot);
|
|
1001
|
+
this.#prevLightPos.set(this.#lights.pos);
|
|
1002
|
+
}
|
|
1003
|
+
colMajor(rot, this.#cardRot);
|
|
1004
|
+
colMajor(rot, this.#visRot);
|
|
1005
|
+
const pad = over ? { x: nx, y: ny } : { x: 0, y: 0 };
|
|
1006
|
+
(0, lights_js_1.computeLights)(s.studio, {
|
|
1007
|
+
mode: m.pointer === "none" ? "tilt" : m.pointer,
|
|
1008
|
+
pad,
|
|
1009
|
+
}, s.background, rig, this.#camPos, this.#lights);
|
|
1010
|
+
for (let i = 0; i < 4; i++) {
|
|
1011
|
+
if (this.#lights.type[i] !== 0) {
|
|
1012
|
+
this.#atlas?.ensureLayer(types_js_1.SPD_IDS[this.#lights.spd[i]] ?? "equal");
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
if (!this.#started) {
|
|
1016
|
+
this.#prevCardRot.set(this.#cardRot);
|
|
1017
|
+
this.#prevLightPos.set(this.#lights.pos);
|
|
1018
|
+
this.#started = true;
|
|
1019
|
+
}
|
|
1020
|
+
const embossDef = this.#renderDef?.emboss;
|
|
1021
|
+
if (embossDef) {
|
|
1022
|
+
this.#emboss ??= embossDef.createAssets();
|
|
1023
|
+
// a URL, or an image given in settings (kept by reference); "element" is read back in render
|
|
1024
|
+
const logo = r.values["emboss.logo"];
|
|
1025
|
+
if (logo !== "element") {
|
|
1026
|
+
this.#capHash = ""; // the next element readback installs its logo again
|
|
1027
|
+
if (this.#capPending || this.#capInFlight) {
|
|
1028
|
+
// a readback of the element (still blank, or on its way) is no longer wanted
|
|
1029
|
+
this.#capPending = false;
|
|
1030
|
+
this.#capInFlight = false;
|
|
1031
|
+
this.#capToken++;
|
|
1032
|
+
this.#capKey = "";
|
|
1033
|
+
this.#capTries = 0;
|
|
1034
|
+
}
|
|
1035
|
+
this.#emboss.setLogo(logo, this.#logoReadOpts("ink"));
|
|
1036
|
+
}
|
|
1037
|
+
this.#emboss.setPaper(embossDef.paperKey(r.values));
|
|
1038
|
+
}
|
|
1039
|
+
else if (this.#emboss || this.#printTex || this.#capRt) {
|
|
1040
|
+
this.#releaseEmboss(); // switched away from emboss
|
|
1041
|
+
}
|
|
1042
|
+
this.#eta = (0, grating_js_1.etaFrame)(this.#renderDef.gratingSummary(r.values), this.#lights, rot, this.#camPos);
|
|
1043
|
+
}
|
|
1044
|
+
render(ctx) {
|
|
1045
|
+
const atlas = this.#atlas;
|
|
1046
|
+
const s = this.#scene;
|
|
1047
|
+
if (!atlas ||
|
|
1048
|
+
!s ||
|
|
1049
|
+
!this.#hdr ||
|
|
1050
|
+
!this.#conv ||
|
|
1051
|
+
!this.#cum ||
|
|
1052
|
+
!this.#black ||
|
|
1053
|
+
!this.#bytesTex ||
|
|
1054
|
+
!this.#eta) {
|
|
1055
|
+
ctx.blit(ctx.src, ctx.target);
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
this.#ensureHdr(ctx);
|
|
1059
|
+
if (!this.#blackReady) {
|
|
1060
|
+
ctx.draw({
|
|
1061
|
+
frag: FRAG_ZERO,
|
|
1062
|
+
vert: shader_js_1.PLAIN_VERT,
|
|
1063
|
+
target: this.#black,
|
|
1064
|
+
});
|
|
1065
|
+
this.#blackReady = true;
|
|
1066
|
+
}
|
|
1067
|
+
if (!this.#ltcReady && this.#ltcTex && this.#ltc1 && this.#ltc2) {
|
|
1068
|
+
for (const [target, row] of [
|
|
1069
|
+
[this.#ltc1, 0],
|
|
1070
|
+
[this.#ltc2, ltc_js_1.LTC_SIZE],
|
|
1071
|
+
]) {
|
|
1072
|
+
ctx.draw({
|
|
1073
|
+
frag: FRAG_DECODE_RGBA,
|
|
1074
|
+
vert: shader_js_1.PLAIN_VERT,
|
|
1075
|
+
target,
|
|
1076
|
+
uniforms: { uBytes: this.#ltcTex, uRowOffset: row },
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
this.#ltcReady = true;
|
|
1080
|
+
}
|
|
1081
|
+
if (this.#atlasUploaded !== atlas.version) {
|
|
1082
|
+
this.#uploadAtlas(ctx, atlas);
|
|
1083
|
+
}
|
|
1084
|
+
const tone = (0, settings_js_1.backgroundTone)(s.background, s.bgColor);
|
|
1085
|
+
const levels = (0, geometry_js_1.envLevels)(s.studio.ambient, tone);
|
|
1086
|
+
if (this.#env && !(0, env_js_1.sameLevels)(this.#envDrawn, levels)) {
|
|
1087
|
+
ctx.draw({
|
|
1088
|
+
frag: env_js_1.FRAG_ENV_PREFILTER,
|
|
1089
|
+
vert: shader_js_1.PLAIN_VERT,
|
|
1090
|
+
target: this.#env,
|
|
1091
|
+
uniforms: {
|
|
1092
|
+
uRims: levels.rims,
|
|
1093
|
+
uFill: levels.fill,
|
|
1094
|
+
uScrim: levels.scrim,
|
|
1095
|
+
uCameraSide: levels.cameraSide,
|
|
1096
|
+
uCameraTexture: levels.cameraTexture,
|
|
1097
|
+
uBehind: levels.behind,
|
|
1098
|
+
uBlobs: this.#blobs.blobs,
|
|
1099
|
+
uBlobNorm: this.#blobs.norm,
|
|
1100
|
+
},
|
|
1101
|
+
});
|
|
1102
|
+
this.#envDrawn = levels;
|
|
1103
|
+
}
|
|
1104
|
+
const waves = this.#waves;
|
|
1105
|
+
const tier = this.#tier();
|
|
1106
|
+
const tr = tier.trips;
|
|
1107
|
+
const L = this.#lights;
|
|
1108
|
+
const bins = atlas.bins[tier.defines.NB === 6 ? 6 : 8];
|
|
1109
|
+
// the uniforms take 8 bins; the low tier's 6 leave the rest zero
|
|
1110
|
+
const binLam = this.#binLam.fill(0);
|
|
1111
|
+
binLam.set(bins.lambda);
|
|
1112
|
+
const binW = this.#binW.fill(0);
|
|
1113
|
+
binW.set(bins.W);
|
|
1114
|
+
const emb = this.#renderDef?.emboss ? this.#embossUniforms(ctx) : {};
|
|
1115
|
+
const persp = !this.params.flat;
|
|
1116
|
+
const card = {
|
|
1117
|
+
uCardRot: this.#cardRot,
|
|
1118
|
+
uPrevCardRot: this.#prevCardRot,
|
|
1119
|
+
uCardSizeMm: this.#domainMm,
|
|
1120
|
+
uCardWorldMm: this.#cardSizeMm,
|
|
1121
|
+
uVisRot: this.#visRot,
|
|
1122
|
+
uViewProj: this.#viewProj,
|
|
1123
|
+
uPersp: persp ? 1 : 0,
|
|
1124
|
+
};
|
|
1125
|
+
// the emboss paper is the whole card
|
|
1126
|
+
const mask = this.#renderDef?.id === "emboss"
|
|
1127
|
+
? SOURCE_CHANNELS.none
|
|
1128
|
+
: (SOURCE_CHANNELS[this.params.sourceChannel] ?? 0);
|
|
1129
|
+
if (persp) {
|
|
1130
|
+
ctx.clear(this.#hdr);
|
|
1131
|
+
if (mask === 1) {
|
|
1132
|
+
const base = this.#ensureBase(ctx);
|
|
1133
|
+
ctx.clear(base);
|
|
1134
|
+
ctx.draw({
|
|
1135
|
+
frag: shader_js_1.FRAG_CARD_BASE,
|
|
1136
|
+
vert: shader_js_1.CARD_VERT,
|
|
1137
|
+
target: base,
|
|
1138
|
+
uniforms: { ...card, src: ctx.src },
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
ctx.draw({
|
|
1143
|
+
frag: this.#frag,
|
|
1144
|
+
vert: shader_js_1.CARD_VERT,
|
|
1145
|
+
target: this.#hdr,
|
|
1146
|
+
uniforms: {
|
|
1147
|
+
...this.#matUniforms,
|
|
1148
|
+
...emb,
|
|
1149
|
+
...card,
|
|
1150
|
+
cameraPosition: [...this.#camPos],
|
|
1151
|
+
uWrapMm: [0, 0],
|
|
1152
|
+
uBowMm: s.card.bowMm,
|
|
1153
|
+
uBowAxis: s.card.bowAxis === "along" ? 1 : 0,
|
|
1154
|
+
uLightType: L.type,
|
|
1155
|
+
uLightOrder: L.order,
|
|
1156
|
+
uLightPos: L.pos,
|
|
1157
|
+
uPrevLightPos: this.#prevLightPos,
|
|
1158
|
+
uLightU: L.u,
|
|
1159
|
+
uLightW: L.w,
|
|
1160
|
+
uLightRadius: L.radius,
|
|
1161
|
+
uLightRad: L.rad,
|
|
1162
|
+
uLightSpd: L.spd,
|
|
1163
|
+
uLightRGB: L.rgb,
|
|
1164
|
+
uEtaOrd: this.#eta.ord,
|
|
1165
|
+
uEtaMir: this.#eta.mir,
|
|
1166
|
+
uEtaEnv: this.#eta.env,
|
|
1167
|
+
uKeyLight: L.key,
|
|
1168
|
+
uMaxOrder: tr.maxOrder,
|
|
1169
|
+
uGhB: tr.ghB,
|
|
1170
|
+
uVorR: tr.vorR,
|
|
1171
|
+
uFlakeR: tr.flakeR,
|
|
1172
|
+
uBCells: tr.bCells,
|
|
1173
|
+
uBBins: tr.bBins,
|
|
1174
|
+
uBLevels: tr.bLevels,
|
|
1175
|
+
uEnv: this.#env ?? this.#black,
|
|
1176
|
+
uEnvMaxLod: env_js_1.ENV_LEVELS - 1,
|
|
1177
|
+
uEnvIntensity: 1,
|
|
1178
|
+
uEnvRot: (0, env_js_1.envRotation)(s.studio.ambient.rotationDeg, this.#rigInv ?? undefined),
|
|
1179
|
+
uEnvUniform: 0,
|
|
1180
|
+
uCmfConv: this.#conv,
|
|
1181
|
+
uCmfCum: this.#cum,
|
|
1182
|
+
uSpecProj: atlas.specProj,
|
|
1183
|
+
uBinLam: binLam,
|
|
1184
|
+
uBinW: binW,
|
|
1185
|
+
uBinWidth: bins.width,
|
|
1186
|
+
uLtc1: this.#ltc1 ?? this.#black,
|
|
1187
|
+
uLtc2: this.#ltc2 ?? this.#black,
|
|
1188
|
+
uWave: waves?.data ?? NO_WAVES,
|
|
1189
|
+
uWaveBoard: waves?.board ?? [0, 0],
|
|
1190
|
+
uWaveCoat: waves?.coat ?? [0, 0],
|
|
1191
|
+
uBumpMode: 0,
|
|
1192
|
+
uBumpMom: this.#black,
|
|
1193
|
+
uBumpCross: this.#black,
|
|
1194
|
+
uBumpScale: [1, 1],
|
|
1195
|
+
uBumpK: [0, 0],
|
|
1196
|
+
uWear: s.card.wear,
|
|
1197
|
+
uDebugLight: 1,
|
|
1198
|
+
uPrintSrc: ctx.src,
|
|
1199
|
+
uMask: mask,
|
|
1200
|
+
uInk: Math.min(Math.max(this.params.ink, 0), 1),
|
|
1201
|
+
},
|
|
1202
|
+
});
|
|
1203
|
+
const hw = this.#hdr.width;
|
|
1204
|
+
const hh = this.#hdr.height;
|
|
1205
|
+
const div = tier.glareStartDiv;
|
|
1206
|
+
let gw0 = 0;
|
|
1207
|
+
const glare = s.display.glare;
|
|
1208
|
+
if (glare > 0) {
|
|
1209
|
+
this.#glare.ensure(ctx, hw, hh, tier.glareLevels, div);
|
|
1210
|
+
gw0 = this.#glare.render(ctx, this.#hdr, hw, hh, div, s.display.glareRadiusPx, ctx.pixelRatio);
|
|
1211
|
+
}
|
|
1212
|
+
const g0 = glare > 0 ? this.#glare.level0 : null;
|
|
1213
|
+
ctx.draw({
|
|
1214
|
+
frag: FRAG_OUTPUT,
|
|
1215
|
+
target: ctx.target,
|
|
1216
|
+
uniforms: {
|
|
1217
|
+
tHdr: this.#hdr,
|
|
1218
|
+
src: ctx.src,
|
|
1219
|
+
uExposure: (0, settings_js_1.exposureMultiplier)(s.display.ev, tone),
|
|
1220
|
+
uTone: TONES[s.display.tone],
|
|
1221
|
+
uP3: 0,
|
|
1222
|
+
uMask: mask,
|
|
1223
|
+
uPersp: persp ? 1 : 0,
|
|
1224
|
+
uBase: (persp && mask === 1 && this.#base) || this.#black,
|
|
1225
|
+
tG0: g0 ?? this.#black,
|
|
1226
|
+
uGW0: gw0,
|
|
1227
|
+
uGlare: g0 ? glare : 0,
|
|
1228
|
+
uG0Scale: g0 ? this.#glare.outputScale(hw, hh, div) : [1, 1],
|
|
1229
|
+
...grainUniforms(s.grain, ctx.pixelRatio, ctx.time),
|
|
1230
|
+
},
|
|
1231
|
+
});
|
|
1232
|
+
this.#drawnOnce = true;
|
|
1233
|
+
this.#settleReady();
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* The logo's placement in the card's surface frame [mm]: `emboss.x` / `emboss.y` / `emboss.width` are CSS px of the
|
|
1237
|
+
* element (centre and 36/63 of the width when unset), converted with the frame's mm per px.
|
|
1238
|
+
*/
|
|
1239
|
+
#logoPlacement() {
|
|
1240
|
+
const v = this.#resolved?.values ?? {};
|
|
1241
|
+
const px = (id) => {
|
|
1242
|
+
const x = v[id];
|
|
1243
|
+
return typeof x === "number" && Number.isFinite(x) ? x : null;
|
|
1244
|
+
};
|
|
1245
|
+
const [ew, eh] = this.#elemCss;
|
|
1246
|
+
const mmPerPx = this.#domainMm[0] / Math.max(ew, 1);
|
|
1247
|
+
const x = px("emboss.x") ?? ew / 2;
|
|
1248
|
+
const y = px("emboss.y") ?? eh / 2;
|
|
1249
|
+
// the element as the logo fills the element; an image logo is 36/63 of its width (holo.spot's proportion)
|
|
1250
|
+
const w = px("emboss.width") ??
|
|
1251
|
+
(v["emboss.logo"] === "element" ? ew : (ew * 36) / 63);
|
|
1252
|
+
const rot = ((px("emboss.rotation") ?? 0) * Math.PI) / 180;
|
|
1253
|
+
return {
|
|
1254
|
+
uLogoXf: [
|
|
1255
|
+
(x - ew / 2) * mmPerPx,
|
|
1256
|
+
(eh / 2 - y) * mmPerPx, // CSS y runs down, the card frame's up
|
|
1257
|
+
Math.cos(rot),
|
|
1258
|
+
Math.sin(rot),
|
|
1259
|
+
],
|
|
1260
|
+
uLogoW: Math.max(w, 1) * mmPerPx,
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
/** How the logo image is read: `sourceChannel` picks alpha (holospot's coverage) or luminance, `emboss.threshold` the cut. */
|
|
1264
|
+
#logoReadOpts(frame) {
|
|
1265
|
+
const t = this.#resolved?.values["emboss.threshold"];
|
|
1266
|
+
return {
|
|
1267
|
+
frame,
|
|
1268
|
+
read: this.params.sourceChannel === "luminance" ? "luma" : "auto",
|
|
1269
|
+
threshold: typeof t === "number" ? t : 0.5,
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
/** What decides how the element logo is read (its cache key). */
|
|
1273
|
+
#readOptsKey() {
|
|
1274
|
+
const o = this.#logoReadOpts("full");
|
|
1275
|
+
return `${o.read}|${o.threshold}`;
|
|
1276
|
+
}
|
|
1277
|
+
/** emboss with the element as its logo, and neither `emboss.print` nor `emboss.paperColour`: no ground. */
|
|
1278
|
+
#clearPaper() {
|
|
1279
|
+
const v = this.#resolved?.values;
|
|
1280
|
+
return (this.#renderDef?.id === "emboss" &&
|
|
1281
|
+
v?.["emboss.logo"] === "element" &&
|
|
1282
|
+
!givenImage(v["emboss.print"]) &&
|
|
1283
|
+
this.#p.settings["emboss.paperColour"] === undefined);
|
|
1284
|
+
}
|
|
1285
|
+
// ---- the element as the logo: read back once per size / `holo` (a still element)
|
|
1286
|
+
#capRt = null;
|
|
1287
|
+
#capKey = "";
|
|
1288
|
+
#capGen = 0;
|
|
1289
|
+
#capTries = 0;
|
|
1290
|
+
#capPending = false;
|
|
1291
|
+
/** A readback is on its way; the token drops one that arrives after #release or a restore. */
|
|
1292
|
+
#capInFlight = false;
|
|
1293
|
+
#capToken = 0;
|
|
1294
|
+
/** Hash of the last pixels read back, so an unchanged element does not rebuild the logo. */
|
|
1295
|
+
#capHash = "";
|
|
1296
|
+
#captureElementLogo(ctx) {
|
|
1297
|
+
const [pw, ph] = ctx.dims.elementPixel;
|
|
1298
|
+
const k = Math.min(1, 1024 / Math.max(pw, ph, 1));
|
|
1299
|
+
const w = Math.max(1, Math.round(pw * k));
|
|
1300
|
+
const h = Math.max(1, Math.round(ph * k));
|
|
1301
|
+
const key = `${w}x${h}|${this.#capGen}|${this.#readOptsKey()}`;
|
|
1302
|
+
if (key === this.#capKey || this.#capInFlight) {
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
this.#capPending = true;
|
|
1306
|
+
if (!this.#capRt ||
|
|
1307
|
+
this.#capRt.width !== w ||
|
|
1308
|
+
this.#capRt.height !== h) {
|
|
1309
|
+
this.#capRt?.dispose();
|
|
1310
|
+
this.#capRt = ctx.createRenderTarget({ size: [w, h] });
|
|
1311
|
+
}
|
|
1312
|
+
(0, _capture_js_1.captureContent)(ctx, this.#capRt);
|
|
1313
|
+
// read back without stalling the GPU: 8 bit, premultiplied, rows top-down; it resolves a frame or so later
|
|
1314
|
+
this.#capInFlight = true;
|
|
1315
|
+
const token = this.#capToken;
|
|
1316
|
+
ctx.readPixels(this.#capRt, { flipY: true }).then((raw) => {
|
|
1317
|
+
if (token === this.#capToken) {
|
|
1318
|
+
this.#capInFlight = false;
|
|
1319
|
+
this.#useElementLogo(raw, w, h, key);
|
|
1320
|
+
}
|
|
1321
|
+
}, () => {
|
|
1322
|
+
// disposed or context lost: #release / the restore start over
|
|
1323
|
+
if (token === this.#capToken) {
|
|
1324
|
+
this.#capInFlight = false;
|
|
1325
|
+
}
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
/** Turns the element read back (premultiplied, top-down) into the logo. */
|
|
1329
|
+
#useElementLogo(raw, w, h, key) {
|
|
1330
|
+
const px = new Uint8ClampedArray(w * h * 4);
|
|
1331
|
+
let visible = false;
|
|
1332
|
+
for (let i = 0; i < w * h * 4; i += 4) {
|
|
1333
|
+
const al = raw[i + 3];
|
|
1334
|
+
const u = al > 0 ? 255 / al : 0;
|
|
1335
|
+
px[i] = raw[i] * u;
|
|
1336
|
+
px[i + 1] = raw[i + 1] * u;
|
|
1337
|
+
px[i + 2] = raw[i + 2] * u;
|
|
1338
|
+
px[i + 3] = al;
|
|
1339
|
+
visible ||= al > 8;
|
|
1340
|
+
}
|
|
1341
|
+
// the element may not be drawn yet on the first frames: read it again for a while
|
|
1342
|
+
if (!visible && ++this.#capTries < 120) {
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
this.#capKey = key;
|
|
1346
|
+
this.#capTries = 0;
|
|
1347
|
+
this.#capPending = false;
|
|
1348
|
+
const hash = `${w}x${h}|${this.#readOptsKey()}|${fnv1a(px)}`;
|
|
1349
|
+
const a = this.#emboss;
|
|
1350
|
+
if (!a || hash === this.#capHash) {
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
this.#capHash = hash;
|
|
1354
|
+
const canvas = this.#makeCanvas(w, h);
|
|
1355
|
+
this.#ctx2d(canvas)?.putImageData(new ImageData(px, w, h), 0, 0);
|
|
1356
|
+
a.setLogo(visible ? canvas : "", this.#logoReadOpts("full"));
|
|
1357
|
+
}
|
|
1358
|
+
// ---- emboss.print: an image printed on the paper instead of the element
|
|
1359
|
+
#printWant = "";
|
|
1360
|
+
#printImg = null;
|
|
1361
|
+
#printTex = null;
|
|
1362
|
+
#printBusy = false;
|
|
1363
|
+
#printError = null;
|
|
1364
|
+
#printToken = 0;
|
|
1365
|
+
#printUniforms(ctx) {
|
|
1366
|
+
const want = this.#resolved?.values["emboss.print"] ?? "";
|
|
1367
|
+
if (want !== this.#printWant) {
|
|
1368
|
+
this.#printWant = want;
|
|
1369
|
+
const token = ++this.#printToken;
|
|
1370
|
+
this.#printTex?.dispose();
|
|
1371
|
+
this.#printTex = null;
|
|
1372
|
+
this.#printImg = null;
|
|
1373
|
+
this.#printError = null;
|
|
1374
|
+
this.#printBusy = false;
|
|
1375
|
+
// a URL, or an <img> that has not loaded yet: decode it first (a texture of an unloaded image would stay
|
|
1376
|
+
// 0 × 0); a loaded image, a canvas or an ImageBitmap is used at once
|
|
1377
|
+
let pending = null;
|
|
1378
|
+
if (typeof want === "string" && want.trim() !== "") {
|
|
1379
|
+
pending = new Image();
|
|
1380
|
+
pending.crossOrigin = "anonymous";
|
|
1381
|
+
pending.src = want.trim();
|
|
1382
|
+
}
|
|
1383
|
+
else if (isImgElement(want) &&
|
|
1384
|
+
!(want.complete && want.naturalWidth > 0)) {
|
|
1385
|
+
pending = want;
|
|
1386
|
+
}
|
|
1387
|
+
else if (givenImage(want)) {
|
|
1388
|
+
this.#printImg = want;
|
|
1389
|
+
}
|
|
1390
|
+
if (pending) {
|
|
1391
|
+
const img = pending;
|
|
1392
|
+
const label = typeof want === "string" ? ` ${want}` : "";
|
|
1393
|
+
this.#printBusy = true;
|
|
1394
|
+
img.decode().then(() => {
|
|
1395
|
+
if (token === this.#printToken) {
|
|
1396
|
+
this.#printImg = img;
|
|
1397
|
+
this.#printBusy = false;
|
|
1398
|
+
}
|
|
1399
|
+
}, (e) => {
|
|
1400
|
+
if (token === this.#printToken) {
|
|
1401
|
+
this.#printError = `HoloEffect: could not load emboss.print${label}: ${(e instanceof Error ? e.message : String(e)).replace(/\.$/, "")}. A cross-origin image needs CORS.`;
|
|
1402
|
+
console.warn(this.#printError);
|
|
1403
|
+
this.#printBusy = false;
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
const img = this.#printImg;
|
|
1409
|
+
if (img && !this.#printTex) {
|
|
1410
|
+
this.#printTex = ctx.wrapTexture(img, { autoUpdate: false });
|
|
1411
|
+
}
|
|
1412
|
+
// the print: emboss.print once it is loaded (none while it loads or after it fails, not the element), else
|
|
1413
|
+
// the element, unless the element is the logo
|
|
1414
|
+
const v = this.#resolved?.values ?? {};
|
|
1415
|
+
const ink = typeof v["emboss.printInk"] === "number" ? v["emboss.printInk"] : 1;
|
|
1416
|
+
const printOn = givenImage(want)
|
|
1417
|
+
? !!this.#printTex
|
|
1418
|
+
: v["emboss.logo"] !== "element";
|
|
1419
|
+
const uPrintK = [printOn ? 1 : 0, Math.min(Math.max(ink, 0), 1), 0, 0];
|
|
1420
|
+
if (!img || !this.#printTex) {
|
|
1421
|
+
return {
|
|
1422
|
+
uPrintK,
|
|
1423
|
+
uPrintOwn: 0,
|
|
1424
|
+
uPrintImg: this.#black ?? ctx.src,
|
|
1425
|
+
uPrintRect: [0, 0, 1, 1],
|
|
1426
|
+
};
|
|
1427
|
+
}
|
|
1428
|
+
// cover the element, as CSS background-size: cover
|
|
1429
|
+
const iw = isImgElement(img) ? img.naturalWidth : img.width;
|
|
1430
|
+
const ih = isImgElement(img) ? img.naturalHeight : img.height;
|
|
1431
|
+
const ae = this.#elemCss[0] / Math.max(this.#elemCss[1], 1);
|
|
1432
|
+
const ai = iw / Math.max(ih, 1);
|
|
1433
|
+
const sx = ai > ae ? ae / ai : 1;
|
|
1434
|
+
const sy = ai > ae ? 1 : ai / ae;
|
|
1435
|
+
return {
|
|
1436
|
+
uPrintK,
|
|
1437
|
+
uPrintOwn: 1,
|
|
1438
|
+
uPrintImg: this.#printTex,
|
|
1439
|
+
uPrintRect: [(1 - sx) / 2, (1 - sy) / 2, sx, sy],
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
/** Uploads the Foil Emboss textures when they change and returns their uniforms. */
|
|
1443
|
+
#embossUniforms(ctx) {
|
|
1444
|
+
const a = this.#emboss;
|
|
1445
|
+
const black = this.#black;
|
|
1446
|
+
if (!a || !black) {
|
|
1447
|
+
return {};
|
|
1448
|
+
}
|
|
1449
|
+
if (this.#resolved?.values["emboss.logo"] === "element") {
|
|
1450
|
+
this.#captureElementLogo(ctx);
|
|
1451
|
+
}
|
|
1452
|
+
const print = this.#printUniforms(ctx);
|
|
1453
|
+
if (a.logoVersion !== this.#logoUp) {
|
|
1454
|
+
this.#logoUp = a.logoVersion;
|
|
1455
|
+
const l = a.logo;
|
|
1456
|
+
if (l) {
|
|
1457
|
+
const { w, h } = l.image;
|
|
1458
|
+
if (!this.#logoRt ||
|
|
1459
|
+
this.#logoRt.width !== w ||
|
|
1460
|
+
this.#logoRt.height !== h) {
|
|
1461
|
+
this.#logoRt?.dispose();
|
|
1462
|
+
this.#logoRt = ctx.createRenderTarget({
|
|
1463
|
+
size: [w, h],
|
|
1464
|
+
float: true,
|
|
1465
|
+
filter: "linear",
|
|
1466
|
+
mipmap: true,
|
|
1467
|
+
wrap: "clamp",
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
this.#upload(ctx, l.image, this.#logoRt);
|
|
1471
|
+
this.#logoMap = l.map;
|
|
1472
|
+
}
|
|
1473
|
+
else {
|
|
1474
|
+
this.#logoRt?.dispose();
|
|
1475
|
+
this.#logoRt = null;
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
if (a.paperVersion !== this.#paperUp && a.paper) {
|
|
1479
|
+
this.#paperUp = a.paperVersion;
|
|
1480
|
+
const n = a.paper.mom.w;
|
|
1481
|
+
const opts = {
|
|
1482
|
+
size: [n, n],
|
|
1483
|
+
float: true,
|
|
1484
|
+
filter: "linear",
|
|
1485
|
+
mipmap: true,
|
|
1486
|
+
wrap: "repeat",
|
|
1487
|
+
};
|
|
1488
|
+
this.#paperRt ??= {
|
|
1489
|
+
mom: ctx.createRenderTarget(opts),
|
|
1490
|
+
aux: ctx.createRenderTarget(opts),
|
|
1491
|
+
};
|
|
1492
|
+
this.#upload(ctx, a.paper.mom, this.#paperRt.mom);
|
|
1493
|
+
this.#upload(ctx, a.paper.aux, this.#paperRt.aux);
|
|
1494
|
+
}
|
|
1495
|
+
return {
|
|
1496
|
+
...print,
|
|
1497
|
+
...this.#logoPlacement(),
|
|
1498
|
+
uLogoTex: this.#logoRt ?? black,
|
|
1499
|
+
uLogoOn: this.#logoRt ? 1 : 0,
|
|
1500
|
+
uLogoMap: this.#logoMap,
|
|
1501
|
+
uPaperMom: this.#paperRt?.mom ?? black,
|
|
1502
|
+
uPaperAux: this.#paperRt?.aux ?? black,
|
|
1503
|
+
uPaperOn: this.#paperRt ? 1 : 0,
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
/** One float RGBA byte image (emboss-assets.ts) → a float target, through a canvas and the decode pass. */
|
|
1507
|
+
#upload(ctx, img, target) {
|
|
1508
|
+
const canvas = this.#makeCanvas(4 * img.w, img.h);
|
|
1509
|
+
this.#ctx2d(canvas)?.putImageData(new ImageData(img.bytes, 4 * img.w, img.h), 0, 0);
|
|
1510
|
+
const tex = ctx.wrapTexture(canvas, {
|
|
1511
|
+
autoUpdate: false,
|
|
1512
|
+
filter: "nearest",
|
|
1513
|
+
});
|
|
1514
|
+
ctx.draw({
|
|
1515
|
+
frag: FRAG_DECODE_RGBA,
|
|
1516
|
+
vert: shader_js_1.PLAIN_VERT,
|
|
1517
|
+
target,
|
|
1518
|
+
uniforms: { uBytes: tex, uRowOffset: 0 },
|
|
1519
|
+
});
|
|
1520
|
+
tex.dispose();
|
|
1521
|
+
}
|
|
1522
|
+
dispose() {
|
|
1523
|
+
this.#life++;
|
|
1524
|
+
this.#restoreUnsub?.();
|
|
1525
|
+
this.#restoreUnsub = null;
|
|
1526
|
+
this.#release();
|
|
1527
|
+
// a pending ready resolves: nothing more is drawn until the next init
|
|
1528
|
+
this.#drawnOnce = false;
|
|
1529
|
+
this.#disposed = true;
|
|
1530
|
+
const w = this.#readyWaiters;
|
|
1531
|
+
this.#readyWaiters = [];
|
|
1532
|
+
for (const f of w) {
|
|
1533
|
+
f();
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
/** Frees the GPU resources and forgets what was drawn into them (dispose, and a restored context). */
|
|
1537
|
+
#release() {
|
|
1538
|
+
for (const rt of [
|
|
1539
|
+
this.#conv,
|
|
1540
|
+
this.#cum,
|
|
1541
|
+
this.#hdr,
|
|
1542
|
+
this.#base,
|
|
1543
|
+
this.#black,
|
|
1544
|
+
this.#env,
|
|
1545
|
+
this.#ltc1,
|
|
1546
|
+
this.#ltc2,
|
|
1547
|
+
]) {
|
|
1548
|
+
rt?.dispose();
|
|
1549
|
+
}
|
|
1550
|
+
this.#bytesTex?.dispose();
|
|
1551
|
+
this.#ltcTex?.dispose();
|
|
1552
|
+
this.#glare.dispose();
|
|
1553
|
+
this.#releaseEmboss();
|
|
1554
|
+
this.#conv = this.#cum = this.#hdr = this.#black = this.#env = null;
|
|
1555
|
+
this.#base = null;
|
|
1556
|
+
this.#ltc1 = this.#ltc2 = null;
|
|
1557
|
+
this.#bytesTex = this.#ltcTex = null;
|
|
1558
|
+
this.#atlasUploaded = -1;
|
|
1559
|
+
this.#ltcReady = false;
|
|
1560
|
+
this.#blackReady = false;
|
|
1561
|
+
this.#envDrawn = null;
|
|
1562
|
+
}
|
|
1563
|
+
/** Frees what only `emboss` uses: its workers, logo and paper maps, the element read back as the logo, and `emboss.print`. */
|
|
1564
|
+
#releaseEmboss() {
|
|
1565
|
+
this.#emboss?.dispose();
|
|
1566
|
+
this.#emboss = null;
|
|
1567
|
+
this.#logoRt?.dispose();
|
|
1568
|
+
this.#logoRt = null;
|
|
1569
|
+
this.#paperRt?.mom.dispose();
|
|
1570
|
+
this.#paperRt?.aux.dispose();
|
|
1571
|
+
this.#paperRt = null;
|
|
1572
|
+
this.#logoUp = this.#paperUp = -1;
|
|
1573
|
+
this.#capRt?.dispose();
|
|
1574
|
+
this.#capRt = null;
|
|
1575
|
+
this.#capKey = "";
|
|
1576
|
+
this.#capHash = "";
|
|
1577
|
+
this.#capTries = 0;
|
|
1578
|
+
this.#capPending = false;
|
|
1579
|
+
this.#capInFlight = false;
|
|
1580
|
+
this.#capToken++;
|
|
1581
|
+
this.#printTex?.dispose();
|
|
1582
|
+
this.#printTex = null;
|
|
1583
|
+
this.#printImg = null;
|
|
1584
|
+
this.#printWant = "";
|
|
1585
|
+
this.#printToken++;
|
|
1586
|
+
this.#printBusy = false;
|
|
1587
|
+
this.#printError = null;
|
|
1588
|
+
}
|
|
1589
|
+
#uploadAtlas(ctx, atlas) {
|
|
1590
|
+
const canvas = this.#bytesCanvas;
|
|
1591
|
+
const c2d = canvas ? this.#ctx2d(canvas) : null;
|
|
1592
|
+
if (!c2d || !this.#bytesTex || !this.#conv || !this.#cum) {
|
|
1593
|
+
return;
|
|
1594
|
+
}
|
|
1595
|
+
c2d.putImageData(new ImageData(atlas.bytes, atlas_js_1.ATLAS.imageWidth, atlas_js_1.ATLAS.imageHeight), 0, 0);
|
|
1596
|
+
this.#bytesTex.update();
|
|
1597
|
+
ctx.draw({
|
|
1598
|
+
frag: FRAG_DECODE,
|
|
1599
|
+
vert: shader_js_1.PLAIN_VERT,
|
|
1600
|
+
target: this.#conv,
|
|
1601
|
+
uniforms: { uBytes: this.#bytesTex, uRowOffset: 0 },
|
|
1602
|
+
});
|
|
1603
|
+
ctx.draw({
|
|
1604
|
+
frag: FRAG_DECODE,
|
|
1605
|
+
vert: shader_js_1.PLAIN_VERT,
|
|
1606
|
+
target: this.#cum,
|
|
1607
|
+
uniforms: { uBytes: this.#bytesTex, uRowOffset: atlas_js_1.ATLAS.height },
|
|
1608
|
+
});
|
|
1609
|
+
this.#atlasUploaded = atlas.version;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
exports.HoloEffect = HoloEffect;
|
|
1613
|
+
//# sourceMappingURL=holo.js.map
|