@fjandin/react-shader 0.0.7 → 0.0.9

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 +1 @@
1
- {"version":3,"file":"shader.d.ts","sourceRoot":"","sources":["../../src/example/shader.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,QA4FnB,CAAA"}
1
+ {"version":3,"file":"shader.d.ts","sourceRoot":"","sources":["../../src/example/shader.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ,QAwCnB,CAAA"}
package/dist/index.cjs CHANGED
@@ -29,7 +29,10 @@ var __export = (target, all) => {
29
29
  // src/index.ts
30
30
  var exports_src = {};
31
31
  __export(exports_src, {
32
+ generateUtilsFunction: () => generateUtilsFunction,
32
33
  generateSimplexNoiseFunction: () => generateSimplexNoiseFunction,
34
+ generateSceneCirclesFunction: () => generateSceneCirclesFunction,
35
+ generateDistortionRippleFunction: () => generateDistortionRippleFunction,
33
36
  generateColorPaletteFunction: () => generateColorPaletteFunction,
34
37
  ReactShader: () => ReactShader
35
38
  });
@@ -550,6 +553,63 @@ function generateColorPaletteFunction(name, paletteString) {
550
553
  }
551
554
  `;
552
555
  }
556
+ // src/shaders/distortion-ripple.ts
557
+ function generateDistortionRippleFunction() {
558
+ return `
559
+ vec2 DistortionRipple(vec2 uv, vec2 center, float radius, float intensity, float thickness) {
560
+ // 1. Calculate vector and distance from center
561
+ vec2 dir = uv - center;
562
+ float dist = length(dir);
563
+
564
+ // 2. Create a mask so the ripple only exists near the radius Z
565
+ // Using smoothstep creates a soft edge for the ripple
566
+ float mask = smoothstep(radius + thickness, radius, dist) * smoothstep(radius - thickness, radius, dist);
567
+
568
+ // 3. Calculate the displacement amount using a Sine wave
569
+ // We subtract dist from radius to orient the wave correctly
570
+ float wave = sin((dist - radius) * 20.0);
571
+
572
+ // 4. Apply intensity and mask, then offset the UV
573
+ vec2 offset = normalize(dir) * wave * intensity * mask;
574
+
575
+ return offset;
576
+ }
577
+ `;
578
+ }
579
+ // src/shaders/scene-circles.ts
580
+ function generateSceneCirclesFunction(paletteString = "[[0.5 0.5 0.5] [0.5 0.5 0.5] [1.0 1.0 1.0] [0.263 0.416 0.557]]") {
581
+ return `
582
+ ${generateColorPaletteFunction("circlesPalette", paletteString)}
583
+
584
+ vec3 SceneCircles(
585
+ vec2 uv0,
586
+ float iterations,
587
+ float fractMultiplier,
588
+ float time,
589
+ float waveLength,
590
+ float edgeBlur,
591
+ float contrast
592
+ ) {
593
+ vec3 col = vec3(0.0);
594
+ vec2 uv = uv0;
595
+
596
+ for (float i = 0.0; i < iterations; i++) {
597
+ uv = fract(uv * fractMultiplier) - 0.5;
598
+
599
+ float d = length(uv) * exp(-length(uv0));
600
+
601
+ vec3 color = circlesPalette(length(uv0) + i * 0.4 + time * 0.4);
602
+
603
+ d = sin(d * waveLength + time) / waveLength;
604
+ d = abs(d);
605
+ d = pow(edgeBlur / d, contrast);
606
+
607
+ col += color * d;
608
+ }
609
+ return col;
610
+ }
611
+ `;
612
+ }
553
613
  // src/shaders/simplex-noise.ts
554
614
  function generateSimplexNoiseFunction() {
555
615
  return `
@@ -659,7 +719,7 @@ function generateSimplexNoiseFunction() {
659
719
  + dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ;
660
720
  }
661
721
 
662
- float SimplexNoise(vec3 v) {
722
+ float SimplexNoise3D(vec3 v) {
663
723
  const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
664
724
  const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
665
725
 
@@ -734,3 +794,15 @@ function generateSimplexNoiseFunction() {
734
794
  }
735
795
  `;
736
796
  }
797
+ // src/shaders/utils.ts
798
+ function generateUtilsFunction() {
799
+ return `
800
+ vec2 GetUv(vec2 fragCoord, vec2 resolution) {
801
+ return (fragCoord - 0.5 * resolution) / resolution.y;
802
+ }
803
+
804
+ vec2 GetMouse(vec2 mouse, vec2 resolution) {
805
+ return (mouse - 0.5 * resolution) / resolution.y;
806
+ }
807
+ `;
808
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  export { ReactShader } from "./ReactShader";
2
2
  export { generateColorPaletteFunction } from "./shaders/color-palette";
3
+ export { generateDistortionRippleFunction } from "./shaders/distortion-ripple";
4
+ export { generateSceneCirclesFunction } from "./shaders/scene-circles";
3
5
  export { generateSimplexNoiseFunction } from "./shaders/simplex-noise";
6
+ export { generateUtilsFunction } from "./shaders/utils";
4
7
  export type { DefaultUniforms, FloatArray, FrameInfo, ReactShaderProps, UniformValue, Vec2, Vec2Array, Vec3, Vec3Array, Vec4, Vec4Array, } from "./types";
5
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAA;AACtE,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAA;AACtE,YAAY,EACV,eAAe,EACf,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,SAAS,GACV,MAAM,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAA;AACtE,OAAO,EAAE,gCAAgC,EAAE,MAAM,6BAA6B,CAAA;AAC9E,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAA;AACtE,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAA;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACvD,YAAY,EACV,eAAe,EACf,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,SAAS,GACV,MAAM,SAAS,CAAA"}
package/dist/index.js CHANGED
@@ -513,6 +513,63 @@ function generateColorPaletteFunction(name, paletteString) {
513
513
  }
514
514
  `;
515
515
  }
516
+ // src/shaders/distortion-ripple.ts
517
+ function generateDistortionRippleFunction() {
518
+ return `
519
+ vec2 DistortionRipple(vec2 uv, vec2 center, float radius, float intensity, float thickness) {
520
+ // 1. Calculate vector and distance from center
521
+ vec2 dir = uv - center;
522
+ float dist = length(dir);
523
+
524
+ // 2. Create a mask so the ripple only exists near the radius Z
525
+ // Using smoothstep creates a soft edge for the ripple
526
+ float mask = smoothstep(radius + thickness, radius, dist) * smoothstep(radius - thickness, radius, dist);
527
+
528
+ // 3. Calculate the displacement amount using a Sine wave
529
+ // We subtract dist from radius to orient the wave correctly
530
+ float wave = sin((dist - radius) * 20.0);
531
+
532
+ // 4. Apply intensity and mask, then offset the UV
533
+ vec2 offset = normalize(dir) * wave * intensity * mask;
534
+
535
+ return offset;
536
+ }
537
+ `;
538
+ }
539
+ // src/shaders/scene-circles.ts
540
+ function generateSceneCirclesFunction(paletteString = "[[0.5 0.5 0.5] [0.5 0.5 0.5] [1.0 1.0 1.0] [0.263 0.416 0.557]]") {
541
+ return `
542
+ ${generateColorPaletteFunction("circlesPalette", paletteString)}
543
+
544
+ vec3 SceneCircles(
545
+ vec2 uv0,
546
+ float iterations,
547
+ float fractMultiplier,
548
+ float time,
549
+ float waveLength,
550
+ float edgeBlur,
551
+ float contrast
552
+ ) {
553
+ vec3 col = vec3(0.0);
554
+ vec2 uv = uv0;
555
+
556
+ for (float i = 0.0; i < iterations; i++) {
557
+ uv = fract(uv * fractMultiplier) - 0.5;
558
+
559
+ float d = length(uv) * exp(-length(uv0));
560
+
561
+ vec3 color = circlesPalette(length(uv0) + i * 0.4 + time * 0.4);
562
+
563
+ d = sin(d * waveLength + time) / waveLength;
564
+ d = abs(d);
565
+ d = pow(edgeBlur / d, contrast);
566
+
567
+ col += color * d;
568
+ }
569
+ return col;
570
+ }
571
+ `;
572
+ }
516
573
  // src/shaders/simplex-noise.ts
517
574
  function generateSimplexNoiseFunction() {
518
575
  return `
@@ -622,7 +679,7 @@ function generateSimplexNoiseFunction() {
622
679
  + dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ;
623
680
  }
624
681
 
625
- float SimplexNoise(vec3 v) {
682
+ float SimplexNoise3D(vec3 v) {
626
683
  const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
627
684
  const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
628
685
 
@@ -697,8 +754,23 @@ function generateSimplexNoiseFunction() {
697
754
  }
698
755
  `;
699
756
  }
757
+ // src/shaders/utils.ts
758
+ function generateUtilsFunction() {
759
+ return `
760
+ vec2 GetUv(vec2 fragCoord, vec2 resolution) {
761
+ return (fragCoord - 0.5 * resolution) / resolution.y;
762
+ }
763
+
764
+ vec2 GetMouse(vec2 mouse, vec2 resolution) {
765
+ return (mouse - 0.5 * resolution) / resolution.y;
766
+ }
767
+ `;
768
+ }
700
769
  export {
770
+ generateUtilsFunction,
701
771
  generateSimplexNoiseFunction,
772
+ generateSceneCirclesFunction,
773
+ generateDistortionRippleFunction,
702
774
  generateColorPaletteFunction,
703
775
  ReactShader
704
776
  };
@@ -0,0 +1,16 @@
1
+ /**
2
+ *
3
+ * @returns glsl function for distortion ripple
4
+ *
5
+ * vec2 uv: uv coordinates
6
+ *
7
+ * vec2 center: center of the ripple
8
+ *
9
+ * float radius: radius of the ripple
10
+ *
11
+ * float intensity: intensity of the ripple
12
+ *
13
+ * float thickness: thickness of the ripple
14
+ */
15
+ export declare function generateDistortionRippleFunction(): string;
16
+ //# sourceMappingURL=distortion-ripple.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"distortion-ripple.d.ts","sourceRoot":"","sources":["../../src/shaders/distortion-ripple.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gCAAgC,WAqB/C"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ *
3
+ * @param paletteString
4
+ * @returns glsl function for rendering circles
5
+ *
6
+ * vec2 uv0: uv coordinates
7
+ *
8
+ * float iterations: number of iterations
9
+ *
10
+ * float fractMultiplier: fract multiplier
11
+ *
12
+ * float time: time
13
+ *
14
+ * float waveLength: wave length
15
+ *
16
+ * float edgeBlur: edge blur
17
+ *
18
+ * float contrast: contrast
19
+ */
20
+ export declare function generateSceneCirclesFunction(paletteString?: string): string;
21
+ //# sourceMappingURL=scene-circles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scene-circles.d.ts","sourceRoot":"","sources":["../../src/shaders/scene-circles.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,4BAA4B,CAC1C,aAAa,SAAoE,UAiClF"}
@@ -0,0 +1,2 @@
1
+ export declare function generateUtilsFunction(): string;
2
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/shaders/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,WAUpC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fjandin/react-shader",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "React component for rendering WebGL shaders",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",