shaders 2.5.94 → 2.5.96
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/dist/core/Blur-CXXttTb1.js +138 -0
- package/dist/core/{ChannelBlur-CCaPXjka.js → ChannelBlur-gzP71FWd.js} +37 -2
- package/dist/core/{Crescent-DPxGWdPH.js → Crescent-BkRt-XWy.js} +1 -1
- package/dist/core/{Cross-CDyzf8TT.js → Cross-kkY7feuC.js} +1 -1
- package/dist/core/{Crystal-DSuN8TNY.js → Crystal-xVyUhVD-.js} +1 -1
- package/dist/core/CursorRipples-Cgm7N0Bp.js +289 -0
- package/dist/core/CursorTrail-CCRbdwHJ.js +263 -0
- package/dist/core/{Ellipse-BNmzdnpK.js → Ellipse-CXxGqTYI.js} +1 -1
- package/dist/core/{Emboss-nrduRrVs.js → Emboss-ClQV27Mt.js} +1 -1
- package/dist/core/{Flower-B4xPp0Qa.js → Flower-MAwlZEv8.js} +1 -1
- package/dist/core/{Glass-CRfTkmRy.js → Glass-DDBKYclp.js} +46 -8
- package/dist/core/Glow-BwaPYDRZ.js +174 -0
- package/dist/core/GridDistortion-DtaRNrTZ.js +278 -0
- package/dist/core/Liquify-cE5dxrfh.js +351 -0
- package/dist/core/{Neon-CUKnkAK8.js → Neon-Dg8UfC7P.js} +1 -1
- package/dist/core/{Polygon-C1y6Nyh4.js → Polygon-DRCs3CYs.js} +1 -1
- package/dist/core/ProgressiveBlur-B8xwWyTM.js +236 -0
- package/dist/core/{Ring-Chj1tp_P.js → Ring-QApyKPzE.js} +1 -1
- package/dist/core/{RoundedRect-BEj6tE1e.js → RoundedRect-Ca9af9xe.js} +1 -1
- package/dist/core/{Shatter-CZMOHj60.js → Shatter-BssZTRYJ.js} +154 -66
- package/dist/core/{Star-fPw1j10r.js → Star-DiXwnPGP.js} +1 -1
- package/dist/core/TiltShift-CI3FlfYk.js +252 -0
- package/dist/core/{Trapezoid-Cr61vRvN.js → Trapezoid-BX_hmeZJ.js} +1 -1
- package/dist/core/{Vesica-AXTA8DJU.js → Vesica-DU0f85NG.js} +1 -1
- package/dist/core/{VideoTexture-BobyGZGr.js → VideoTexture-DJrkry82.js} +1 -1
- package/dist/core/{WebcamTexture-BXj7sqND.js → WebcamTexture-Cf8J7JB1.js} +1 -1
- package/dist/core/computeBlur-C3oX720H.js +141 -0
- package/dist/core/effects/glass.d.ts +1 -1
- package/dist/core/effects/glass.d.ts.map +1 -1
- package/dist/core/index.js +213 -128
- package/dist/core/registry.js +102 -101
- package/dist/core/renderer.d.ts +19 -1
- package/dist/core/renderer.d.ts.map +1 -1
- package/dist/core/shaderRegistry-B_84rvO8.js +244 -0
- package/dist/core/shaders/Blur/index.d.ts.map +1 -1
- package/dist/core/shaders/Blur/index.js +2 -1
- package/dist/core/shaders/BrightnessContrast/index.js +1 -1
- package/dist/core/shaders/Bulge/index.js +1 -1
- package/dist/core/shaders/CRTScreen/index.js +1 -1
- package/dist/core/shaders/ChannelBlur/index.d.ts.map +1 -1
- package/dist/core/shaders/ChannelBlur/index.js +2 -1
- package/dist/core/shaders/Checkerboard/index.js +1 -1
- package/dist/core/shaders/ChromaFlow/index.js +1 -1
- package/dist/core/shaders/ChromaticAberration/index.js +1 -1
- package/dist/core/shaders/Circle/index.js +1 -1
- package/dist/core/shaders/ConcentricSpin/index.js +1 -1
- package/dist/core/shaders/ConicGradient/index.js +1 -1
- package/dist/core/shaders/ContourLines/index.js +1 -1
- package/dist/core/shaders/Crescent/index.js +2 -2
- package/dist/core/shaders/Cross/index.js +2 -2
- package/dist/core/shaders/Crystal/index.js +2 -2
- package/dist/core/shaders/CursorRipples/index.d.ts.map +1 -1
- package/dist/core/shaders/CursorRipples/index.js +1 -1
- package/dist/core/shaders/CursorTrail/index.d.ts.map +1 -1
- package/dist/core/shaders/CursorTrail/index.js +1 -1
- package/dist/core/shaders/DOMTexture/index.js +1 -1
- package/dist/core/shaders/DiamondGradient/index.js +1 -1
- package/dist/core/shaders/DiffuseBlur/index.js +1 -1
- package/dist/core/shaders/Dither/index.js +1 -1
- package/dist/core/shaders/DotGrid/index.js +1 -1
- package/dist/core/shaders/DropShadow/index.js +1 -1
- package/dist/core/shaders/Duotone/index.js +1 -1
- package/dist/core/shaders/Ellipse/index.js +2 -2
- package/dist/core/shaders/Emboss/index.js +2 -2
- package/dist/core/shaders/FallingLines/index.js +1 -1
- package/dist/core/shaders/FilmGrain/index.js +1 -1
- package/dist/core/shaders/FloatingParticles/index.js +1 -1
- package/dist/core/shaders/FlowField/index.js +1 -1
- package/dist/core/shaders/Flower/index.js +2 -2
- package/dist/core/shaders/FlowingGradient/index.js +1 -1
- package/dist/core/shaders/Form3D/index.js +1 -1
- package/dist/core/shaders/Glass/index.d.ts.map +1 -1
- package/dist/core/shaders/Glass/index.js +3 -2
- package/dist/core/shaders/GlassTiles/index.js +1 -1
- package/dist/core/shaders/Glitch/index.js +1 -1
- package/dist/core/shaders/Glow/index.d.ts.map +1 -1
- package/dist/core/shaders/Glow/index.js +2 -1
- package/dist/core/shaders/Godrays/index.js +1 -1
- package/dist/core/shaders/Grayscale/index.js +1 -1
- package/dist/core/shaders/Grid/index.js +1 -1
- package/dist/core/shaders/GridDistortion/index.d.ts.map +1 -1
- package/dist/core/shaders/GridDistortion/index.js +1 -1
- package/dist/core/shaders/Group/index.js +1 -1
- package/dist/core/shaders/Halftone/index.js +1 -1
- package/dist/core/shaders/HexGrid/index.js +1 -1
- package/dist/core/shaders/HueShift/index.js +1 -1
- package/dist/core/shaders/ImageTexture/index.js +1 -1
- package/dist/core/shaders/Invert/index.js +1 -1
- package/dist/core/shaders/Kaleidoscope/index.js +1 -1
- package/dist/core/shaders/LensFlare/index.js +1 -1
- package/dist/core/shaders/LinearBlur/index.js +1 -1
- package/dist/core/shaders/LinearGradient/index.js +1 -1
- package/dist/core/shaders/Liquify/index.d.ts.map +1 -1
- package/dist/core/shaders/Liquify/index.js +1 -1
- package/dist/core/shaders/Mirror/index.js +1 -1
- package/dist/core/shaders/MultiPointGradient/index.js +1 -1
- package/dist/core/shaders/Neon/index.js +2 -2
- package/dist/core/shaders/Paper/index.js +1 -1
- package/dist/core/shaders/Perspective/index.js +1 -1
- package/dist/core/shaders/Pixelate/index.js +1 -1
- package/dist/core/shaders/Plasma/index.js +1 -1
- package/dist/core/shaders/PolarCoordinates/index.js +1 -1
- package/dist/core/shaders/Polygon/index.js +2 -2
- package/dist/core/shaders/Posterize/index.js +1 -1
- package/dist/core/shaders/ProgressiveBlur/index.d.ts.map +1 -1
- package/dist/core/shaders/ProgressiveBlur/index.js +2 -1
- package/dist/core/shaders/RadialGradient/index.js +1 -1
- package/dist/core/shaders/RectangularCoordinates/index.js +1 -1
- package/dist/core/shaders/Ring/index.js +2 -2
- package/dist/core/shaders/Ripples/index.js +1 -1
- package/dist/core/shaders/RoundedRect/index.js +2 -2
- package/dist/core/shaders/Saturation/index.js +1 -1
- package/dist/core/shaders/Sharpness/index.js +1 -1
- package/dist/core/shaders/Shatter/index.d.ts.map +1 -1
- package/dist/core/shaders/Shatter/index.js +1 -1
- package/dist/core/shaders/SimplexNoise/index.js +1 -1
- package/dist/core/shaders/SineWave/index.js +1 -1
- package/dist/core/shaders/Solarize/index.js +1 -1
- package/dist/core/shaders/SolidColor/index.js +1 -1
- package/dist/core/shaders/Spherize/index.js +1 -1
- package/dist/core/shaders/Spiral/index.js +1 -1
- package/dist/core/shaders/Star/index.js +2 -2
- package/dist/core/shaders/Strands/index.js +1 -1
- package/dist/core/shaders/Stretch/index.js +1 -1
- package/dist/core/shaders/Stripes/index.js +1 -1
- package/dist/core/shaders/StudioBackground/index.js +1 -1
- package/dist/core/shaders/Swirl/index.js +1 -1
- package/dist/core/shaders/TiltShift/index.d.ts.map +1 -1
- package/dist/core/shaders/TiltShift/index.js +2 -1
- package/dist/core/shaders/Tint/index.js +1 -1
- package/dist/core/shaders/Trapezoid/index.js +2 -2
- package/dist/core/shaders/Tritone/index.js +1 -1
- package/dist/core/shaders/Truchet/index.js +1 -1
- package/dist/core/shaders/Twirl/index.js +1 -1
- package/dist/core/shaders/Vesica/index.js +2 -2
- package/dist/core/shaders/Vibrance/index.js +1 -1
- package/dist/core/shaders/VideoTexture/index.js +2 -2
- package/dist/core/shaders/Vignette/index.js +1 -1
- package/dist/core/shaders/Voronoi/index.js +1 -1
- package/dist/core/shaders/WaveDistortion/index.js +1 -1
- package/dist/core/shaders/Weave/index.js +1 -1
- package/dist/core/shaders/WebcamTexture/index.js +2 -2
- package/dist/core/shaders/ZoomBlur/index.js +1 -1
- package/dist/core/types.d.ts +49 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/utilities/computeBlur.d.ts +50 -0
- package/dist/core/utilities/computeBlur.d.ts.map +1 -0
- package/dist/js/createShader.js +1 -1
- package/dist/react/Shader.js +1 -1
- package/dist/registry.js +2 -2
- package/dist/solid/engine/Shader.js +1 -1
- package/dist/svelte/index.js +1 -1
- package/dist/vue/Shader.vue_vue_type_script_setup_true_lang.js +1 -1
- package/package.json +1 -1
- package/dist/core/Blur-DTyNQt1R.js +0 -78
- package/dist/core/CursorRipples-Bo-3LZoC.js +0 -186
- package/dist/core/CursorTrail-C-0lpOV1.js +0 -160
- package/dist/core/Glow-CKWIRcBt.js +0 -108
- package/dist/core/GridDistortion-DXM5MgSc.js +0 -183
- package/dist/core/Liquify-CqcAWBwZ.js +0 -228
- package/dist/core/ProgressiveBlur-BcHBSVDo.js +0 -128
- package/dist/core/TiltShift-BysRsV8v.js +0 -141
- package/dist/core/shaderRegistry-BzOzMO4V.js +0 -244
- /package/dist/core/{BrightnessContrast-BoR9bi58.js → BrightnessContrast-CJTOpQCn.js} +0 -0
- /package/dist/core/{Bulge-DN2R75Hp.js → Bulge-Chpbxxzj.js} +0 -0
- /package/dist/core/{CRTScreen-DolQEkb1.js → CRTScreen-CTwXU-NX.js} +0 -0
- /package/dist/core/{Checkerboard-_IUtUrDv.js → Checkerboard-ucave4-a.js} +0 -0
- /package/dist/core/{ChromaFlow-Cq6hDVjX.js → ChromaFlow-BZXyVHtK.js} +0 -0
- /package/dist/core/{ChromaticAberration-G8_bwQtD.js → ChromaticAberration-DsMj-vBw.js} +0 -0
- /package/dist/core/{Circle--0oHzoCi.js → Circle-QgCuVo44.js} +0 -0
- /package/dist/core/{ConcentricSpin-BzxzMieZ.js → ConcentricSpin-Crfxti93.js} +0 -0
- /package/dist/core/{ConicGradient-BXXizzIs.js → ConicGradient-CQAPYlQg.js} +0 -0
- /package/dist/core/{ContourLines-C0XSJEkE.js → ContourLines-KTHC32hd.js} +0 -0
- /package/dist/core/{DOMTexture-Dw3Qakny.js → DOMTexture-D-RkeyMs.js} +0 -0
- /package/dist/core/{DiamondGradient-TsOxHjg_.js → DiamondGradient-BC3ugP8a.js} +0 -0
- /package/dist/core/{DiffuseBlur-BqIV4JLM.js → DiffuseBlur-eyM1v3ad.js} +0 -0
- /package/dist/core/{Dither-D_YF6z03.js → Dither-CDfDotR6.js} +0 -0
- /package/dist/core/{DotGrid-CiDt4NmI.js → DotGrid-T9YbgC3V.js} +0 -0
- /package/dist/core/{DropShadow-BRoXryDA.js → DropShadow-jMhnYPXZ.js} +0 -0
- /package/dist/core/{Duotone-CGHcHB9f.js → Duotone-Bl02WcA2.js} +0 -0
- /package/dist/core/{FallingLines-vdw8KxhV.js → FallingLines-CArEXajJ.js} +0 -0
- /package/dist/core/{FilmGrain-BqQeKO6Z.js → FilmGrain-Ph73aoC_.js} +0 -0
- /package/dist/core/{FloatingParticles-DR5cv6Eh.js → FloatingParticles-BtwGRl_d.js} +0 -0
- /package/dist/core/{FlowField-DpP32B1X.js → FlowField-RyqiRxyI.js} +0 -0
- /package/dist/core/{FlowingGradient-lSouJxmq.js → FlowingGradient-C0Zoyfd6.js} +0 -0
- /package/dist/core/{Form3D-DQD-0zrd.js → Form3D-rKpxb9t3.js} +0 -0
- /package/dist/core/{GlassTiles-B7aAvcTQ.js → GlassTiles-k1C4a4u8.js} +0 -0
- /package/dist/core/{Glitch-CgmgjLea.js → Glitch-DzPMkBu4.js} +0 -0
- /package/dist/core/{Godrays-o-3Im6H1.js → Godrays-DAYmq-BP.js} +0 -0
- /package/dist/core/{Grayscale-Bip62olI.js → Grayscale-lYKBBkGY.js} +0 -0
- /package/dist/core/{Grid-hwQnF_hs.js → Grid-BJ-nxN3i.js} +0 -0
- /package/dist/core/{Group-BexPm4Fb.js → Group-DpozigtX.js} +0 -0
- /package/dist/core/{Halftone-onLYU4dF.js → Halftone-BVL2oy37.js} +0 -0
- /package/dist/core/{HexGrid-BkqEEgfh.js → HexGrid-D-EmQ4kI.js} +0 -0
- /package/dist/core/{HueShift-BldS-av9.js → HueShift-D9K0ynaS.js} +0 -0
- /package/dist/core/{ImageTexture-DLCjc5cM.js → ImageTexture-CArkZMfh.js} +0 -0
- /package/dist/core/{Invert-C2LI5GXr.js → Invert-DCnwo_Xq.js} +0 -0
- /package/dist/core/{Kaleidoscope-CxWjs5jx.js → Kaleidoscope-BytHro3k.js} +0 -0
- /package/dist/core/{LensFlare-BNO7tCXH.js → LensFlare-B0vv4x97.js} +0 -0
- /package/dist/core/{LinearBlur-Ds6rm8u-.js → LinearBlur-BFewxPjV.js} +0 -0
- /package/dist/core/{LinearGradient-BZjDhnZp.js → LinearGradient-BKUf_u7r.js} +0 -0
- /package/dist/core/{Mirror-5W3sul9v.js → Mirror-DIle92J8.js} +0 -0
- /package/dist/core/{MultiPointGradient-lpUGnrLq.js → MultiPointGradient-DDwac_mm.js} +0 -0
- /package/dist/core/{Paper-14yYPnWW.js → Paper-bMSMCeYK.js} +0 -0
- /package/dist/core/{Perspective-POVbIGPc.js → Perspective-BmfvQV6W.js} +0 -0
- /package/dist/core/{Pixelate-CxUxBDeN.js → Pixelate-Dl26r6IT.js} +0 -0
- /package/dist/core/{Plasma-DM9TU0VN.js → Plasma-CJWS1TvX.js} +0 -0
- /package/dist/core/{PolarCoordinates-t4Wa00gQ.js → PolarCoordinates-lq6K4WBm.js} +0 -0
- /package/dist/core/{Posterize-Dk4DE8Ee.js → Posterize-BjH7Zscm.js} +0 -0
- /package/dist/core/{RadialGradient-CSXQIa5L.js → RadialGradient-DiGFPgrn.js} +0 -0
- /package/dist/core/{RectangularCoordinates-YaZ_uRXb.js → RectangularCoordinates-COkNDxi0.js} +0 -0
- /package/dist/core/{Ripples-wJx2FwJY.js → Ripples-C8Q17Hvz.js} +0 -0
- /package/dist/core/{Saturation-B500nPZH.js → Saturation-CgDaiq6n.js} +0 -0
- /package/dist/core/{Sharpness-NqY4_gKZ.js → Sharpness-CRXT0D30.js} +0 -0
- /package/dist/core/{SimplexNoise-2-J7EbY9.js → SimplexNoise-KfTCAfpL.js} +0 -0
- /package/dist/core/{SineWave-OWJVWsI1.js → SineWave-Ckeap_YM.js} +0 -0
- /package/dist/core/{Solarize-CEhQxL9Z.js → Solarize-DhtQYYpW.js} +0 -0
- /package/dist/core/{SolidColor-Dlzm61ZG.js → SolidColor-6yUkGybH.js} +0 -0
- /package/dist/core/{Spherize-CXf4_Mkm.js → Spherize-8LXrGGG_.js} +0 -0
- /package/dist/core/{Spiral-CSXNX92f.js → Spiral-Bs7uZrBr.js} +0 -0
- /package/dist/core/{Strands-BPVy1zbt.js → Strands-DsAAVemq.js} +0 -0
- /package/dist/core/{Stretch-CFAjfvny.js → Stretch-D7P2R5lV.js} +0 -0
- /package/dist/core/{Stripes-BSGzno-I.js → Stripes-DF8agIiJ.js} +0 -0
- /package/dist/core/{StudioBackground-81AihXcZ.js → StudioBackground-BFeNfwEu.js} +0 -0
- /package/dist/core/{Swirl-D_ZvZtDS.js → Swirl-BwezrSAA.js} +0 -0
- /package/dist/core/{Tint-C6xN-Qot.js → Tint-BdXlqlzz.js} +0 -0
- /package/dist/core/{Tritone-Dk8GcpYo.js → Tritone-BlJ7cchN.js} +0 -0
- /package/dist/core/{Truchet-BFd2XYD3.js → Truchet-Bnn0fwbF.js} +0 -0
- /package/dist/core/{Twirl-CA0r8U7e.js → Twirl-C5ijhqz1.js} +0 -0
- /package/dist/core/{Vibrance-Dq1jBFJb.js → Vibrance-dqIV6GBe.js} +0 -0
- /package/dist/core/{Vignette-DB8x78Up.js → Vignette-DB1wO1dm.js} +0 -0
- /package/dist/core/{Voronoi-ALXxxHBo.js → Voronoi-C3WIJFWc.js} +0 -0
- /package/dist/core/{WaveDistortion-CHb75HO3.js → WaveDistortion-BKma8-Ju.js} +0 -0
- /package/dist/core/{Weave-j4CrCig4.js → Weave-xuu_vQ5e.js} +0 -0
- /package/dist/core/{ZoomBlur-Cl75kL8E.js → ZoomBlur-UcS2iFT2.js} +0 -0
- /package/dist/core/{browser-DIoaEnIX.js → browser-ClWxLlIB.js} +0 -0
- /package/dist/core/{sdf-Bux00UoZ.js → sdf-DyC2H_qS.js} +0 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { t as applyEdgeHandling } from "./edges-CfGcQniB.js";
|
|
2
|
+
import { c as transformEdges } from "./transformations-B5lM6fYX.js";
|
|
3
|
+
import { t as unpremultiplyAlpha } from "./alpha-C4ptedXe.js";
|
|
4
|
+
import { StorageTexture } from "three/webgpu";
|
|
5
|
+
import { DataTexture, FloatType, LinearFilter as LinearFilter$1, RGFormat } from "three";
|
|
6
|
+
import { Fn, If, attributeArray, convertToTexture, float, instanceIndex, screenUV, storageTexture, texture, textureStore, uint, uniform, uvec2, vec2, vec4, viewportSize } from "three/tsl";
|
|
7
|
+
var DEFAULT_GRID_SIZE = 20;
|
|
8
|
+
var displacementStateCache = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
var getOrCreateDisplacementState = (uniforms) => {
|
|
10
|
+
let state = displacementStateCache.get(uniforms);
|
|
11
|
+
const gridSize = uniforms?.gridSize?.uniform?.value ? Math.max(8, Math.min(128, Math.floor(uniforms.gridSize.uniform.value))) : DEFAULT_GRID_SIZE;
|
|
12
|
+
if (state && state.gridSize !== gridSize) {
|
|
13
|
+
state.dataTexture.dispose();
|
|
14
|
+
state = void 0;
|
|
15
|
+
displacementStateCache.delete(uniforms);
|
|
16
|
+
}
|
|
17
|
+
if (!state) {
|
|
18
|
+
const data = new Float32Array(gridSize * gridSize * 2);
|
|
19
|
+
const dataTexture = new DataTexture(data, gridSize, gridSize, RGFormat, FloatType);
|
|
20
|
+
dataTexture.magFilter = LinearFilter$1;
|
|
21
|
+
dataTexture.minFilter = LinearFilter$1;
|
|
22
|
+
dataTexture.needsUpdate = true;
|
|
23
|
+
state = {
|
|
24
|
+
dataTexture,
|
|
25
|
+
data,
|
|
26
|
+
tslNode: texture(dataTexture),
|
|
27
|
+
gridSize
|
|
28
|
+
};
|
|
29
|
+
displacementStateCache.set(uniforms, state);
|
|
30
|
+
}
|
|
31
|
+
return state;
|
|
32
|
+
};
|
|
33
|
+
const componentDefinition = {
|
|
34
|
+
name: "GridDistortion",
|
|
35
|
+
category: "Interactive",
|
|
36
|
+
description: "Interactive grid distortion controlled by mouse position",
|
|
37
|
+
requiresRTT: true,
|
|
38
|
+
requiresChild: true,
|
|
39
|
+
props: {
|
|
40
|
+
intensity: {
|
|
41
|
+
default: 1,
|
|
42
|
+
description: "Strength of the distortion effect",
|
|
43
|
+
ui: {
|
|
44
|
+
type: "range",
|
|
45
|
+
min: 0,
|
|
46
|
+
max: 5,
|
|
47
|
+
step: .1,
|
|
48
|
+
label: "Intensity",
|
|
49
|
+
group: "Effect"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
decay: {
|
|
53
|
+
default: 3,
|
|
54
|
+
description: "Rate of distortion decay (higher = faster)",
|
|
55
|
+
ui: {
|
|
56
|
+
type: "range",
|
|
57
|
+
min: 0,
|
|
58
|
+
max: 10,
|
|
59
|
+
step: .1,
|
|
60
|
+
label: "Decay",
|
|
61
|
+
group: "Effect"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
radius: {
|
|
65
|
+
default: 1,
|
|
66
|
+
description: "Radius of the distortion effect",
|
|
67
|
+
ui: {
|
|
68
|
+
type: "range",
|
|
69
|
+
min: 0,
|
|
70
|
+
max: 3,
|
|
71
|
+
step: .1,
|
|
72
|
+
label: "Radius",
|
|
73
|
+
group: "Effect"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
gridSize: {
|
|
77
|
+
default: 20,
|
|
78
|
+
description: "Resolution of the distortion grid (higher = more detailed)",
|
|
79
|
+
ui: {
|
|
80
|
+
type: ["range", "map"],
|
|
81
|
+
min: 8,
|
|
82
|
+
max: 128,
|
|
83
|
+
step: 1,
|
|
84
|
+
label: "Grid Size",
|
|
85
|
+
group: "Effect"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
edges: {
|
|
89
|
+
default: "stretch",
|
|
90
|
+
description: "How to handle edges when distortion pushes content out of bounds",
|
|
91
|
+
transform: transformEdges,
|
|
92
|
+
compileTime: true,
|
|
93
|
+
ui: {
|
|
94
|
+
type: "select",
|
|
95
|
+
options: [
|
|
96
|
+
{
|
|
97
|
+
label: "Stretch",
|
|
98
|
+
value: "stretch"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
label: "Transparent",
|
|
102
|
+
value: "transparent"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
label: "Mirror",
|
|
106
|
+
value: "mirror"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
label: "Wrap",
|
|
110
|
+
value: "wrap"
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
label: "Edges",
|
|
114
|
+
group: "Effect"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
computeNode: ({ uniforms, onCleanup, dimensions }) => {
|
|
119
|
+
const GRID_SIZE = uniforms?.gridSize?.uniform?.value ? Math.max(8, Math.min(128, Math.floor(uniforms.gridSize.uniform.value))) : DEFAULT_GRID_SIZE;
|
|
120
|
+
const buffer = attributeArray(GRID_SIZE * GRID_SIZE, "vec4");
|
|
121
|
+
const dispTex = new StorageTexture(GRID_SIZE, GRID_SIZE);
|
|
122
|
+
dispTex.type = FloatType;
|
|
123
|
+
const dispTexNode = storageTexture(dispTex);
|
|
124
|
+
onCleanup(() => {
|
|
125
|
+
dispTex.dispose();
|
|
126
|
+
});
|
|
127
|
+
const cursorXU = uniform(.5);
|
|
128
|
+
const cursorYU = uniform(.5);
|
|
129
|
+
const mouseVelXU = uniform(0);
|
|
130
|
+
const mouseVelYU = uniform(0);
|
|
131
|
+
const dtU = uniform(.016);
|
|
132
|
+
const decayU = uniform(3);
|
|
133
|
+
const intensityU = uniform(1);
|
|
134
|
+
const radiusU = uniform(.05);
|
|
135
|
+
const aspectU = uniform(1);
|
|
136
|
+
const gs = uint(GRID_SIZE);
|
|
137
|
+
const updatePass = Fn(() => {
|
|
138
|
+
const idx = instanceIndex;
|
|
139
|
+
const j = idx.mod(gs);
|
|
140
|
+
const i = idx.div(gs);
|
|
141
|
+
const cell = buffer.element(idx);
|
|
142
|
+
const dx = cell.x.mul(float(1).sub(decayU.mul(dtU))).toVar();
|
|
143
|
+
const dy = cell.y.mul(float(1).sub(decayU.mul(dtU))).toVar();
|
|
144
|
+
const cellX = j.toFloat().add(float(.5)).div(float(GRID_SIZE));
|
|
145
|
+
const cellY = i.toFloat().add(float(.5)).div(float(GRID_SIZE));
|
|
146
|
+
const ddx = aspectU.greaterThanEqual(float(1)).select(cellX.sub(cursorXU).mul(aspectU), cellX.sub(cursorXU));
|
|
147
|
+
const ddy = aspectU.greaterThanEqual(float(1)).select(cellY.sub(cursorYU), cellY.sub(cursorYU).div(aspectU));
|
|
148
|
+
const distSq = ddx.mul(ddx).add(ddy.mul(ddy));
|
|
149
|
+
const radius2 = radiusU.mul(float(2));
|
|
150
|
+
If(distSq.lessThan(radius2.mul(radius2)).and(mouseVelXU.abs().add(mouseVelYU.abs()).greaterThan(float(.01))), () => {
|
|
151
|
+
const influence = distSq.negate().div(radiusU.mul(radiusU)).exp();
|
|
152
|
+
dx.assign(dx.add(mouseVelXU.mul(influence).mul(intensityU).mul(dtU).mul(float(.5))));
|
|
153
|
+
dy.assign(dy.add(mouseVelYU.mul(influence).mul(intensityU).mul(dtU).mul(float(.5))));
|
|
154
|
+
});
|
|
155
|
+
dx.assign(dx.clamp(float(-1), float(1)));
|
|
156
|
+
dy.assign(dy.clamp(float(-1), float(1)));
|
|
157
|
+
buffer.element(idx).assign(vec4(dx, dy, float(0), float(0)));
|
|
158
|
+
})().compute(GRID_SIZE * GRID_SIZE, [256]);
|
|
159
|
+
const outputPass = Fn(() => {
|
|
160
|
+
const idx = instanceIndex;
|
|
161
|
+
const j = idx.mod(gs);
|
|
162
|
+
const i = idx.div(gs);
|
|
163
|
+
const cell = buffer.element(idx);
|
|
164
|
+
textureStore(dispTexNode, uvec2(j, i), vec4(cell.x, cell.y, float(0), float(1))).toWriteOnly();
|
|
165
|
+
})().compute(GRID_SIZE * GRID_SIZE, [256]);
|
|
166
|
+
let prevX = .5;
|
|
167
|
+
let prevY = .5;
|
|
168
|
+
let lastTime = Date.now();
|
|
169
|
+
let lastActiveTime = Date.now();
|
|
170
|
+
let smoothVelX = 0;
|
|
171
|
+
let smoothVelY = 0;
|
|
172
|
+
return {
|
|
173
|
+
outputs: {
|
|
174
|
+
displacement: dispTex,
|
|
175
|
+
gridSize: GRID_SIZE
|
|
176
|
+
},
|
|
177
|
+
getComputeNodes: (params) => {
|
|
178
|
+
const currentTime = Date.now();
|
|
179
|
+
const dt = Math.min((currentTime - lastTime) / 1e3, .016);
|
|
180
|
+
lastTime = currentTime;
|
|
181
|
+
const aspect = dimensions.width / Math.max(dimensions.height, 1);
|
|
182
|
+
const velX = dt > 0 ? (params.pointer.x - prevX) / dt : 0;
|
|
183
|
+
const velY = dt > 0 ? (params.pointer.y - prevY) / dt : 0;
|
|
184
|
+
smoothVelX = smoothVelX * .85 + velX * .15;
|
|
185
|
+
smoothVelY = smoothVelY * .85 + velY * .15;
|
|
186
|
+
prevX = params.pointer.x;
|
|
187
|
+
prevY = params.pointer.y;
|
|
188
|
+
if (Math.abs(velX) + Math.abs(velY) > .01) lastActiveTime = currentTime;
|
|
189
|
+
const decayVal = uniforms.decay.uniform.value;
|
|
190
|
+
const settleTime = decayVal > 0 ? Math.min(3e4, Math.log(1e-4) / Math.log(Math.max(1e-6, 1 - decayVal * .016)) * 16.67) : 3e4;
|
|
191
|
+
if (currentTime - lastActiveTime > settleTime) return null;
|
|
192
|
+
cursorXU.value = params.pointer.x;
|
|
193
|
+
cursorYU.value = params.pointer.y;
|
|
194
|
+
mouseVelXU.value = smoothVelX;
|
|
195
|
+
mouseVelYU.value = smoothVelY;
|
|
196
|
+
dtU.value = dt;
|
|
197
|
+
decayU.value = uniforms.decay.uniform.value;
|
|
198
|
+
intensityU.value = uniforms.intensity.uniform.value;
|
|
199
|
+
radiusU.value = uniforms.radius.uniform.value * .05;
|
|
200
|
+
aspectU.value = aspect;
|
|
201
|
+
return [updatePass, outputPass];
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
},
|
|
205
|
+
fragmentNode: ({ uniforms, onBeforeRender, childNode, onCleanup, dimensions, computeOutputs }) => {
|
|
206
|
+
let displacementField;
|
|
207
|
+
let GRID_SIZE;
|
|
208
|
+
if (computeOutputs?.displacement) {
|
|
209
|
+
displacementField = texture(computeOutputs.displacement);
|
|
210
|
+
GRID_SIZE = computeOutputs.gridSize;
|
|
211
|
+
} else {
|
|
212
|
+
const state = getOrCreateDisplacementState(uniforms);
|
|
213
|
+
displacementField = state.tslNode;
|
|
214
|
+
GRID_SIZE = state.gridSize;
|
|
215
|
+
const { dataTexture: displacementTexture, data: displacementData } = state;
|
|
216
|
+
const mouseVelX = uniform(0);
|
|
217
|
+
const mouseVelY = uniform(0);
|
|
218
|
+
let prevX = .5, prevY = .5, lastTime = Date.now();
|
|
219
|
+
onBeforeRender(({ pointer }) => {
|
|
220
|
+
const currentTime = Date.now();
|
|
221
|
+
const dt = Math.min((currentTime - lastTime) / 1e3, .016);
|
|
222
|
+
lastTime = currentTime;
|
|
223
|
+
const aspect$1 = Math.max(1, dimensions.width) / Math.max(1, dimensions.height);
|
|
224
|
+
const velX = dt > 0 ? (pointer.x - prevX) / dt : 0;
|
|
225
|
+
const velY = dt > 0 ? (pointer.y - prevY) / dt : 0;
|
|
226
|
+
mouseVelX.value = mouseVelX.value * .85 + velX * .15;
|
|
227
|
+
mouseVelY.value = mouseVelY.value * .85 + velY * .15;
|
|
228
|
+
const decay = uniforms.decay.uniform.value;
|
|
229
|
+
const intensity = uniforms.intensity.uniform.value;
|
|
230
|
+
const radius = uniforms.radius.uniform.value * .05;
|
|
231
|
+
for (let i = 0; i < GRID_SIZE; i++) for (let j = 0; j < GRID_SIZE; j++) {
|
|
232
|
+
const idx = (i * GRID_SIZE + j) * 2;
|
|
233
|
+
displacementData[idx] *= 1 - decay * dt;
|
|
234
|
+
displacementData[idx + 1] *= 1 - decay * dt;
|
|
235
|
+
const cellX = (j + .5) / GRID_SIZE;
|
|
236
|
+
const cellY = (i + .5) / GRID_SIZE;
|
|
237
|
+
const dx = aspect$1 >= 1 ? (cellX - pointer.x) * aspect$1 : cellX - pointer.x;
|
|
238
|
+
const dy = aspect$1 >= 1 ? cellY - pointer.y : (cellY - pointer.y) / aspect$1;
|
|
239
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
240
|
+
if (dist < radius * 2 && Math.abs(velX) + Math.abs(velY) > .01) {
|
|
241
|
+
const influence = Math.exp(-dist * dist / (radius * radius));
|
|
242
|
+
displacementData[idx] += mouseVelX.value * influence * intensity * dt * .5;
|
|
243
|
+
displacementData[idx + 1] += mouseVelY.value * influence * intensity * dt * .5;
|
|
244
|
+
}
|
|
245
|
+
displacementData[idx] = Math.max(-1, Math.min(1, displacementData[idx]));
|
|
246
|
+
displacementData[idx + 1] = Math.max(-1, Math.min(1, displacementData[idx + 1]));
|
|
247
|
+
}
|
|
248
|
+
displacementTexture.needsUpdate = true;
|
|
249
|
+
prevX = pointer.x;
|
|
250
|
+
prevY = pointer.y;
|
|
251
|
+
});
|
|
252
|
+
onCleanup(() => {
|
|
253
|
+
displacementTexture.dispose();
|
|
254
|
+
displacementStateCache.delete(uniforms);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
if (!childNode) return vec4(0, 0, 0, 0);
|
|
258
|
+
const childTexture = convertToTexture(childNode);
|
|
259
|
+
onCleanup(() => {
|
|
260
|
+
if (childTexture?.renderTarget?.dispose) childTexture.renderTarget.dispose();
|
|
261
|
+
});
|
|
262
|
+
const aspect = viewportSize.x.div(viewportSize.y);
|
|
263
|
+
const gridSizeUniform = uniforms.gridSize.uniform;
|
|
264
|
+
const isWide = aspect.greaterThan(float(1));
|
|
265
|
+
const cellsX = isWide.select(gridSizeUniform, gridSizeUniform.mul(aspect)).max(float(1));
|
|
266
|
+
const cellsY = isWide.select(gridSizeUniform.div(aspect), gridSizeUniform).max(float(1));
|
|
267
|
+
const cellIndexX = screenUV.x.mul(cellsX).floor();
|
|
268
|
+
const cellIndexY = screenUV.y.mul(cellsY).floor();
|
|
269
|
+
const gridCellUV = vec2(cellIndexX.add(.5).div(cellsX), cellIndexY.add(.5).div(cellsY));
|
|
270
|
+
const displacement = displacementField.sample(gridCellUV).xy;
|
|
271
|
+
const maxDisplacement = float(.1);
|
|
272
|
+
const clampedDisplacement = displacement.clamp(vec2(maxDisplacement.negate(), maxDisplacement.negate()), vec2(maxDisplacement, maxDisplacement));
|
|
273
|
+
const distortedUV = screenUV.sub(clampedDisplacement);
|
|
274
|
+
return unpremultiplyAlpha(applyEdgeHandling(distortedUV, childTexture.sample(distortedUV), childTexture, uniforms.edges.uniform.value));
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
var GridDistortion_default = componentDefinition;
|
|
278
|
+
export { componentDefinition as n, GridDistortion_default as t };
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { t as applyEdgeHandling } from "./edges-CfGcQniB.js";
|
|
2
|
+
import { c as transformEdges } from "./transformations-B5lM6fYX.js";
|
|
3
|
+
import { t as unpremultiplyAlpha } from "./alpha-C4ptedXe.js";
|
|
4
|
+
import { StorageTexture } from "three/webgpu";
|
|
5
|
+
import { DataTexture, FloatType, LinearFilter as LinearFilter$1, RGFormat } from "three";
|
|
6
|
+
import { Fn, If, attributeArray, convertToTexture, float, instanceIndex, screenUV, storageTexture, texture, textureStore, uint, uniform, uvec2, vec2, vec4 } from "three/tsl";
|
|
7
|
+
var GRID_SIZE = 64;
|
|
8
|
+
const componentDefinition = {
|
|
9
|
+
name: "Liquify",
|
|
10
|
+
category: "Interactive",
|
|
11
|
+
description: "Liquid-like interactive deformation effect",
|
|
12
|
+
requiresRTT: true,
|
|
13
|
+
requiresChild: true,
|
|
14
|
+
props: {
|
|
15
|
+
intensity: {
|
|
16
|
+
default: 10,
|
|
17
|
+
description: "Scale of the fabric displacement effect",
|
|
18
|
+
ui: {
|
|
19
|
+
type: ["range", "map"],
|
|
20
|
+
min: 0,
|
|
21
|
+
max: 20,
|
|
22
|
+
step: .1,
|
|
23
|
+
label: "Intensity",
|
|
24
|
+
group: "Effect"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
stiffness: {
|
|
28
|
+
default: 3,
|
|
29
|
+
description: "Fabric rigidity (higher = stiffer canvas, lower = stretchy silk)",
|
|
30
|
+
ui: {
|
|
31
|
+
type: "range",
|
|
32
|
+
min: 1,
|
|
33
|
+
max: 30,
|
|
34
|
+
step: .5,
|
|
35
|
+
label: "Stiffness",
|
|
36
|
+
group: "Effect"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
damping: {
|
|
40
|
+
default: 3,
|
|
41
|
+
description: "How quickly fabric motion settles",
|
|
42
|
+
ui: {
|
|
43
|
+
type: "range",
|
|
44
|
+
min: 0,
|
|
45
|
+
max: 10,
|
|
46
|
+
step: .1,
|
|
47
|
+
label: "Damping",
|
|
48
|
+
group: "Effect"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
radius: {
|
|
52
|
+
default: 1,
|
|
53
|
+
description: "Cursor influence area",
|
|
54
|
+
ui: {
|
|
55
|
+
type: "range",
|
|
56
|
+
min: .1,
|
|
57
|
+
max: 1.5,
|
|
58
|
+
step: .1,
|
|
59
|
+
label: "Radius",
|
|
60
|
+
group: "Effect"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
edges: {
|
|
64
|
+
default: "stretch",
|
|
65
|
+
description: "How to handle edges when distortion pushes content out of bounds",
|
|
66
|
+
transform: transformEdges,
|
|
67
|
+
compileTime: true,
|
|
68
|
+
ui: {
|
|
69
|
+
type: "select",
|
|
70
|
+
options: [
|
|
71
|
+
{
|
|
72
|
+
label: "Stretch",
|
|
73
|
+
value: "stretch"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
label: "Transparent",
|
|
77
|
+
value: "transparent"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
label: "Mirror",
|
|
81
|
+
value: "mirror"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
label: "Wrap",
|
|
85
|
+
value: "wrap"
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
label: "Edges",
|
|
89
|
+
group: "Effect"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
computeNode: ({ uniforms, onCleanup, dimensions }) => {
|
|
94
|
+
const bufferA = attributeArray(GRID_SIZE * GRID_SIZE, "vec4");
|
|
95
|
+
const bufferB = attributeArray(GRID_SIZE * GRID_SIZE, "vec4");
|
|
96
|
+
const dispTex = new StorageTexture(GRID_SIZE, GRID_SIZE);
|
|
97
|
+
dispTex.type = FloatType;
|
|
98
|
+
const dispTexNode = storageTexture(dispTex);
|
|
99
|
+
onCleanup(() => {
|
|
100
|
+
dispTex.dispose();
|
|
101
|
+
});
|
|
102
|
+
const cursorXU = uniform(.5);
|
|
103
|
+
const cursorYU = uniform(.5);
|
|
104
|
+
const dirXU = uniform(0);
|
|
105
|
+
const dirYU = uniform(0);
|
|
106
|
+
const clampedSpeedU = uniform(0);
|
|
107
|
+
const dtU = uniform(.016);
|
|
108
|
+
const subDtU = uniform(.008);
|
|
109
|
+
const stiffnessU = uniform(3);
|
|
110
|
+
const dampFactorU = uniform(.97);
|
|
111
|
+
const radiusU = uniform(.08);
|
|
112
|
+
const aspectU = uniform(1);
|
|
113
|
+
const gs = uint(GRID_SIZE);
|
|
114
|
+
const gsm1 = uint(GRID_SIZE - 1);
|
|
115
|
+
const buildSpringKernel = (readBuf, writeBuf) => Fn(() => {
|
|
116
|
+
const idx = instanceIndex;
|
|
117
|
+
const j = idx.mod(gs);
|
|
118
|
+
const i = idx.div(gs);
|
|
119
|
+
If(i.greaterThan(uint(0)).and(i.lessThan(gsm1)).and(j.greaterThan(uint(0))).and(j.lessThan(gsm1)), () => {
|
|
120
|
+
const current = readBuf.element(idx);
|
|
121
|
+
const dispX = current.x;
|
|
122
|
+
const dispY = current.y;
|
|
123
|
+
const velX = current.z;
|
|
124
|
+
const velY = current.w;
|
|
125
|
+
const idxL = idx.sub(uint(1));
|
|
126
|
+
const idxR = idx.add(uint(1));
|
|
127
|
+
const idxU = idx.sub(gs);
|
|
128
|
+
const idxD = idx.add(gs);
|
|
129
|
+
const idxUL = idx.sub(gs).sub(uint(1));
|
|
130
|
+
const idxUR = idx.sub(gs).add(uint(1));
|
|
131
|
+
const idxDL = idx.add(gs).sub(uint(1));
|
|
132
|
+
const idxDR = idx.add(gs).add(uint(1));
|
|
133
|
+
const fx = stiffnessU.mul(readBuf.element(idxL).x.sub(dispX).add(readBuf.element(idxR).x.sub(dispX)).add(readBuf.element(idxU).x.sub(dispX)).add(readBuf.element(idxD).x.sub(dispX))).toVar();
|
|
134
|
+
const fy = stiffnessU.mul(readBuf.element(idxL).y.sub(dispY).add(readBuf.element(idxR).y.sub(dispY)).add(readBuf.element(idxU).y.sub(dispY)).add(readBuf.element(idxD).y.sub(dispY))).toVar();
|
|
135
|
+
const shearK = stiffnessU.mul(float(.35));
|
|
136
|
+
fx.assign(fx.add(shearK.mul(readBuf.element(idxUL).x.sub(dispX).add(readBuf.element(idxUR).x.sub(dispX)).add(readBuf.element(idxDL).x.sub(dispX)).add(readBuf.element(idxDR).x.sub(dispX)))));
|
|
137
|
+
fy.assign(fy.add(shearK.mul(readBuf.element(idxUL).y.sub(dispY).add(readBuf.element(idxUR).y.sub(dispY)).add(readBuf.element(idxDL).y.sub(dispY)).add(readBuf.element(idxDR).y.sub(dispY)))));
|
|
138
|
+
fx.assign(fx.sub(stiffnessU.mul(float(.1)).mul(dispX)));
|
|
139
|
+
fy.assign(fy.sub(stiffnessU.mul(float(.1)).mul(dispY)));
|
|
140
|
+
const newVelX = velX.mul(dampFactorU).add(fx.mul(subDtU)).toVar();
|
|
141
|
+
const newVelY = velY.mul(dampFactorU).add(fy.mul(subDtU)).toVar();
|
|
142
|
+
If(clampedSpeedU.greaterThan(float(.01)), () => {
|
|
143
|
+
const cellX = j.toFloat().add(float(.5)).div(float(GRID_SIZE));
|
|
144
|
+
const cellY = i.toFloat().add(float(.5)).div(float(GRID_SIZE));
|
|
145
|
+
const ddx = aspectU.greaterThanEqual(float(1)).select(cellX.sub(cursorXU).mul(aspectU), cellX.sub(cursorXU));
|
|
146
|
+
const ddy = aspectU.greaterThanEqual(float(1)).select(cellY.sub(cursorYU), cellY.sub(cursorYU).div(aspectU));
|
|
147
|
+
const distSq = ddx.mul(ddx).add(ddy.mul(ddy));
|
|
148
|
+
const influenceRadius = radiusU.mul(float(3));
|
|
149
|
+
If(distSq.lessThan(influenceRadius.mul(influenceRadius)), () => {
|
|
150
|
+
const forceMag = distSq.negate().div(radiusU.mul(radiusU)).exp().mul(clampedSpeedU).mul(dtU).mul(float(2));
|
|
151
|
+
newVelX.assign(newVelX.add(dirXU.mul(forceMag)));
|
|
152
|
+
newVelY.assign(newVelY.add(dirYU.mul(forceMag)));
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
const newDispX = dispX.add(newVelX.mul(subDtU)).clamp(float(-.5), float(.5));
|
|
156
|
+
const newDispY = dispY.add(newVelY.mul(subDtU)).clamp(float(-.5), float(.5));
|
|
157
|
+
writeBuf.element(idx).assign(vec4(newDispX, newDispY, newVelX, newVelY));
|
|
158
|
+
});
|
|
159
|
+
})().compute(GRID_SIZE * GRID_SIZE, [256]);
|
|
160
|
+
const buildOutputKernel = (srcBuf) => Fn(() => {
|
|
161
|
+
const idx = instanceIndex;
|
|
162
|
+
const j = idx.mod(gs);
|
|
163
|
+
const i = idx.div(gs);
|
|
164
|
+
const cell = srcBuf.element(idx);
|
|
165
|
+
textureStore(dispTexNode, uvec2(j, i), vec4(cell.x, cell.y, float(0), float(1))).toWriteOnly();
|
|
166
|
+
})().compute(GRID_SIZE * GRID_SIZE, [256]);
|
|
167
|
+
const springAtoB = buildSpringKernel(bufferA, bufferB);
|
|
168
|
+
const springBtoA = buildSpringKernel(bufferB, bufferA);
|
|
169
|
+
const outputFromA = buildOutputKernel(bufferA);
|
|
170
|
+
let prevX = .5;
|
|
171
|
+
let prevY = .5;
|
|
172
|
+
let lastTime = Date.now();
|
|
173
|
+
let lastActiveTime = Date.now();
|
|
174
|
+
return {
|
|
175
|
+
outputs: { displacement: dispTex },
|
|
176
|
+
getComputeNodes: (params) => {
|
|
177
|
+
const currentTime = Date.now();
|
|
178
|
+
const dt = Math.min((currentTime - lastTime) / 1e3, .016);
|
|
179
|
+
lastTime = currentTime;
|
|
180
|
+
if (dt <= 0) return null;
|
|
181
|
+
const aspect = dimensions.width / Math.max(dimensions.height, 1);
|
|
182
|
+
const stiffness = uniforms.stiffness.uniform.value;
|
|
183
|
+
const damping = uniforms.damping.uniform.value;
|
|
184
|
+
const radius = uniforms.radius.uniform.value * .08;
|
|
185
|
+
const rawVelX = (params.pointer.x - prevX) / dt;
|
|
186
|
+
const rawVelY = (params.pointer.y - prevY) / dt;
|
|
187
|
+
const speed = Math.sqrt(rawVelX * rawVelX + rawVelY * rawVelY);
|
|
188
|
+
const clampedSpeed = Math.min(speed, 3);
|
|
189
|
+
prevX = params.pointer.x;
|
|
190
|
+
prevY = params.pointer.y;
|
|
191
|
+
if (clampedSpeed > .01) lastActiveTime = currentTime;
|
|
192
|
+
const dampVal = uniforms.damping.uniform.value;
|
|
193
|
+
const settleMs = dampVal > 0 ? Math.min(3e4, 5e3 / dampVal) : 3e4;
|
|
194
|
+
if (currentTime - lastActiveTime > settleMs) return null;
|
|
195
|
+
const subDt = dt / 2;
|
|
196
|
+
cursorXU.value = params.pointer.x;
|
|
197
|
+
cursorYU.value = params.pointer.y;
|
|
198
|
+
dirXU.value = speed > .01 ? rawVelX / speed : 0;
|
|
199
|
+
dirYU.value = speed > .01 ? rawVelY / speed : 0;
|
|
200
|
+
clampedSpeedU.value = clampedSpeed;
|
|
201
|
+
dtU.value = dt;
|
|
202
|
+
subDtU.value = subDt;
|
|
203
|
+
stiffnessU.value = stiffness;
|
|
204
|
+
dampFactorU.value = Math.max(0, Math.min(1, 1 - damping * subDt));
|
|
205
|
+
radiusU.value = radius;
|
|
206
|
+
aspectU.value = aspect;
|
|
207
|
+
return [
|
|
208
|
+
springAtoB,
|
|
209
|
+
springBtoA,
|
|
210
|
+
outputFromA
|
|
211
|
+
];
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
},
|
|
215
|
+
fragmentNode: ({ uniforms, onBeforeRender, childNode, onCleanup, dimensions, computeOutputs }) => {
|
|
216
|
+
if (!childNode) return vec4(0, 0, 0, 0);
|
|
217
|
+
const childTexture = computeOutputs?.childTexture ?? convertToTexture(childNode);
|
|
218
|
+
if (!computeOutputs) onCleanup(() => {
|
|
219
|
+
if (childTexture?.renderTarget?.dispose) childTexture.renderTarget.dispose();
|
|
220
|
+
});
|
|
221
|
+
let displacement;
|
|
222
|
+
if (computeOutputs?.displacement) {
|
|
223
|
+
childTexture.sample(screenUV);
|
|
224
|
+
displacement = texture(computeOutputs.displacement).sample(screenUV).xy;
|
|
225
|
+
} else {
|
|
226
|
+
const displacementX = new Float32Array(GRID_SIZE * GRID_SIZE);
|
|
227
|
+
const displacementY = new Float32Array(GRID_SIZE * GRID_SIZE);
|
|
228
|
+
const velocityX = new Float32Array(GRID_SIZE * GRID_SIZE);
|
|
229
|
+
const velocityY = new Float32Array(GRID_SIZE * GRID_SIZE);
|
|
230
|
+
const tempVelocityX = new Float32Array(GRID_SIZE * GRID_SIZE);
|
|
231
|
+
const tempVelocityY = new Float32Array(GRID_SIZE * GRID_SIZE);
|
|
232
|
+
const tempDisplacementX = new Float32Array(GRID_SIZE * GRID_SIZE);
|
|
233
|
+
const tempDisplacementY = new Float32Array(GRID_SIZE * GRID_SIZE);
|
|
234
|
+
const displacementData = new Float32Array(GRID_SIZE * GRID_SIZE * 2);
|
|
235
|
+
const displacementTexture = new DataTexture(displacementData, GRID_SIZE, GRID_SIZE, RGFormat, FloatType);
|
|
236
|
+
displacementTexture.magFilter = LinearFilter$1;
|
|
237
|
+
displacementTexture.minFilter = LinearFilter$1;
|
|
238
|
+
displacementTexture.needsUpdate = true;
|
|
239
|
+
const displacementField = texture(displacementTexture);
|
|
240
|
+
let prevX = .5;
|
|
241
|
+
let prevY = .5;
|
|
242
|
+
let lastTime = Date.now();
|
|
243
|
+
const SUBSTEPS = 2;
|
|
244
|
+
onBeforeRender(({ pointer }) => {
|
|
245
|
+
const currentTime = Date.now();
|
|
246
|
+
const dt = Math.min((currentTime - lastTime) / 1e3, .016);
|
|
247
|
+
lastTime = currentTime;
|
|
248
|
+
if (dt <= 0) return;
|
|
249
|
+
const aspect = dimensions.width / Math.max(dimensions.height, 1);
|
|
250
|
+
const stiffness = uniforms.stiffness.uniform.value;
|
|
251
|
+
const damping = uniforms.damping.uniform.value;
|
|
252
|
+
const radius = uniforms.radius.uniform.value * .08;
|
|
253
|
+
const rawVelX = (pointer.x - prevX) / dt;
|
|
254
|
+
const rawVelY = (pointer.y - prevY) / dt;
|
|
255
|
+
const speed = Math.sqrt(rawVelX * rawVelX + rawVelY * rawVelY);
|
|
256
|
+
const clampedSpeed = Math.min(speed, 3);
|
|
257
|
+
let dirX = 0, dirY = 0;
|
|
258
|
+
if (speed > .01) {
|
|
259
|
+
dirX = rawVelX / speed;
|
|
260
|
+
dirY = rawVelY / speed;
|
|
261
|
+
}
|
|
262
|
+
const subDt = dt / SUBSTEPS;
|
|
263
|
+
for (let s = 0; s < SUBSTEPS; s++) {
|
|
264
|
+
if (s === 0 && clampedSpeed > .01) {
|
|
265
|
+
const influenceRadius = radius * 3;
|
|
266
|
+
const minI = Math.max(1, Math.floor((pointer.y - influenceRadius) * GRID_SIZE));
|
|
267
|
+
const maxI = Math.min(GRID_SIZE - 2, Math.ceil((pointer.y + influenceRadius) * GRID_SIZE));
|
|
268
|
+
const minJ = Math.max(1, Math.floor((pointer.x - influenceRadius) * GRID_SIZE));
|
|
269
|
+
const maxJ = Math.min(GRID_SIZE - 2, Math.ceil((pointer.x + influenceRadius) * GRID_SIZE));
|
|
270
|
+
for (let i = minI; i <= maxI; i++) for (let j = minJ; j <= maxJ; j++) {
|
|
271
|
+
const idx = i * GRID_SIZE + j;
|
|
272
|
+
const cellX = (j + .5) / GRID_SIZE;
|
|
273
|
+
const cellY = (i + .5) / GRID_SIZE;
|
|
274
|
+
const ddx = aspect >= 1 ? (cellX - pointer.x) * aspect : cellX - pointer.x;
|
|
275
|
+
const ddy = aspect >= 1 ? cellY - pointer.y : (cellY - pointer.y) / aspect;
|
|
276
|
+
const dist = Math.sqrt(ddx * ddx + ddy * ddy);
|
|
277
|
+
if (dist < influenceRadius) {
|
|
278
|
+
const forceMag = Math.exp(-dist * dist / (radius * radius)) * clampedSpeed * dt * 2;
|
|
279
|
+
velocityX[idx] += dirX * forceMag;
|
|
280
|
+
velocityY[idx] += dirY * forceMag;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const dampFactor = Math.max(0, Math.min(1, 1 - damping * subDt));
|
|
285
|
+
const shearK = stiffness * .35;
|
|
286
|
+
tempVelocityX.set(velocityX);
|
|
287
|
+
tempVelocityY.set(velocityY);
|
|
288
|
+
tempDisplacementX.set(displacementX);
|
|
289
|
+
tempDisplacementY.set(displacementY);
|
|
290
|
+
for (let i = 1; i < GRID_SIZE - 1; i++) for (let j = 1; j < GRID_SIZE - 1; j++) {
|
|
291
|
+
const idx = i * GRID_SIZE + j;
|
|
292
|
+
let fx = 0, fy = 0;
|
|
293
|
+
const idxL = idx - 1, idxR = idx + 1;
|
|
294
|
+
const idxU = idx - GRID_SIZE, idxD = idx + GRID_SIZE;
|
|
295
|
+
fx += stiffness * (displacementX[idxL] - displacementX[idx]);
|
|
296
|
+
fx += stiffness * (displacementX[idxR] - displacementX[idx]);
|
|
297
|
+
fx += stiffness * (displacementX[idxU] - displacementX[idx]);
|
|
298
|
+
fx += stiffness * (displacementX[idxD] - displacementX[idx]);
|
|
299
|
+
fy += stiffness * (displacementY[idxL] - displacementY[idx]);
|
|
300
|
+
fy += stiffness * (displacementY[idxR] - displacementY[idx]);
|
|
301
|
+
fy += stiffness * (displacementY[idxU] - displacementY[idx]);
|
|
302
|
+
fy += stiffness * (displacementY[idxD] - displacementY[idx]);
|
|
303
|
+
const idxUL = idx - GRID_SIZE - 1, idxUR = idx - GRID_SIZE + 1;
|
|
304
|
+
const idxDL = idx + GRID_SIZE - 1, idxDR = idx + GRID_SIZE + 1;
|
|
305
|
+
fx += shearK * (displacementX[idxUL] - displacementX[idx]);
|
|
306
|
+
fx += shearK * (displacementX[idxUR] - displacementX[idx]);
|
|
307
|
+
fx += shearK * (displacementX[idxDL] - displacementX[idx]);
|
|
308
|
+
fx += shearK * (displacementX[idxDR] - displacementX[idx]);
|
|
309
|
+
fy += shearK * (displacementY[idxUL] - displacementY[idx]);
|
|
310
|
+
fy += shearK * (displacementY[idxUR] - displacementY[idx]);
|
|
311
|
+
fy += shearK * (displacementY[idxDL] - displacementY[idx]);
|
|
312
|
+
fy += shearK * (displacementY[idxDR] - displacementY[idx]);
|
|
313
|
+
fx -= stiffness * .1 * displacementX[idx];
|
|
314
|
+
fy -= stiffness * .1 * displacementY[idx];
|
|
315
|
+
tempVelocityX[idx] = velocityX[idx] * dampFactor + fx * subDt;
|
|
316
|
+
tempVelocityY[idx] = velocityY[idx] * dampFactor + fy * subDt;
|
|
317
|
+
tempDisplacementX[idx] = displacementX[idx] + tempVelocityX[idx] * subDt;
|
|
318
|
+
tempDisplacementY[idx] = displacementY[idx] + tempVelocityY[idx] * subDt;
|
|
319
|
+
tempDisplacementX[idx] = Math.max(-.5, Math.min(.5, tempDisplacementX[idx]));
|
|
320
|
+
tempDisplacementY[idx] = Math.max(-.5, Math.min(.5, tempDisplacementY[idx]));
|
|
321
|
+
}
|
|
322
|
+
velocityX.set(tempVelocityX);
|
|
323
|
+
velocityY.set(tempVelocityY);
|
|
324
|
+
displacementX.set(tempDisplacementX);
|
|
325
|
+
displacementY.set(tempDisplacementY);
|
|
326
|
+
}
|
|
327
|
+
for (let i = 0; i < GRID_SIZE; i++) for (let j = 0; j < GRID_SIZE; j++) {
|
|
328
|
+
const idx = i * GRID_SIZE + j;
|
|
329
|
+
const dIdx = idx * 2;
|
|
330
|
+
displacementData[dIdx] = displacementX[idx];
|
|
331
|
+
displacementData[dIdx + 1] = displacementY[idx];
|
|
332
|
+
}
|
|
333
|
+
displacementTexture.needsUpdate = true;
|
|
334
|
+
prevX = pointer.x;
|
|
335
|
+
prevY = pointer.y;
|
|
336
|
+
});
|
|
337
|
+
onCleanup(() => {
|
|
338
|
+
displacementTexture.dispose();
|
|
339
|
+
});
|
|
340
|
+
displacement = displacementField.sample(screenUV).xy;
|
|
341
|
+
}
|
|
342
|
+
const intensityScale = uniforms.intensity.uniform.mul(.1);
|
|
343
|
+
const scaledDisplacement = displacement.mul(intensityScale);
|
|
344
|
+
const maxDisp = float(.15);
|
|
345
|
+
const clampedDisplacement = scaledDisplacement.clamp(vec2(maxDisp.negate(), maxDisp.negate()), vec2(maxDisp, maxDisp));
|
|
346
|
+
const distortedUV = screenUV.sub(clampedDisplacement);
|
|
347
|
+
return unpremultiplyAlpha(applyEdgeHandling(distortedUV, childTexture.sample(distortedUV), childTexture, uniforms.edges.uniform.value));
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
var Liquify_default = componentDefinition;
|
|
351
|
+
export { componentDefinition as n, Liquify_default as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as transformColor, l as transformPosition } from "./transformations-B5lM6fYX.js";
|
|
2
|
-
import { n as createAnalyticSdfSampler, r as createSvgSdfSampler } from "./sdf-
|
|
2
|
+
import { n as createAnalyticSdfSampler, r as createSvgSdfSampler } from "./sdf-DyC2H_qS.js";
|
|
3
3
|
import { Fn, atan, clamp, cos, exp, exp2, float, max, mix, pow, screenUV, sin, smoothstep, sqrt, uniform, vec2, vec3, vec4, viewportSize } from "three/tsl";
|
|
4
4
|
var _LZ = .7;
|
|
5
5
|
var _INV_LIGHT_LEN = 1 / Math.sqrt(1 + _LZ * _LZ);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as transformColor, l as transformPosition, o as transformColorSpace, t as colorSpaceOptions } from "./transformations-B5lM6fYX.js";
|
|
2
2
|
import { t as mixColors } from "./colorMixing-BPpDnR5I.js";
|
|
3
|
-
import { c as polygonSdf, t as circleSdf } from "./sdf-
|
|
3
|
+
import { c as polygonSdf, t as circleSdf } from "./sdf-DyC2H_qS.js";
|
|
4
4
|
import { cos, float, mix, screenUV, sin, smoothstep, vec2, vec4, viewportSize } from "three/tsl";
|
|
5
5
|
var transformStrokePosition = (value) => {
|
|
6
6
|
return {
|