shaders 2.5.123 → 2.5.124

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.
@@ -1,11 +1,21 @@
1
1
  import { a as transformColor } from "./transformations-CJcUeZIC.js";
2
2
  import { t as createAnimatedTime } from "./time-DUqSFWvT.js";
3
- import { Fn, cos, dot, float, floor, fract, length, min, mix, screenUV, sin, smoothstep, time, vec2, vec3, vec4, viewportSize } from "three/tsl";
3
+ import { StorageTexture } from "three/webgpu";
4
+ import { FloatType } from "three";
5
+ import { Fn, cos, dot, float, floor, fract, instanceIndex, length, min, mix, screenUV, sin, smoothstep, storageTexture, texture, textureStore, time, uint, uniform, uvec2, vec2, vec3, vec4, viewportSize } from "three/tsl";
6
+ var PARTICLE_TEX = 1024;
4
7
  var hash1_2 = Fn(([p]) => {
5
- return fract(sin(dot(p, vec2(127.1, 311.7))).mul(43758.5453123));
8
+ const p3 = fract(vec3(p.x, p.y, p.x).mul(.1031));
9
+ const d = dot(p3, vec3(p3.y, p3.z, p3.x).add(33.33));
10
+ const p3b = p3.add(d);
11
+ return fract(p3b.x.add(p3b.y).mul(p3b.z));
6
12
  });
7
13
  var hash2_2 = Fn(([p]) => {
8
- return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))).mul(43758.5453));
14
+ const p3 = fract(vec3(p.x, p.y, p.x).mul(vec3(.1031, .103, .0973)));
15
+ const d = dot(p3, vec3(p3.y, p3.z, p3.x).add(33.33));
16
+ const p3b = p3.add(d);
17
+ const s = p3b.x.add(p3b.y);
18
+ return fract(vec2(s.mul(p3b.z), s.mul(p3b.y)));
9
19
  });
10
20
  var voronoiPointFromRoot = Fn(([root, deg]) => {
11
21
  const point = hash2_2(root).sub(.5);
@@ -20,6 +30,13 @@ var getParticleDistance = Fn(([uv$1, cellUV, randomness]) => {
20
30
  const pointUV = voronoiPointFromRoot(cellUV, degFromRootUV(cellUV, randomness));
21
31
  return length(uv$1.sub(pointUV));
22
32
  });
33
+ var degFromRootUV_compute = Fn(([uv$1, randomness, frameTimeU]) => {
34
+ return frameTimeU.mul(randomness).mul(hash1_2(uv$1).sub(.5)).mul(2);
35
+ });
36
+ var getParticleDistance_compute = Fn(([uv$1, cellUV, randomness, frameTimeU]) => {
37
+ const pointUV = voronoiPointFromRoot(cellUV, degFromRootUV_compute(cellUV, randomness, frameTimeU));
38
+ return length(uv$1.sub(pointUV));
39
+ });
23
40
  const componentDefinition = {
24
41
  name: "FloatingParticles",
25
42
  category: "Textures",
@@ -63,7 +80,7 @@ const componentDefinition = {
63
80
  }
64
81
  },
65
82
  particleSize: {
66
- default: 1,
83
+ default: 2,
67
84
  description: "Size of particles",
68
85
  ui: {
69
86
  type: ["range", "map"],
@@ -157,8 +174,106 @@ const componentDefinition = {
157
174
  }
158
175
  }
159
176
  },
177
+ computeNode: (params) => {
178
+ const { uniforms, onCleanup } = params;
179
+ const texSize = PARTICLE_TEX;
180
+ const count = texSize * texSize;
181
+ const gs = uint(texSize);
182
+ const outTex = new StorageTexture(texSize, texSize);
183
+ outTex.type = FloatType;
184
+ const outTexNode = storageTexture(outTex);
185
+ onCleanup(() => outTex.dispose());
186
+ const animTimeU = uniform(0);
187
+ const frameTimeU = uniform(0);
188
+ const aspectU = uniform(16 / 9);
189
+ const computeRenderParticle = Fn(([uv$1]) => {
190
+ const rootUV = floor(uv$1);
191
+ const randomness = uniforms.randomness.uniform;
192
+ const dCenter = getParticleDistance_compute(uv$1, rootUV, randomness, frameTimeU);
193
+ const dLeft = getParticleDistance_compute(uv$1, rootUV.add(vec2(-1, 0)), randomness, frameTimeU);
194
+ const dRight = getParticleDistance_compute(uv$1, rootUV.add(vec2(1, 0)), randomness, frameTimeU);
195
+ const dTop = getParticleDistance_compute(uv$1, rootUV.add(vec2(0, -1)), randomness, frameTimeU);
196
+ const dBottom = getParticleDistance_compute(uv$1, rootUV.add(vec2(0, 1)), randomness, frameTimeU);
197
+ const minDist = min(min(min(min(dCenter, dLeft), dRight), dTop), dBottom);
198
+ const softness = uniforms.particleSoftness.uniform;
199
+ const scaledSize = uniforms.particleSize.uniform.mul(.01);
200
+ const innerRadius = scaledSize.mul(.6);
201
+ const baseIntensity = smoothstep(innerRadius, innerRadius.add(softness.mul(scaledSize.mul(2.4))), minDist).oneMinus();
202
+ const twinkleIntensity = uniforms.twinkle.uniform;
203
+ const particlePhase = hash1_2(rootUV);
204
+ const twinkleValue = sin(frameTimeU.mul(2).add(particlePhase.mul(6.28318))).mul(.5).add(.5);
205
+ const twinkleModifier = mix(float(1), twinkleValue, twinkleIntensity);
206
+ return baseIntensity.mul(twinkleModifier).mul(uniforms.particleColor.uniform.rgb);
207
+ });
208
+ const computeLayeredParticles = Fn(([uv$1]) => {
209
+ const sizeMod = float(1.05);
210
+ const alphaMod = float(.9);
211
+ const layers = uniforms.count.uniform;
212
+ const particles = vec3(0).toVar();
213
+ const layerScale = float(1).toVar();
214
+ const alpha = float(1).toVar();
215
+ const offset = vec2(0).toVar();
216
+ const angleRad = uniforms.angle.uniform.mul(3.14159).div(180);
217
+ const baseMovementDir = vec2(cos(angleRad), sin(angleRad));
218
+ const baseMovement = animTimeU.mul(baseMovementDir);
219
+ const speedVar = uniforms.speedVariance.uniform;
220
+ const angleVar = uniforms.angleVariance.uniform.mul(3.14159).div(180);
221
+ for (let i = 0; i < 5; i++) {
222
+ const layerActive = float(i).lessThan(layers).and(alpha.greaterThan(.02));
223
+ const layerHash = hash2_2(vec2(alpha, float(i).mul(7.919)));
224
+ const speedMod = float(1).add(layerHash.x.sub(.5).mul(speedVar));
225
+ const angleDelta = layerHash.y.sub(.5).mul(angleVar).mul(2);
226
+ const variedAngle = angleRad.add(angleDelta).toVar();
227
+ const variedDir = vec2(cos(variedAngle), sin(variedAngle));
228
+ const movement = baseMovement.mul(speedMod).add(variedDir.sub(baseMovementDir).mul(animTimeU));
229
+ const layerParticles = computeRenderParticle(uv$1.mul(layerScale).add(movement).add(offset)).mul(alpha);
230
+ particles.assign(particles.add(layerActive.select(layerParticles, vec3(0))));
231
+ offset.assign(offset.add(layerHash.mul(10)));
232
+ alpha.assign(alpha.mul(alphaMod));
233
+ layerScale.assign(layerScale.mul(sizeMod));
234
+ }
235
+ return particles;
236
+ });
237
+ const particlePass = Fn(() => {
238
+ const idx = instanceIndex;
239
+ const j = idx.mod(gs);
240
+ const i = idx.div(gs);
241
+ const u = j.toFloat().add(.5).div(float(texSize));
242
+ const v = i.toFloat().add(.5).div(float(texSize));
243
+ const particles = computeLayeredParticles(vec2(u.mul(2).sub(1).mul(aspectU), v.mul(2).sub(1)).mul(uniforms.particleDensity.uniform));
244
+ const pa = length(particles).clamp(0, 1);
245
+ textureStore(outTexNode, uvec2(j, i), vec4(particles, pa)).toWriteOnly();
246
+ })().compute(count, [256]);
247
+ return {
248
+ outputs: { particleTexture: outTex },
249
+ getComputeNodes: (frameParams) => {
250
+ animTimeU.value += frameParams.deltaTime * uniforms.speed.uniform.value;
251
+ frameTimeU.value += frameParams.deltaTime;
252
+ if (frameParams.dimensions.height > 0) aspectU.value = frameParams.dimensions.width / frameParams.dimensions.height;
253
+ return [particlePass];
254
+ }
255
+ };
256
+ },
160
257
  fragmentNode: (params) => {
161
- const { uniforms, childNode } = params;
258
+ const { uniforms, childNode, computeOutputs } = params;
259
+ if (computeOutputs?.particleTexture) {
260
+ const particleField = texture(computeOutputs.particleTexture);
261
+ const px = float(1 / PARTICLE_TEX);
262
+ const s0 = particleField.sample(screenUV);
263
+ const s1 = particleField.sample(screenUV.add(vec2(px, float(0))));
264
+ const s2 = particleField.sample(screenUV.add(vec2(float(0), px)));
265
+ const s3 = particleField.sample(screenUV.add(vec2(px.negate(), float(0))));
266
+ const s4 = particleField.sample(screenUV.add(vec2(float(0), px.negate())));
267
+ const w0 = float(.5), w1 = float(.125);
268
+ const particles$1 = s0.xyz.mul(w0).add(s1.xyz.mul(w1)).add(s2.xyz.mul(w1)).add(s3.xyz.mul(w1)).add(s4.xyz.mul(w1));
269
+ const particleAlpha$1 = s0.w.mul(w0).add(s1.w.mul(w1)).add(s2.w.mul(w1)).add(s3.w.mul(w1)).add(s4.w.mul(w1));
270
+ if (childNode) {
271
+ const mixedColor = mix(childNode.xyz, particles$1, particleAlpha$1.greaterThan(.01).select(particleAlpha$1, 0));
272
+ const pa = particleAlpha$1.clamp(0, 1);
273
+ return vec4(mixedColor, pa.add(childNode.w.mul(float(1).sub(pa))));
274
+ }
275
+ return vec4(particles$1, particleAlpha$1);
276
+ }
162
277
  const baseUV = screenUV;
163
278
  const animTime = createAnimatedTime(params, uniforms.speed);
164
279
  const renderParticle = Fn(([uv$2]) => {
@@ -175,7 +290,7 @@ const componentDefinition = {
175
290
  const innerRadius = scaledSize.mul(.6);
176
291
  const baseIntensity = smoothstep(innerRadius, innerRadius.add(softness.mul(scaledSize.mul(2.4))), minDist).oneMinus();
177
292
  const twinkleIntensity = uniforms.twinkle.uniform;
178
- const particlePhase = rootUV.x.mul(12.9898).add(rootUV.y.mul(78.233)).sin().mul(43758.5453).fract();
293
+ const particlePhase = hash1_2(rootUV);
179
294
  const twinkleValue = sin(time.mul(2).add(particlePhase.mul(6.28318))).mul(.5).add(.5);
180
295
  const twinkleModifier = mix(float(1), twinkleValue, twinkleIntensity);
181
296
  return baseIntensity.mul(twinkleModifier).mul(uniforms.particleColor.uniform.rgb);
@@ -193,7 +308,7 @@ const componentDefinition = {
193
308
  const baseMovement = animTime.mul(baseMovementDir);
194
309
  const speedVar = uniforms.speedVariance.uniform;
195
310
  const angleVar = uniforms.angleVariance.uniform.mul(3.14159).div(180);
196
- for (let i = 0; i < 4; i++) {
311
+ for (let i = 0; i < 5; i++) {
197
312
  const layerActive = float(i).lessThan(layers).and(alpha.greaterThan(.02));
198
313
  const layerHash = hash2_2(vec2(alpha, float(i).mul(7.919)));
199
314
  const speedMod = float(1).add(layerHash.x.sub(.5).mul(speedVar));
@@ -42,7 +42,7 @@ import "./Ellipse-sWhNvW9-.js";
42
42
  import "./Emboss-DGaubb9x.js";
43
43
  import "./FallingLines-DqIZ8wTH.js";
44
44
  import "./FilmGrain-Dbw02Jz9.js";
45
- import "./FloatingParticles-DKoG78j0.js";
45
+ import "./FloatingParticles-LMsFTJKp.js";
46
46
  import "./Flower-BbRNrXIa.js";
47
47
  import "./FlowField-D3CAHBBG.js";
48
48
  import "./FlowingGradient-BRQ_K-k3.js";
@@ -123,7 +123,7 @@ import "./Weave-ou5shgl3.js";
123
123
  import "./WebcamTexture-D4e06ajM.js";
124
124
  import "./WorleyNoise-Uf6IPm7A.js";
125
125
  import "./ZoomBlur-DJ-RNKHM.js";
126
- import { t as getAllShaders } from "./shaderRegistry-9d8S78Sy.js";
126
+ import { t as getAllShaders } from "./shaderRegistry-DZDkRCt8.js";
127
127
  import { Material, Mesh, MeshBasicNodeMaterial, OrthographicCamera, PlaneGeometry, SRGBColorSpace, Scene, Vector2, WebGPURenderer } from "three/webgpu";
128
128
  import { WebGLRenderer } from "three";
129
129
  import { PI, abs, add, atan, clamp, convertToTexture, cos, div, dot, float, fract, max, min, mix, mul, pow, screenUV, sign, sin, smoothstep, sqrt, step, sub, time, uniform, uv, vec2, vec3, vec4 } from "three/tsl";
@@ -42,7 +42,7 @@ import "./Ellipse-sWhNvW9-.js";
42
42
  import "./Emboss-DGaubb9x.js";
43
43
  import "./FallingLines-DqIZ8wTH.js";
44
44
  import "./FilmGrain-Dbw02Jz9.js";
45
- import "./FloatingParticles-DKoG78j0.js";
45
+ import "./FloatingParticles-LMsFTJKp.js";
46
46
  import "./Flower-BbRNrXIa.js";
47
47
  import "./FlowField-D3CAHBBG.js";
48
48
  import "./FlowingGradient-BRQ_K-k3.js";
@@ -123,5 +123,5 @@ import "./Weave-ou5shgl3.js";
123
123
  import "./WebcamTexture-D4e06ajM.js";
124
124
  import "./WorleyNoise-Uf6IPm7A.js";
125
125
  import "./ZoomBlur-DJ-RNKHM.js";
126
- import { a as shaderRegistry, i as getShadersByCategory, n as getShaderByName, r as getShaderCategories, t as getAllShaders } from "./shaderRegistry-9d8S78Sy.js";
126
+ import { a as shaderRegistry, i as getShadersByCategory, n as getShaderByName, r as getShaderCategories, t as getAllShaders } from "./shaderRegistry-DZDkRCt8.js";
127
127
  export { getAllShaders, getShaderByName, getShaderCategories, getShadersByCategory, shaderRegistry };
@@ -35,7 +35,7 @@ import { n as componentDefinition$33 } from "./Ellipse-sWhNvW9-.js";
35
35
  import { n as componentDefinition$34 } from "./Emboss-DGaubb9x.js";
36
36
  import { n as componentDefinition$35 } from "./FallingLines-DqIZ8wTH.js";
37
37
  import { n as componentDefinition$36 } from "./FilmGrain-Dbw02Jz9.js";
38
- import { n as componentDefinition$37 } from "./FloatingParticles-DKoG78j0.js";
38
+ import { n as componentDefinition$37 } from "./FloatingParticles-LMsFTJKp.js";
39
39
  import { n as componentDefinition$38 } from "./Flower-BbRNrXIa.js";
40
40
  import { n as componentDefinition$39 } from "./FlowField-D3CAHBBG.js";
41
41
  import { n as componentDefinition$40 } from "./FlowingGradient-BRQ_K-k3.js";
@@ -25,7 +25,7 @@ export interface ComponentProps {
25
25
  /**
26
26
  * Size of particles
27
27
  *
28
- * @default 1
28
+ * @default 2
29
29
  */
30
30
  particleSize: number;
31
31
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/shaders/FloatingParticles/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAqB,MAAM,iBAAiB,CAAA;AAIvE,OAAO,EAAC,cAAc,EAAC,MAAM,qCAAqC,CAAA;AAkClE,MAAM,WAAW,cAAc;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,EAAE,MAAM,CAAA;IACpB,gBAAgB,EAAE,MAAM,CAAA;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;IACnD,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;CAC1B;AAED,eAAO,MAAM,mBAAmB,EAAE,mBAAmB,CAAC,cAAc,CAuMnE,CAAA;AAED,eAAe,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/shaders/FloatingParticles/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAwC,MAAM,iBAAiB,CAAA;AAU1F,OAAO,EAAC,cAAc,EAAC,MAAM,qCAAqC,CAAA;AA4DlE,MAAM,WAAW,cAAc;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,EAAE,MAAM,CAAA;IACpB,gBAAgB,EAAE,MAAM,CAAA;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;IACnD,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;CAC1B;AAED,eAAO,MAAM,mBAAmB,EAAE,mBAAmB,CAAC,cAAc,CA0SnE,CAAA;AAED,eAAe,mBAAmB,CAAA"}
@@ -1,4 +1,4 @@
1
1
  import "../../transformations-CJcUeZIC.js";
2
2
  import "../../time-DUqSFWvT.js";
3
- import { n as componentDefinition, t as FloatingParticles_default } from "../../FloatingParticles-DKoG78j0.js";
3
+ import { n as componentDefinition, t as FloatingParticles_default } from "../../FloatingParticles-LMsFTJKp.js";
4
4
  export { componentDefinition, FloatingParticles_default as default };
@@ -148,7 +148,7 @@ async function createShader(canvas, preset, options) {
148
148
  return;
149
149
  }
150
150
  if (renderer.getPerformanceStats().fps > 0) {
151
- state.telemetryCollector = startTelemetry(renderer, "2.5.123", options?.disableTelemetry || false, false);
151
+ state.telemetryCollector = startTelemetry(renderer, "2.5.124", options?.disableTelemetry || false, false);
152
152
  if (state.telemetryCollector) state.telemetryCollector.start();
153
153
  state.telemetryStartTimeout = null;
154
154
  } else state.telemetryStartTimeout = setTimeout(checkRendering, 500);
@@ -468,7 +468,7 @@ var shaderMetadata = {
468
468
  "randomness": .25,
469
469
  "speed": .25,
470
470
  "angle": 90,
471
- "particleSize": 1,
471
+ "particleSize": 2,
472
472
  "particleSoftness": 0,
473
473
  "twinkle": .5,
474
474
  "count": 5,
@@ -89,7 +89,7 @@ const Shader = ({ children, disableTelemetry = false, colorSpace = "p3-linear",
89
89
  return;
90
90
  }
91
91
  if (rendererRef.current.getPerformanceStats().fps > 0) {
92
- telemetryCollectorRef.current = startTelemetry(rendererRef.current, "2.5.123", disableTelemetry, isPreview);
92
+ telemetryCollectorRef.current = startTelemetry(rendererRef.current, "2.5.124", disableTelemetry, isPreview);
93
93
  if (telemetryCollectorRef.current) telemetryCollectorRef.current.start();
94
94
  telemetryStartTimeoutRef.current = null;
95
95
  } else telemetryStartTimeoutRef.current = window.setTimeout(checkRendering, 500);