shaders 2.2.41 → 2.2.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/core/Shatter-COjV2jLy.js +299 -0
  2. package/dist/core/WebcamTexture-D4Uv7Plz.js +168 -0
  3. package/dist/core/index.js +43 -39
  4. package/dist/core/shaderRegistry.d.ts.map +1 -1
  5. package/dist/core/shaders/Shatter/index.d.ts +70 -0
  6. package/dist/core/shaders/Shatter/index.d.ts.map +1 -0
  7. package/dist/core/shaders/Shatter/index.js +4 -0
  8. package/dist/core/shaders/SimplexNoise/index.js +1 -1
  9. package/dist/core/shaders/SineWave/index.js +1 -1
  10. package/dist/core/shaders/SolidColor/index.js +1 -1
  11. package/dist/core/shaders/Spherize/index.js +1 -1
  12. package/dist/core/shaders/Spiral/index.js +1 -1
  13. package/dist/core/shaders/Strands/index.js +1 -1
  14. package/dist/core/shaders/Stretch/index.js +1 -1
  15. package/dist/core/shaders/Stripes/index.js +1 -1
  16. package/dist/core/shaders/Swirl/index.js +1 -1
  17. package/dist/core/shaders/TiltShift/index.js +1 -1
  18. package/dist/core/shaders/Tint/index.js +1 -1
  19. package/dist/core/shaders/Tritone/index.js +1 -1
  20. package/dist/core/shaders/Twirl/index.js +1 -1
  21. package/dist/core/shaders/Vibrance/index.js +1 -1
  22. package/dist/core/shaders/WaveDistortion/index.js +1 -1
  23. package/dist/core/shaders/WebcamTexture/index.d.ts +21 -0
  24. package/dist/core/shaders/WebcamTexture/index.d.ts.map +1 -0
  25. package/dist/core/shaders/WebcamTexture/index.js +2 -0
  26. package/dist/core/shaders/ZoomBlur/index.js +1 -1
  27. package/dist/react/components/Shatter.d.ts +31 -0
  28. package/dist/react/components/Shatter.d.ts.map +1 -0
  29. package/dist/react/components/WebcamTexture.d.ts +31 -0
  30. package/dist/react/components/WebcamTexture.d.ts.map +1 -0
  31. package/dist/react/{generatePresetCode-K6ZAneRr.js → generatePresetCode-D0yiVxb4.js} +21 -0
  32. package/dist/react/index.d.ts +2 -0
  33. package/dist/react/index.d.ts.map +1 -1
  34. package/dist/react/index.js +717 -439
  35. package/dist/react/utils/generatePresetCode.d.ts.map +1 -1
  36. package/dist/react/utils/generatePresetCode.js +1 -1
  37. package/dist/registry.js +337 -0
  38. package/dist/solid/components/Shatter.d.ts +28 -0
  39. package/dist/solid/components/Shatter.d.ts.map +1 -0
  40. package/dist/solid/components/WebcamTexture.d.ts +28 -0
  41. package/dist/solid/components/WebcamTexture.d.ts.map +1 -0
  42. package/dist/solid/index.d.ts +2 -0
  43. package/dist/solid/index.d.ts.map +1 -1
  44. package/dist/solid/index.js +659 -375
  45. package/dist/solid/utils/generatePresetCode.d.ts.map +1 -1
  46. package/dist/solid/utils/generatePresetCode.js +21 -0
  47. package/dist/svelte/components/Shatter.svelte.d.ts +19 -0
  48. package/dist/svelte/components/WebcamTexture.svelte.d.ts +19 -0
  49. package/dist/svelte/{generatePresetCode-x1dhDaQ3.js → generatePresetCode-DUGaV_ym.js} +21 -0
  50. package/dist/svelte/index.d.ts +2 -0
  51. package/dist/svelte/index.js +256 -34
  52. package/dist/svelte/utils/generatePresetCode.js +1 -1
  53. package/dist/vue/components/Shatter.vue.d.ts +57 -0
  54. package/dist/vue/components/Shatter.vue.d.ts.map +1 -0
  55. package/dist/vue/components/WebcamTexture.vue.d.ts +57 -0
  56. package/dist/vue/components/WebcamTexture.vue.d.ts.map +1 -0
  57. package/dist/vue/{generatePresetCode-BaNcX5ua.js → generatePresetCode-CShQ8TLw.js} +21 -0
  58. package/dist/vue/index.d.ts +2 -0
  59. package/dist/vue/index.d.ts.map +1 -1
  60. package/dist/vue/index.js +381 -130
  61. package/dist/vue/utils/generatePresetCode.d.ts.map +1 -1
  62. package/dist/vue/utils/generatePresetCode.js +1 -1
  63. package/package.json +17 -1
  64. /package/dist/core/{SimplexNoise-CMMeggo6.js → SimplexNoise-Ce79jgYM.js} +0 -0
  65. /package/dist/core/{SineWave-DVVLqHPw.js → SineWave-Cv2gOU8a.js} +0 -0
  66. /package/dist/core/{SolidColor-zYROg_aE.js → SolidColor-DFkDBFq3.js} +0 -0
  67. /package/dist/core/{Spherize-tsKMpSaS.js → Spherize-R-s4pX9t.js} +0 -0
  68. /package/dist/core/{Spiral-DDyVSeG_.js → Spiral-W4dALX1z.js} +0 -0
  69. /package/dist/core/{Strands-B9vY4uA7.js → Strands-DtN5POfO.js} +0 -0
  70. /package/dist/core/{Stretch-BhHjbcqd.js → Stretch-BzvP_hdu.js} +0 -0
  71. /package/dist/core/{Stripes-TdCUOh07.js → Stripes-BbNFX05u.js} +0 -0
  72. /package/dist/core/{Swirl-m1-Mnzj5.js → Swirl-CfsYsr4X.js} +0 -0
  73. /package/dist/core/{TiltShift-C_NUqKZF.js → TiltShift-B6gbm7Z8.js} +0 -0
  74. /package/dist/core/{Tint-ChKku9xR.js → Tint-CpnitsHw.js} +0 -0
  75. /package/dist/core/{Tritone-D-NcV7N-.js → Tritone-DzvSKVfR.js} +0 -0
  76. /package/dist/core/{Twirl-Cqzll6nW.js → Twirl-BXH4uAd6.js} +0 -0
  77. /package/dist/core/{Vibrance-CxunJkcb.js → Vibrance-ByN9bRgU.js} +0 -0
  78. /package/dist/core/{WaveDistortion-UQZKCfKh.js → WaveDistortion-BA1PyqYH.js} +0 -0
  79. /package/dist/core/{ZoomBlur-DqKYdlmm.js → ZoomBlur-CIkkDBIo.js} +0 -0
@@ -0,0 +1,299 @@
1
+ import { t as applyEdgeHandling } from "./edges-Bd7GP4s2.js";
2
+ import { o as transformEdges } from "./transformations-YbhRK-rd.js";
3
+ import { DataTexture, FloatType, LinearFilter, RGBAFormat } from "three";
4
+ import { convertToTexture, float, screenUV, smoothstep, texture, vec2, vec4 } from "three/tsl";
5
+ var seededRandom = (seed) => {
6
+ const x = Math.sin(seed) * 1e4;
7
+ return x - Math.floor(x);
8
+ };
9
+ const componentDefinition = {
10
+ name: "Shatter",
11
+ category: "Interactive",
12
+ description: "Broken glass effect with tectonic plate displacement",
13
+ requiresRTT: true,
14
+ requiresChild: true,
15
+ props: {
16
+ crackWidth: {
17
+ default: 1,
18
+ description: "Thickness of crack lines",
19
+ ui: {
20
+ type: "range",
21
+ min: .5,
22
+ max: 5,
23
+ step: .1,
24
+ label: "Crack Width"
25
+ }
26
+ },
27
+ intensity: {
28
+ default: 4,
29
+ description: "How much shards shift",
30
+ ui: {
31
+ type: "range",
32
+ min: 0,
33
+ max: 20,
34
+ step: 1,
35
+ label: "Intensity"
36
+ }
37
+ },
38
+ radius: {
39
+ default: .4,
40
+ description: "Cursor influence radius",
41
+ ui: {
42
+ type: "range",
43
+ min: .1,
44
+ max: 1,
45
+ step: .1,
46
+ label: "Radius"
47
+ }
48
+ },
49
+ decay: {
50
+ default: 1,
51
+ description: "How fast shards return to rest",
52
+ ui: {
53
+ type: "range",
54
+ min: .1,
55
+ max: 10,
56
+ step: .1,
57
+ label: "Decay"
58
+ }
59
+ },
60
+ seed: {
61
+ default: 2,
62
+ description: "Random seed for pattern",
63
+ ui: {
64
+ type: "range",
65
+ min: 0,
66
+ max: 50,
67
+ step: 1,
68
+ label: "Seed"
69
+ }
70
+ },
71
+ chromaticSplit: {
72
+ default: 1,
73
+ description: "RGB separation for prismatic glass effect",
74
+ ui: {
75
+ type: "range",
76
+ min: 0,
77
+ max: 5,
78
+ step: .1,
79
+ label: "Chromatic Split"
80
+ }
81
+ },
82
+ refractionStrength: {
83
+ default: 5,
84
+ description: "How much cracks bend/distort the underlying image",
85
+ ui: {
86
+ type: "range",
87
+ min: 0,
88
+ max: 10,
89
+ step: .1,
90
+ label: "Refraction"
91
+ }
92
+ },
93
+ shardLighting: {
94
+ default: .1,
95
+ description: "Subtle lighting on tilted shards for 3D depth",
96
+ ui: {
97
+ type: "range",
98
+ min: 0,
99
+ max: .5,
100
+ step: .1,
101
+ label: "Shard Lighting"
102
+ }
103
+ },
104
+ edges: {
105
+ default: "mirror",
106
+ description: "How to handle edges when displacement pushes content out of bounds",
107
+ transform: transformEdges,
108
+ ui: {
109
+ type: "select",
110
+ options: [
111
+ {
112
+ label: "Stretch",
113
+ value: "stretch"
114
+ },
115
+ {
116
+ label: "Transparent",
117
+ value: "transparent"
118
+ },
119
+ {
120
+ label: "Mirror",
121
+ value: "mirror"
122
+ },
123
+ {
124
+ label: "Wrap",
125
+ value: "wrap"
126
+ }
127
+ ],
128
+ label: "Edges"
129
+ }
130
+ }
131
+ },
132
+ fragmentNode: ({ uniforms, onBeforeRender, childNode, onCleanup }) => {
133
+ const SHARD_COUNT = 16;
134
+ const FRICTION = 1;
135
+ const cellData = new Float32Array(SHARD_COUNT * 4);
136
+ const cellTexture = new DataTexture(cellData, 4, 4, RGBAFormat, FloatType);
137
+ cellTexture.magFilter = LinearFilter;
138
+ cellTexture.minFilter = LinearFilter;
139
+ const displacementData = new Float32Array(SHARD_COUNT * 4);
140
+ const displacementTexture = new DataTexture(displacementData, 4, 4, RGBAFormat, FloatType);
141
+ displacementTexture.magFilter = LinearFilter;
142
+ displacementTexture.minFilter = LinearFilter;
143
+ const generateCells = (seed) => {
144
+ for (let i = 0; i < SHARD_COUNT; i++) {
145
+ cellData[i * 4] = seededRandom(seed + i * 2);
146
+ cellData[i * 4 + 1] = seededRandom(seed + i * 2 + 1);
147
+ cellData[i * 4 + 2] = seededRandom(seed + i * 3);
148
+ cellData[i * 4 + 3] = seededRandom(seed + i * 3 + 1);
149
+ }
150
+ cellTexture.needsUpdate = true;
151
+ };
152
+ let currentSeed = uniforms.seed.uniform.value;
153
+ generateCells(currentSeed);
154
+ displacementData.fill(0);
155
+ displacementTexture.needsUpdate = true;
156
+ let prevX = .5;
157
+ let prevY = .5;
158
+ let lastTime = Date.now();
159
+ onBeforeRender(({ pointer }) => {
160
+ const currentTime = Date.now();
161
+ const dt = Math.min((currentTime - lastTime) / 1e3, .016);
162
+ lastTime = currentTime;
163
+ const newSeed = uniforms.seed.uniform.value;
164
+ if (newSeed !== currentSeed) {
165
+ currentSeed = newSeed;
166
+ generateCells(currentSeed);
167
+ displacementData.fill(0);
168
+ }
169
+ const intensity = uniforms.intensity.uniform.value;
170
+ const radius = uniforms.radius.uniform.value;
171
+ const decay = uniforms.decay.uniform.value;
172
+ const friction = FRICTION;
173
+ let velX = dt > 0 ? (pointer.x - prevX) / dt : 0;
174
+ let velY = dt > 0 ? (pointer.y - prevY) / dt : 0;
175
+ let speed = Math.sqrt(velX * velX + velY * velY);
176
+ const maxVelocity = 5 + intensity * 2;
177
+ if (speed > maxVelocity) {
178
+ const scale = maxVelocity / speed;
179
+ velX *= scale;
180
+ velY *= scale;
181
+ speed = maxVelocity;
182
+ }
183
+ for (let i = 0; i < SHARD_COUNT; i++) {
184
+ const cellX = cellData[i * 4];
185
+ const cellY = cellData[i * 4 + 1];
186
+ const randomDirX = cellData[i * 4 + 2] - .5;
187
+ const randomDirY = cellData[i * 4 + 3] - .5;
188
+ const dx = cellX - pointer.x;
189
+ const dy = cellY - pointer.y;
190
+ const dist = Math.sqrt(dx * dx + dy * dy);
191
+ let currentDx = displacementData[i * 4];
192
+ let currentDy = displacementData[i * 4 + 1];
193
+ const decayTime = Math.max(.01, decay);
194
+ const decayFactor = Math.exp(-dt / decayTime);
195
+ currentDx *= decayFactor;
196
+ currentDy *= decayFactor;
197
+ let velocityDx = 0;
198
+ let velocityDy = 0;
199
+ if (dist < radius && speed > .01) {
200
+ const influence = Math.max(0, 1 - dist / radius);
201
+ const influenceCurve = influence * influence;
202
+ const pushForce = influenceCurve * speed * intensity * dt * .5;
203
+ velocityDx = velX * pushForce;
204
+ velocityDy = velY * pushForce;
205
+ const jitterForce = influenceCurve * speed * intensity * dt * .1;
206
+ velocityDx += randomDirX * jitterForce;
207
+ velocityDy += randomDirY * jitterForce;
208
+ }
209
+ const lerpFactor = Math.min(1, friction * dt);
210
+ displacementData[i * 4] = currentDx + velocityDx * lerpFactor;
211
+ displacementData[i * 4 + 1] = currentDy + velocityDy * lerpFactor;
212
+ displacementData[i * 4 + 2] = 0;
213
+ displacementData[i * 4 + 3] = 0;
214
+ }
215
+ displacementTexture.needsUpdate = true;
216
+ prevX = pointer.x;
217
+ prevY = pointer.y;
218
+ });
219
+ onCleanup(() => {
220
+ cellTexture.dispose();
221
+ displacementTexture.dispose();
222
+ });
223
+ if (!childNode) return vec4(0, 0, 0, 0);
224
+ const childTexture = convertToTexture(childNode);
225
+ onCleanup(() => {
226
+ if (childTexture?.renderTarget?.dispose) childTexture.renderTarget.dispose();
227
+ });
228
+ const cellField = texture(cellTexture);
229
+ const dispField = texture(displacementTexture);
230
+ const cells = [];
231
+ for (let i = 0; i < SHARD_COUNT; i++) {
232
+ const u = (i % 4 + .5) / 4;
233
+ const v = (Math.floor(i / 4) + .5) / 4;
234
+ const cellPos = cellField.sample(vec2(u, v)).xy;
235
+ const dist = screenUV.sub(cellPos).length();
236
+ cells.push({
237
+ dist,
238
+ index: float(i)
239
+ });
240
+ }
241
+ let minDist1 = cells[0].dist;
242
+ let minDist2 = float(1e3);
243
+ let nearestIdx = cells[0].index;
244
+ for (let i = 1; i < SHARD_COUNT; i++) {
245
+ const dist = cells[i].dist;
246
+ const isNewNearest = dist.lessThan(minDist1);
247
+ const isNewSecond = dist.lessThan(minDist2).and(isNewNearest.not());
248
+ const nextMin2 = isNewNearest.select(minDist1, isNewSecond.select(dist, minDist2));
249
+ const nextMin1 = isNewNearest.select(dist, minDist1);
250
+ const nextIdx = isNewNearest.select(cells[i].index, nearestIdx);
251
+ minDist2 = nextMin2;
252
+ minDist1 = nextMin1;
253
+ nearestIdx = nextIdx;
254
+ }
255
+ const dispU = nearestIdx.mod(float(4)).add(.5).div(4);
256
+ const dispV = nearestIdx.div(float(4)).floor().add(.5).div(4);
257
+ const displacement = dispField.sample(vec2(dispU, dispV)).xy;
258
+ const displacementMag = displacement.length();
259
+ const edgeDiff = minDist2.sub(minDist1);
260
+ const crackThreshold = uniforms.crackWidth.uniform.mul(.005);
261
+ const baseCrackIntensity = float(1).sub(smoothstep(float(0), crackThreshold, edgeDiff));
262
+ const displacementFactor = smoothstep(float(0), float(.01), displacementMag);
263
+ const crackIntensity = baseCrackIntensity.mul(displacementFactor);
264
+ const nearestCellU = nearestIdx.mod(float(4)).add(.5).div(4);
265
+ const nearestCellV = nearestIdx.div(float(4)).floor().add(.5).div(4);
266
+ const nearestCellPos = cellField.sample(vec2(nearestCellU, nearestCellV)).xy;
267
+ const toNearest = screenUV.sub(nearestCellPos).normalize();
268
+ const edgeNormal = vec2(toNearest.y.negate(), toNearest.x);
269
+ const displacedUV = screenUV.sub(displacement);
270
+ const refractionOffset = edgeNormal.mul(uniforms.refractionStrength.uniform).mul(.01);
271
+ const chromaticOffset = uniforms.chromaticSplit.uniform.mul(.005);
272
+ const rOffset = refractionOffset.add(edgeNormal.mul(chromaticOffset));
273
+ const gOffset = refractionOffset;
274
+ const bOffset = refractionOffset.sub(edgeNormal.mul(chromaticOffset));
275
+ const rUV = displacedUV.add(rOffset.mul(crackIntensity));
276
+ const gUV = displacedUV.add(gOffset.mul(crackIntensity));
277
+ const bUV = displacedUV.add(bOffset.mul(crackIntensity));
278
+ const rSample = childTexture.sample(rUV);
279
+ const gSample = childTexture.sample(gUV);
280
+ const bSample = childTexture.sample(bUV);
281
+ const rFinal = applyEdgeHandling(rUV, rSample, childTexture, uniforms.edges.uniform);
282
+ const gFinal = applyEdgeHandling(gUV, gSample, childTexture, uniforms.edges.uniform);
283
+ const bFinal = applyEdgeHandling(bUV, bSample, childTexture, uniforms.edges.uniform);
284
+ const refractedColor = vec4(rFinal.r, gFinal.g, bFinal.b, gFinal.a);
285
+ const normalColor = applyEdgeHandling(displacedUV, childTexture.sample(displacedUV), childTexture, uniforms.edges.uniform);
286
+ let shadedRGB = normalColor.rgb.mul(float(1).sub(crackIntensity)).add(refractedColor.rgb.mul(crackIntensity));
287
+ const displacementLength = displacement.length();
288
+ const tiltX = displacement.x.div(displacementLength.add(.001));
289
+ const tiltY = displacement.y.div(displacementLength.add(.001));
290
+ const lightDir3D = vec2(.3, .6).normalize();
291
+ const normalDot = tiltX.mul(lightDir3D.x).add(tiltY.mul(lightDir3D.y));
292
+ const lightingFactor = float(1).add(normalDot.mul(uniforms.shardLighting.uniform));
293
+ const lightingIntensity = smoothstep(float(0), float(.02), displacementLength);
294
+ const finalLighting = float(1).add(lightingFactor.sub(1).mul(lightingIntensity));
295
+ return vec4(shadedRGB.mul(finalLighting), normalColor.a);
296
+ }
297
+ };
298
+ var Shatter_default = componentDefinition;
299
+ export { componentDefinition as n, Shatter_default as t };
@@ -0,0 +1,168 @@
1
+ import { SRGBColorSpace, VideoTexture } from "three/webgpu";
2
+ import { float, max, min, or, screenUV, select, step, texture, uniform, vec2, vec4, viewportSize } from "three/tsl";
3
+ const componentDefinition = {
4
+ name: "WebcamTexture",
5
+ category: "Base Layers",
6
+ description: "Display a live webcam feed with customizable object-fit modes",
7
+ props: {
8
+ objectFit: {
9
+ default: "cover",
10
+ description: "How the webcam feed should be sized within the viewport",
11
+ transform: (value) => {
12
+ return {
13
+ "cover": 0,
14
+ "contain": 1,
15
+ "fill": 2,
16
+ "scale-down": 3,
17
+ "none": 4
18
+ }[value] ?? 0;
19
+ },
20
+ ui: {
21
+ type: "select",
22
+ options: [
23
+ {
24
+ label: "Cover",
25
+ value: "cover"
26
+ },
27
+ {
28
+ label: "Contain",
29
+ value: "contain"
30
+ },
31
+ {
32
+ label: "Fill",
33
+ value: "fill"
34
+ },
35
+ {
36
+ label: "Scale Down",
37
+ value: "scale-down"
38
+ },
39
+ {
40
+ label: "None",
41
+ value: "none"
42
+ }
43
+ ],
44
+ label: "Object Fit"
45
+ }
46
+ },
47
+ mirror: {
48
+ default: true,
49
+ description: "Mirror the webcam feed horizontally (selfie mode)",
50
+ ui: {
51
+ type: "checkbox",
52
+ label: "Mirror"
53
+ }
54
+ }
55
+ },
56
+ fragmentNode: ({ uniforms, onCleanup }) => {
57
+ const baseUV = screenUV;
58
+ let mediaStream = null;
59
+ let videoElement = null;
60
+ let videoTexture = null;
61
+ let isInitialized = false;
62
+ let isDisposed = false;
63
+ const videoAspectUniform = uniform(1);
64
+ const videoWidthUniform = uniform(640);
65
+ const videoHeightUniform = uniform(480);
66
+ const placeholderVideo = document.createElement("video");
67
+ placeholderVideo.playsInline = true;
68
+ placeholderVideo.muted = true;
69
+ videoTexture = new VideoTexture(placeholderVideo);
70
+ videoTexture.colorSpace = SRGBColorSpace;
71
+ const textureNode = texture(videoTexture);
72
+ const startWebcam = async () => {
73
+ if (isInitialized || isDisposed) return;
74
+ try {
75
+ mediaStream = await navigator.mediaDevices.getUserMedia({
76
+ video: {
77
+ width: { ideal: 1280 },
78
+ height: { ideal: 720 },
79
+ facingMode: "user"
80
+ },
81
+ audio: false
82
+ });
83
+ if (isDisposed) {
84
+ mediaStream.getTracks().forEach((track) => track.stop());
85
+ mediaStream = null;
86
+ return;
87
+ }
88
+ videoElement = document.createElement("video");
89
+ videoElement.srcObject = mediaStream;
90
+ videoElement.playsInline = true;
91
+ videoElement.muted = true;
92
+ await new Promise((resolve, reject) => {
93
+ if (!videoElement) return reject(/* @__PURE__ */ new Error("Video element not created"));
94
+ videoElement.onloadedmetadata = () => {
95
+ resolve();
96
+ };
97
+ videoElement.onerror = () => {
98
+ reject(/* @__PURE__ */ new Error("Failed to load video metadata"));
99
+ };
100
+ });
101
+ if (isDisposed) return;
102
+ await videoElement.play();
103
+ if (isDisposed) return;
104
+ const width = videoElement.videoWidth || 640;
105
+ const height = videoElement.videoHeight || 480;
106
+ videoAspectUniform.value = width / height;
107
+ videoWidthUniform.value = width;
108
+ videoHeightUniform.value = height;
109
+ if (videoTexture) videoTexture.dispose();
110
+ videoTexture = new VideoTexture(videoElement);
111
+ videoTexture.colorSpace = SRGBColorSpace;
112
+ textureNode.value = videoTexture;
113
+ isInitialized = true;
114
+ console.log(`[WebcamTexture] Webcam started: ${width}x${height}`);
115
+ } catch (error) {
116
+ if (error instanceof DOMException) if (error.name === "NotAllowedError") console.error("[WebcamTexture] Camera permission denied by user");
117
+ else if (error.name === "NotFoundError") console.error("[WebcamTexture] No camera found on this device");
118
+ else if (error.name === "NotReadableError") console.error("[WebcamTexture] Camera is already in use by another application");
119
+ else console.error("[WebcamTexture] Camera error:", error.message);
120
+ else console.error("[WebcamTexture] Failed to start webcam:", error);
121
+ }
122
+ };
123
+ startWebcam();
124
+ onCleanup(() => {
125
+ isDisposed = true;
126
+ if (mediaStream) {
127
+ mediaStream.getTracks().forEach((track) => track.stop());
128
+ mediaStream = null;
129
+ }
130
+ if (videoTexture) {
131
+ videoTexture.dispose();
132
+ videoTexture = null;
133
+ }
134
+ if (videoElement) {
135
+ videoElement.srcObject = null;
136
+ videoElement = null;
137
+ }
138
+ placeholderVideo.srcObject = null;
139
+ isInitialized = false;
140
+ });
141
+ const uv$1 = baseUV;
142
+ const viewportAspect = viewportSize.x.div(viewportSize.y);
143
+ const objectFitMode = uniforms.objectFit.uniform;
144
+ const coverScale = max(viewportAspect.div(videoAspectUniform), float(1));
145
+ const coverUVScale = vec2(videoAspectUniform.div(viewportAspect).mul(coverScale), coverScale);
146
+ const containScale = min(viewportAspect.div(videoAspectUniform), float(1));
147
+ const containUVScale = vec2(videoAspectUniform.div(viewportAspect).mul(containScale), containScale);
148
+ const fillUVScale = vec2(1, 1);
149
+ const scaleDownScale = min(min(viewportAspect.div(videoAspectUniform), float(1)), min(viewportSize.x.div(videoWidthUniform), viewportSize.y.div(videoHeightUniform)));
150
+ const scaleDownUVScale = vec2(videoAspectUniform.div(viewportAspect).mul(scaleDownScale), scaleDownScale);
151
+ const noneScale = min(viewportSize.x.div(videoWidthUniform), viewportSize.y.div(videoHeightUniform));
152
+ const noneUVScale = vec2(videoAspectUniform.div(viewportAspect).mul(noneScale), noneScale);
153
+ const isCover = step(objectFitMode, float(.5));
154
+ const isContain = step(float(.5), objectFitMode).mul(step(objectFitMode, float(1.5)));
155
+ const isFill = step(float(1.5), objectFitMode).mul(step(objectFitMode, float(2.5)));
156
+ const isScaleDown = step(float(2.5), objectFitMode).mul(step(objectFitMode, float(3.5)));
157
+ const isNone = step(float(3.5), objectFitMode);
158
+ const uvScale = vec2(0).add(coverUVScale.mul(isCover)).add(containUVScale.mul(isContain)).add(fillUVScale.mul(isFill)).add(scaleDownUVScale.mul(isScaleDown)).add(noneUVScale.mul(isNone));
159
+ const adjustedUV = uv$1.sub(vec2(.5)).div(uvScale).add(vec2(.5));
160
+ const mirrorMode = uniforms.mirror.uniform;
161
+ const finalUV = vec2(select(mirrorMode, float(1).sub(adjustedUV.x), adjustedUV.x), float(1).sub(adjustedUV.y));
162
+ const sampledColor = textureNode.sample(finalUV);
163
+ const isOutOfBounds = or(or(finalUV.x.lessThan(0), finalUV.x.greaterThan(1)), or(finalUV.y.lessThan(0), finalUV.y.greaterThan(1)));
164
+ return vec4(sampledColor.rgb, select(isOutOfBounds, float(0), sampledColor.a));
165
+ }
166
+ };
167
+ var WebcamTexture_default = componentDefinition;
168
+ export { componentDefinition as n, WebcamTexture_default as t };
@@ -46,22 +46,24 @@ import { n as componentDefinition$40 } from "./RectangularCoordinates-CiW3J4UT.j
46
46
  import { n as componentDefinition$41 } from "./Ripples-DKBIp3Qq.js";
47
47
  import { n as componentDefinition$42 } from "./Saturation-DVVlpikK.js";
48
48
  import { n as componentDefinition$43 } from "./Sharpness-cw57bW0s.js";
49
- import { n as componentDefinition$44 } from "./SimplexNoise-CMMeggo6.js";
50
- import { n as componentDefinition$45 } from "./SineWave-DVVLqHPw.js";
51
- import { n as componentDefinition$46 } from "./SolidColor-zYROg_aE.js";
52
- import { n as componentDefinition$47 } from "./Spherize-tsKMpSaS.js";
53
- import { n as componentDefinition$48 } from "./Spiral-DDyVSeG_.js";
54
- import { n as componentDefinition$49 } from "./Strands-B9vY4uA7.js";
55
- import { n as componentDefinition$50 } from "./Stretch-BhHjbcqd.js";
56
- import { n as componentDefinition$51 } from "./Stripes-TdCUOh07.js";
57
- import { n as componentDefinition$52 } from "./Swirl-m1-Mnzj5.js";
58
- import { n as componentDefinition$53 } from "./TiltShift-C_NUqKZF.js";
59
- import { n as componentDefinition$54 } from "./Tint-ChKku9xR.js";
60
- import { n as componentDefinition$55 } from "./Tritone-D-NcV7N-.js";
61
- import { n as componentDefinition$56 } from "./Twirl-Cqzll6nW.js";
62
- import { n as componentDefinition$57 } from "./Vibrance-CxunJkcb.js";
63
- import { n as componentDefinition$58 } from "./WaveDistortion-UQZKCfKh.js";
64
- import { n as componentDefinition$59 } from "./ZoomBlur-DqKYdlmm.js";
49
+ import { n as componentDefinition$44 } from "./Shatter-COjV2jLy.js";
50
+ import { n as componentDefinition$45 } from "./SimplexNoise-Ce79jgYM.js";
51
+ import { n as componentDefinition$46 } from "./SineWave-Cv2gOU8a.js";
52
+ import { n as componentDefinition$47 } from "./SolidColor-DFkDBFq3.js";
53
+ import { n as componentDefinition$48 } from "./Spherize-R-s4pX9t.js";
54
+ import { n as componentDefinition$49 } from "./Spiral-W4dALX1z.js";
55
+ import { n as componentDefinition$50 } from "./Strands-DtN5POfO.js";
56
+ import { n as componentDefinition$51 } from "./Stretch-BzvP_hdu.js";
57
+ import { n as componentDefinition$52 } from "./Stripes-BbNFX05u.js";
58
+ import { n as componentDefinition$53 } from "./Swirl-CfsYsr4X.js";
59
+ import { n as componentDefinition$54 } from "./TiltShift-B6gbm7Z8.js";
60
+ import { n as componentDefinition$55 } from "./Tint-CpnitsHw.js";
61
+ import { n as componentDefinition$56 } from "./Tritone-DzvSKVfR.js";
62
+ import { n as componentDefinition$57 } from "./Twirl-BXH4uAd6.js";
63
+ import { n as componentDefinition$58 } from "./Vibrance-ByN9bRgU.js";
64
+ import { n as componentDefinition$59 } from "./WaveDistortion-BA1PyqYH.js";
65
+ import { n as componentDefinition$60 } from "./WebcamTexture-D4Uv7Plz.js";
66
+ import { n as componentDefinition$61 } from "./ZoomBlur-CIkkDBIo.js";
65
67
  import { Material, Mesh, MeshBasicNodeMaterial, OrthographicCamera, PlaneGeometry, SRGBColorSpace, Scene, WebGPURenderer } from "three/webgpu";
66
68
  import { WebGLRenderer } from "three";
67
69
  import { PI, abs, add, atan, convertToTexture, cos, div, dot, float, fract, max, min, mix, mul, pow, screenUV, sin, smoothstep, sqrt, step, sub, time, uniform, uv, vec2, vec3, vec4 } from "three/tsl";
@@ -1088,7 +1090,7 @@ function shaderRenderer() {
1088
1090
  }
1089
1091
  }
1090
1092
  };
1091
- const registerNode = (id, fragmentNodeFunc, parentId, metadata, uniforms = {}, componentDefinition$60) => {
1093
+ const registerNode = (id, fragmentNodeFunc, parentId, metadata, uniforms = {}, componentDefinition$62) => {
1092
1094
  if (fragmentNodeFunc === null) {
1093
1095
  const queueIndex = pendingRegistrationQueue.findIndex((item) => item.id === id);
1094
1096
  if (queueIndex !== -1) {
@@ -1106,7 +1108,7 @@ function shaderRenderer() {
1106
1108
  parentId,
1107
1109
  metadata,
1108
1110
  uniforms,
1109
- componentDefinition: componentDefinition$60
1111
+ componentDefinition: componentDefinition$62
1110
1112
  };
1111
1113
  else pendingRegistrationQueue.push({
1112
1114
  id,
@@ -1114,7 +1116,7 @@ function shaderRenderer() {
1114
1116
  parentId,
1115
1117
  metadata,
1116
1118
  uniforms,
1117
- componentDefinition: componentDefinition$60
1119
+ componentDefinition: componentDefinition$62
1118
1120
  });
1119
1121
  return;
1120
1122
  }
@@ -1147,11 +1149,11 @@ function shaderRenderer() {
1147
1149
  }
1148
1150
  const nodeInfo = {
1149
1151
  id,
1150
- componentName: componentDefinition$60?.name || "Unknown",
1152
+ componentName: componentDefinition$62?.name || "Unknown",
1151
1153
  fragmentNodeFunc,
1152
1154
  parentId,
1153
- requiresRTT: componentDefinition$60?.requiresRTT || false,
1154
- requiresChild: componentDefinition$60?.requiresChild || false,
1155
+ requiresRTT: componentDefinition$62?.requiresRTT || false,
1156
+ requiresChild: componentDefinition$62?.requiresChild || false,
1155
1157
  opacityUniform,
1156
1158
  metadata: {
1157
1159
  blendMode: metadata?.blendMode || "normal",
@@ -1467,7 +1469,7 @@ function shaderRenderer() {
1467
1469
  if (pendingRegistrationQueue.length === 0) return;
1468
1470
  const queue = [...pendingRegistrationQueue];
1469
1471
  pendingRegistrationQueue = [];
1470
- for (const { id, fragmentNodeFunc, parentId, metadata, uniforms, componentDefinition: componentDefinition$60 } of queue) if (fragmentNodeFunc) registerNode(id, fragmentNodeFunc, parentId, metadata, uniforms, componentDefinition$60);
1472
+ for (const { id, fragmentNodeFunc, parentId, metadata, uniforms, componentDefinition: componentDefinition$62 } of queue) if (fragmentNodeFunc) registerNode(id, fragmentNodeFunc, parentId, metadata, uniforms, componentDefinition$62);
1471
1473
  };
1472
1474
  const initialize = async ({ canvas, enablePerformanceTracking: enableTracking = false }) => {
1473
1475
  if (isInitialized || isInitializing) return;
@@ -1806,22 +1808,24 @@ var createShaderRegistry = () => {
1806
1808
  Ripples: componentDefinition$41,
1807
1809
  Saturation: componentDefinition$42,
1808
1810
  Sharpness: componentDefinition$43,
1809
- SimplexNoise: componentDefinition$44,
1810
- SineWave: componentDefinition$45,
1811
- SolidColor: componentDefinition$46,
1812
- Spherize: componentDefinition$47,
1813
- Spiral: componentDefinition$48,
1814
- Strands: componentDefinition$49,
1815
- Stretch: componentDefinition$50,
1816
- Stripes: componentDefinition$51,
1817
- Swirl: componentDefinition$52,
1818
- TiltShift: componentDefinition$53,
1819
- Tint: componentDefinition$54,
1820
- Tritone: componentDefinition$55,
1821
- Twirl: componentDefinition$56,
1822
- Vibrance: componentDefinition$57,
1823
- WaveDistortion: componentDefinition$58,
1824
- ZoomBlur: componentDefinition$59
1811
+ Shatter: componentDefinition$44,
1812
+ SimplexNoise: componentDefinition$45,
1813
+ SineWave: componentDefinition$46,
1814
+ SolidColor: componentDefinition$47,
1815
+ Spherize: componentDefinition$48,
1816
+ Spiral: componentDefinition$49,
1817
+ Strands: componentDefinition$50,
1818
+ Stretch: componentDefinition$51,
1819
+ Stripes: componentDefinition$52,
1820
+ Swirl: componentDefinition$53,
1821
+ TiltShift: componentDefinition$54,
1822
+ Tint: componentDefinition$55,
1823
+ Tritone: componentDefinition$56,
1824
+ Twirl: componentDefinition$57,
1825
+ Vibrance: componentDefinition$58,
1826
+ WaveDistortion: componentDefinition$59,
1827
+ WebcamTexture: componentDefinition$60,
1828
+ ZoomBlur: componentDefinition$61
1825
1829
  };
1826
1830
  Object.entries(shaderDefinitions).forEach(([fileName, def]) => {
1827
1831
  const propsMetadata = {};
@@ -1 +1 @@
1
- {"version":3,"file":"shaderRegistry.d.ts","sourceRoot":"","sources":["../src/shaderRegistry.ts"],"names":[],"mappings":"AA+DA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAElD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,mBAAmB,CAAC,GAAG,CAAC,CAAA;IACpC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE;QAC5B,EAAE,CAAC,EAAE,GAAG,CAAA;QACR,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB,CAAC,CAAA;CACH;AAgGD,eAAO,MAAM,cAAc,qCAAyB,CAAA;AAGpD,wBAAgB,aAAa,IAAI,mBAAmB,EAAE,CAErD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAE7E;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,mBAAmB,EAAE,CAE5E;AAED,wBAAgB,mBAAmB,IAAI,MAAM,EAAE,CAG9C"}
1
+ {"version":3,"file":"shaderRegistry.d.ts","sourceRoot":"","sources":["../src/shaderRegistry.ts"],"names":[],"mappings":"AAiEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAElD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,mBAAmB,CAAC,GAAG,CAAC,CAAA;IACpC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE;QAC5B,EAAE,CAAC,EAAE,GAAG,CAAA;QACR,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB,CAAC,CAAA;CACH;AAkGD,eAAO,MAAM,cAAc,qCAAyB,CAAA;AAGpD,wBAAgB,aAAa,IAAI,mBAAmB,EAAE,CAErD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAE7E;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,mBAAmB,EAAE,CAE5E;AAED,wBAAgB,mBAAmB,IAAI,MAAM,EAAE,CAG9C"}
@@ -0,0 +1,70 @@
1
+ import { ComponentDefinition } from '../../types';
2
+
3
+ export interface ComponentProps {
4
+ /**
5
+ * Thickness of crack lines
6
+ *
7
+ * Accepts a number between 0.5 and 5.
8
+ * @default 1
9
+ */
10
+ crackWidth: number;
11
+ /**
12
+ * How much shards shift
13
+ *
14
+ * Accepts a number between 0 and 20.
15
+ * @default 4
16
+ */
17
+ intensity: number;
18
+ /**
19
+ * Cursor influence radius
20
+ *
21
+ * Accepts a number between 0.1 and 1.
22
+ * @default 0.4
23
+ */
24
+ radius: number;
25
+ /**
26
+ * How fast shards return to rest
27
+ *
28
+ * Accepts a number between 0.1 and 10.
29
+ * @default 1
30
+ */
31
+ decay: number;
32
+ /**
33
+ * Random seed for pattern
34
+ *
35
+ * Accepts a number between 0 and 50.
36
+ * @default 2
37
+ */
38
+ seed: number;
39
+ /**
40
+ * RGB separation for prismatic glass effect
41
+ *
42
+ * Accepts a number between 0 and 5.
43
+ * @default 1
44
+ */
45
+ chromaticSplit: number;
46
+ /**
47
+ * How much cracks bend/distort the underlying image
48
+ *
49
+ * Accepts a number between 0 and 10.
50
+ * @default 5
51
+ */
52
+ refractionStrength: number;
53
+ /**
54
+ * Subtle lighting on tilted shards for 3D depth
55
+ *
56
+ * Accepts a number between 0 and 0.5.
57
+ * @default 0.1
58
+ */
59
+ shardLighting: number;
60
+ /**
61
+ * How to handle edges when displacement pushes content out of bounds
62
+ *
63
+ * Accepts one of: `"stretch"`, `"transparent"`, `"mirror"`, `"wrap"`.
64
+ * @default "mirror"
65
+ */
66
+ edges: string;
67
+ }
68
+ export declare const componentDefinition: ComponentDefinition<ComponentProps>;
69
+ export default componentDefinition;
70
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/shaders/Shatter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAqB,MAAM,iBAAiB,CAAA;AAQvE,MAAM,WAAW,cAAc;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,MAAM,CAAA;IACtB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,aAAa,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,MAAM,CAAA;CAChB;AAQD,eAAO,MAAM,mBAAmB,EAAE,mBAAmB,CAAC,cAAc,CAqXnE,CAAA;AAED,eAAe,mBAAmB,CAAA"}
@@ -0,0 +1,4 @@
1
+ import "../../edges-Bd7GP4s2.js";
2
+ import "../../transformations-YbhRK-rd.js";
3
+ import { n as componentDefinition, t as Shatter_default } from "../../Shatter-COjV2jLy.js";
4
+ export { componentDefinition, Shatter_default as default };