@fjandin/react-shader 0.0.6 → 0.0.7

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/index.cjs CHANGED
@@ -29,7 +29,8 @@ var __export = (target, all) => {
29
29
  // src/index.ts
30
30
  var exports_src = {};
31
31
  __export(exports_src, {
32
- generateUniformDeclarations: () => generateUniformDeclarations,
32
+ generateSimplexNoiseFunction: () => generateSimplexNoiseFunction,
33
+ generateColorPaletteFunction: () => generateColorPaletteFunction,
33
34
  ReactShader: () => ReactShader
34
35
  });
35
36
  module.exports = __toCommonJS(exports_src);
@@ -536,3 +537,200 @@ function ReactShader({
536
537
  style: { display: "block", width: "100%", height: "100%" }
537
538
  }, undefined, false, undefined, this);
538
539
  }
540
+ // src/shaders/color-palette.ts
541
+ function generateColorPaletteFunction(name, paletteString) {
542
+ const paletteArray = paletteString.replace("[[", "").replace("]]", "").split("] [").map((s) => s.split(" "));
543
+ return `
544
+ vec3 ${name}( float t ) {
545
+ vec3 a = vec3(${paletteArray[0].join(",")});
546
+ vec3 b = vec3(${paletteArray[1].join(",")});
547
+ vec3 c = vec3(${paletteArray[2].join(",")});
548
+ vec3 d = vec3(${paletteArray[3].join(",")});
549
+ return a + b * cos(6.28318 * (c * t + d));
550
+ }
551
+ `;
552
+ }
553
+ // src/shaders/simplex-noise.ts
554
+ function generateSimplexNoiseFunction() {
555
+ return `
556
+
557
+ vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
558
+
559
+ vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
560
+
561
+ float mod289(float x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
562
+
563
+ vec4 permute(vec4 x) { return mod289(((x*34.0)+10.0)*x); }
564
+
565
+ float permute(float x) { return mod289(((x*34.0)+10.0)*x); }
566
+
567
+ vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }
568
+
569
+ float taylorInvSqrt(float r) { return 1.79284291400159 - 0.85373472095314 * r; }
570
+
571
+ vec4 grad4(float j, vec4 ip) {
572
+ const vec4 ones = vec4(1.0, 1.0, 1.0, -1.0);
573
+ vec4 p,s;
574
+
575
+ p.xyz = floor( fract (vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0;
576
+ p.w = 1.5 - dot(abs(p.xyz), ones.xyz);
577
+ s = vec4(lessThan(p, vec4(0.0)));
578
+ p.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www;
579
+
580
+ return p;
581
+ }
582
+
583
+ // (sqrt(5) - 1)/4 = F4, used once below
584
+ #define F4 0.309016994374947451
585
+
586
+ float SimplexNoise4D(vec4 v) {
587
+ const vec4 C = vec4( 0.138196601125011, // (5 - sqrt(5))/20 G4
588
+ 0.276393202250021, // 2 * G4
589
+ 0.414589803375032, // 3 * G4
590
+ -0.447213595499958); // -1 + 4 * G4
591
+
592
+ // First corner
593
+ vec4 i = floor(v + dot(v, vec4(F4)) );
594
+ vec4 x0 = v - i + dot(i, C.xxxx);
595
+
596
+ // Other corners
597
+
598
+ // Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI)
599
+ vec4 i0;
600
+ vec3 isX = step( x0.yzw, x0.xxx );
601
+ vec3 isYZ = step( x0.zww, x0.yyz );
602
+ // i0.x = dot( isX, vec3( 1.0 ) );
603
+ i0.x = isX.x + isX.y + isX.z;
604
+ i0.yzw = 1.0 - isX;
605
+ // i0.y += dot( isYZ.xy, vec2( 1.0 ) );
606
+ i0.y += isYZ.x + isYZ.y;
607
+ i0.zw += 1.0 - isYZ.xy;
608
+ i0.z += isYZ.z;
609
+ i0.w += 1.0 - isYZ.z;
610
+
611
+ // i0 now contains the unique values 0,1,2,3 in each channel
612
+ vec4 i3 = clamp( i0, 0.0, 1.0 );
613
+ vec4 i2 = clamp( i0-1.0, 0.0, 1.0 );
614
+ vec4 i1 = clamp( i0-2.0, 0.0, 1.0 );
615
+
616
+ // x0 = x0 - 0.0 + 0.0 * C.xxxx
617
+ // x1 = x0 - i1 + 1.0 * C.xxxx
618
+ // x2 = x0 - i2 + 2.0 * C.xxxx
619
+ // x3 = x0 - i3 + 3.0 * C.xxxx
620
+ // x4 = x0 - 1.0 + 4.0 * C.xxxx
621
+ vec4 x1 = x0 - i1 + C.xxxx;
622
+ vec4 x2 = x0 - i2 + C.yyyy;
623
+ vec4 x3 = x0 - i3 + C.zzzz;
624
+ vec4 x4 = x0 + C.wwww;
625
+
626
+ // Permutations
627
+ i = mod289(i);
628
+ float j0 = permute( permute( permute( permute(i.w) + i.z) + i.y) + i.x);
629
+ vec4 j1 = permute( permute( permute( permute (
630
+ i.w + vec4(i1.w, i2.w, i3.w, 1.0 ))
631
+ + i.z + vec4(i1.z, i2.z, i3.z, 1.0 ))
632
+ + i.y + vec4(i1.y, i2.y, i3.y, 1.0 ))
633
+ + i.x + vec4(i1.x, i2.x, i3.x, 1.0 ));
634
+
635
+ // Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope
636
+ // 7*7*6 = 294, which is close to the ring size 17*17 = 289.
637
+ vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ;
638
+
639
+ vec4 p0 = grad4(j0, ip);
640
+ vec4 p1 = grad4(j1.x, ip);
641
+ vec4 p2 = grad4(j1.y, ip);
642
+ vec4 p3 = grad4(j1.z, ip);
643
+ vec4 p4 = grad4(j1.w, ip);
644
+
645
+ // Normalise gradients
646
+ vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
647
+ p0 *= norm.x;
648
+ p1 *= norm.y;
649
+ p2 *= norm.z;
650
+ p3 *= norm.w;
651
+ p4 *= taylorInvSqrt(dot(p4,p4));
652
+
653
+ // Mix contributions from the five corners
654
+ vec3 m0 = max(0.6 - vec3(dot(x0,x0), dot(x1,x1), dot(x2,x2)), 0.0);
655
+ vec2 m1 = max(0.6 - vec2(dot(x3,x3), dot(x4,x4) ), 0.0);
656
+ m0 = m0 * m0;
657
+ m1 = m1 * m1;
658
+ return 49.0 * ( dot(m0*m0, vec3( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 )))
659
+ + dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ;
660
+ }
661
+
662
+ float SimplexNoise(vec3 v) {
663
+ const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
664
+ const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
665
+
666
+ // First corner
667
+ vec3 i = floor(v + dot(v, C.yyy) );
668
+ vec3 x0 = v - i + dot(i, C.xxx) ;
669
+
670
+ // Other corners
671
+ vec3 g = step(x0.yzx, x0.xyz);
672
+ vec3 l = 1.0 - g;
673
+ vec3 i1 = min( g.xyz, l.zxy );
674
+ vec3 i2 = max( g.xyz, l.zxy );
675
+
676
+ // x0 = x0 - 0.0 + 0.0 * C.xxx;
677
+ // x1 = x0 - i1 + 1.0 * C.xxx;
678
+ // x2 = x0 - i2 + 2.0 * C.xxx;
679
+ // x3 = x0 - 1.0 + 3.0 * C.xxx;
680
+ vec3 x1 = x0 - i1 + C.xxx;
681
+ vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
682
+ vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y
683
+
684
+ // Permutations
685
+ i = mod289(i);
686
+ vec4 p = permute( permute( permute(
687
+ i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
688
+ + i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
689
+ + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
690
+
691
+ // Gradients: 7x7 points over a square, mapped onto an octahedron.
692
+ // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
693
+ float n_ = 0.142857142857; // 1.0/7.0
694
+ vec3 ns = n_ * D.wyz - D.xzx;
695
+
696
+ vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)
697
+
698
+ vec4 x_ = floor(j * ns.z);
699
+ vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)
700
+
701
+ vec4 x = x_ *ns.x + ns.yyyy;
702
+ vec4 y = y_ *ns.x + ns.yyyy;
703
+ vec4 h = 1.0 - abs(x) - abs(y);
704
+
705
+ vec4 b0 = vec4( x.xy, y.xy );
706
+ vec4 b1 = vec4( x.zw, y.zw );
707
+
708
+ //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
709
+ //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
710
+ vec4 s0 = floor(b0)*2.0 + 1.0;
711
+ vec4 s1 = floor(b1)*2.0 + 1.0;
712
+ vec4 sh = -step(h, vec4(0.0));
713
+
714
+ vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
715
+ vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
716
+
717
+ vec3 p0 = vec3(a0.xy,h.x);
718
+ vec3 p1 = vec3(a0.zw,h.y);
719
+ vec3 p2 = vec3(a1.xy,h.z);
720
+ vec3 p3 = vec3(a1.zw,h.w);
721
+
722
+ // Normalise gradients
723
+ vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
724
+ p0 *= norm.x;
725
+ p1 *= norm.y;
726
+ p2 *= norm.z;
727
+ p3 *= norm.w;
728
+
729
+ // Mix final noise value
730
+ vec4 m = max(0.5 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
731
+ m = m * m;
732
+ return 105.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
733
+ dot(p2,x2), dot(p3,x3) ) );
734
+ }
735
+ `;
736
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { ReactShader } from "./ReactShader";
2
+ export { generateColorPaletteFunction } from "./shaders/color-palette";
3
+ export { generateSimplexNoiseFunction } from "./shaders/simplex-noise";
2
4
  export type { DefaultUniforms, FloatArray, FrameInfo, ReactShaderProps, UniformValue, Vec2, Vec2Array, Vec3, Vec3Array, Vec4, Vec4Array, } from "./types";
3
- export { generateUniformDeclarations } from "./utils/uniforms";
4
5
  //# 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,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;AAChB,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,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,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"}
package/dist/index.js CHANGED
@@ -500,7 +500,205 @@ function ReactShader({
500
500
  style: { display: "block", width: "100%", height: "100%" }
501
501
  }, undefined, false, undefined, this);
502
502
  }
503
+ // src/shaders/color-palette.ts
504
+ function generateColorPaletteFunction(name, paletteString) {
505
+ const paletteArray = paletteString.replace("[[", "").replace("]]", "").split("] [").map((s) => s.split(" "));
506
+ return `
507
+ vec3 ${name}( float t ) {
508
+ vec3 a = vec3(${paletteArray[0].join(",")});
509
+ vec3 b = vec3(${paletteArray[1].join(",")});
510
+ vec3 c = vec3(${paletteArray[2].join(",")});
511
+ vec3 d = vec3(${paletteArray[3].join(",")});
512
+ return a + b * cos(6.28318 * (c * t + d));
513
+ }
514
+ `;
515
+ }
516
+ // src/shaders/simplex-noise.ts
517
+ function generateSimplexNoiseFunction() {
518
+ return `
519
+
520
+ vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
521
+
522
+ vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
523
+
524
+ float mod289(float x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
525
+
526
+ vec4 permute(vec4 x) { return mod289(((x*34.0)+10.0)*x); }
527
+
528
+ float permute(float x) { return mod289(((x*34.0)+10.0)*x); }
529
+
530
+ vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }
531
+
532
+ float taylorInvSqrt(float r) { return 1.79284291400159 - 0.85373472095314 * r; }
533
+
534
+ vec4 grad4(float j, vec4 ip) {
535
+ const vec4 ones = vec4(1.0, 1.0, 1.0, -1.0);
536
+ vec4 p,s;
537
+
538
+ p.xyz = floor( fract (vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0;
539
+ p.w = 1.5 - dot(abs(p.xyz), ones.xyz);
540
+ s = vec4(lessThan(p, vec4(0.0)));
541
+ p.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www;
542
+
543
+ return p;
544
+ }
545
+
546
+ // (sqrt(5) - 1)/4 = F4, used once below
547
+ #define F4 0.309016994374947451
548
+
549
+ float SimplexNoise4D(vec4 v) {
550
+ const vec4 C = vec4( 0.138196601125011, // (5 - sqrt(5))/20 G4
551
+ 0.276393202250021, // 2 * G4
552
+ 0.414589803375032, // 3 * G4
553
+ -0.447213595499958); // -1 + 4 * G4
554
+
555
+ // First corner
556
+ vec4 i = floor(v + dot(v, vec4(F4)) );
557
+ vec4 x0 = v - i + dot(i, C.xxxx);
558
+
559
+ // Other corners
560
+
561
+ // Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI)
562
+ vec4 i0;
563
+ vec3 isX = step( x0.yzw, x0.xxx );
564
+ vec3 isYZ = step( x0.zww, x0.yyz );
565
+ // i0.x = dot( isX, vec3( 1.0 ) );
566
+ i0.x = isX.x + isX.y + isX.z;
567
+ i0.yzw = 1.0 - isX;
568
+ // i0.y += dot( isYZ.xy, vec2( 1.0 ) );
569
+ i0.y += isYZ.x + isYZ.y;
570
+ i0.zw += 1.0 - isYZ.xy;
571
+ i0.z += isYZ.z;
572
+ i0.w += 1.0 - isYZ.z;
573
+
574
+ // i0 now contains the unique values 0,1,2,3 in each channel
575
+ vec4 i3 = clamp( i0, 0.0, 1.0 );
576
+ vec4 i2 = clamp( i0-1.0, 0.0, 1.0 );
577
+ vec4 i1 = clamp( i0-2.0, 0.0, 1.0 );
578
+
579
+ // x0 = x0 - 0.0 + 0.0 * C.xxxx
580
+ // x1 = x0 - i1 + 1.0 * C.xxxx
581
+ // x2 = x0 - i2 + 2.0 * C.xxxx
582
+ // x3 = x0 - i3 + 3.0 * C.xxxx
583
+ // x4 = x0 - 1.0 + 4.0 * C.xxxx
584
+ vec4 x1 = x0 - i1 + C.xxxx;
585
+ vec4 x2 = x0 - i2 + C.yyyy;
586
+ vec4 x3 = x0 - i3 + C.zzzz;
587
+ vec4 x4 = x0 + C.wwww;
588
+
589
+ // Permutations
590
+ i = mod289(i);
591
+ float j0 = permute( permute( permute( permute(i.w) + i.z) + i.y) + i.x);
592
+ vec4 j1 = permute( permute( permute( permute (
593
+ i.w + vec4(i1.w, i2.w, i3.w, 1.0 ))
594
+ + i.z + vec4(i1.z, i2.z, i3.z, 1.0 ))
595
+ + i.y + vec4(i1.y, i2.y, i3.y, 1.0 ))
596
+ + i.x + vec4(i1.x, i2.x, i3.x, 1.0 ));
597
+
598
+ // Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope
599
+ // 7*7*6 = 294, which is close to the ring size 17*17 = 289.
600
+ vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ;
601
+
602
+ vec4 p0 = grad4(j0, ip);
603
+ vec4 p1 = grad4(j1.x, ip);
604
+ vec4 p2 = grad4(j1.y, ip);
605
+ vec4 p3 = grad4(j1.z, ip);
606
+ vec4 p4 = grad4(j1.w, ip);
607
+
608
+ // Normalise gradients
609
+ vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
610
+ p0 *= norm.x;
611
+ p1 *= norm.y;
612
+ p2 *= norm.z;
613
+ p3 *= norm.w;
614
+ p4 *= taylorInvSqrt(dot(p4,p4));
615
+
616
+ // Mix contributions from the five corners
617
+ vec3 m0 = max(0.6 - vec3(dot(x0,x0), dot(x1,x1), dot(x2,x2)), 0.0);
618
+ vec2 m1 = max(0.6 - vec2(dot(x3,x3), dot(x4,x4) ), 0.0);
619
+ m0 = m0 * m0;
620
+ m1 = m1 * m1;
621
+ return 49.0 * ( dot(m0*m0, vec3( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 )))
622
+ + dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ;
623
+ }
624
+
625
+ float SimplexNoise(vec3 v) {
626
+ const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
627
+ const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
628
+
629
+ // First corner
630
+ vec3 i = floor(v + dot(v, C.yyy) );
631
+ vec3 x0 = v - i + dot(i, C.xxx) ;
632
+
633
+ // Other corners
634
+ vec3 g = step(x0.yzx, x0.xyz);
635
+ vec3 l = 1.0 - g;
636
+ vec3 i1 = min( g.xyz, l.zxy );
637
+ vec3 i2 = max( g.xyz, l.zxy );
638
+
639
+ // x0 = x0 - 0.0 + 0.0 * C.xxx;
640
+ // x1 = x0 - i1 + 1.0 * C.xxx;
641
+ // x2 = x0 - i2 + 2.0 * C.xxx;
642
+ // x3 = x0 - 1.0 + 3.0 * C.xxx;
643
+ vec3 x1 = x0 - i1 + C.xxx;
644
+ vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
645
+ vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y
646
+
647
+ // Permutations
648
+ i = mod289(i);
649
+ vec4 p = permute( permute( permute(
650
+ i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
651
+ + i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
652
+ + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
653
+
654
+ // Gradients: 7x7 points over a square, mapped onto an octahedron.
655
+ // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
656
+ float n_ = 0.142857142857; // 1.0/7.0
657
+ vec3 ns = n_ * D.wyz - D.xzx;
658
+
659
+ vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)
660
+
661
+ vec4 x_ = floor(j * ns.z);
662
+ vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)
663
+
664
+ vec4 x = x_ *ns.x + ns.yyyy;
665
+ vec4 y = y_ *ns.x + ns.yyyy;
666
+ vec4 h = 1.0 - abs(x) - abs(y);
667
+
668
+ vec4 b0 = vec4( x.xy, y.xy );
669
+ vec4 b1 = vec4( x.zw, y.zw );
670
+
671
+ //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
672
+ //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
673
+ vec4 s0 = floor(b0)*2.0 + 1.0;
674
+ vec4 s1 = floor(b1)*2.0 + 1.0;
675
+ vec4 sh = -step(h, vec4(0.0));
676
+
677
+ vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
678
+ vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
679
+
680
+ vec3 p0 = vec3(a0.xy,h.x);
681
+ vec3 p1 = vec3(a0.zw,h.y);
682
+ vec3 p2 = vec3(a1.xy,h.z);
683
+ vec3 p3 = vec3(a1.zw,h.w);
684
+
685
+ // Normalise gradients
686
+ vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
687
+ p0 *= norm.x;
688
+ p1 *= norm.y;
689
+ p2 *= norm.z;
690
+ p3 *= norm.w;
691
+
692
+ // Mix final noise value
693
+ vec4 m = max(0.5 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
694
+ m = m * m;
695
+ return 105.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
696
+ dot(p2,x2), dot(p3,x3) ) );
697
+ }
698
+ `;
699
+ }
503
700
  export {
504
- generateUniformDeclarations,
701
+ generateSimplexNoiseFunction,
702
+ generateColorPaletteFunction,
505
703
  ReactShader
506
704
  };
@@ -0,0 +1,2 @@
1
+ export declare function generateColorPaletteFunction(name: string, paletteString: string): string;
2
+ //# sourceMappingURL=color-palette.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-palette.d.ts","sourceRoot":"","sources":["../../src/shaders/color-palette.ts"],"names":[],"mappings":"AAQA,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAgB/E"}
@@ -0,0 +1,2 @@
1
+ export declare function generateSimplexNoiseFunction(): string;
2
+ //# sourceMappingURL=simplex-noise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simplex-noise.d.ts","sourceRoot":"","sources":["../../src/shaders/simplex-noise.ts"],"names":[],"mappings":"AAWA,wBAAgB,4BAA4B,WAsL3C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fjandin/react-shader",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "React component for rendering WebGL shaders",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",