@paper-design/shaders 0.0.31-backbuffer-experiment.2 → 0.0.32

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 (68) hide show
  1. package/README.md +7 -4
  2. package/dist/index.d.ts +1 -1
  3. package/dist/shader-mount.d.ts +0 -9
  4. package/dist/shaders/dithering.d.ts +6 -6
  5. package/dist/shaders/dot-orbit.d.ts +0 -3
  6. package/dist/shaders/god-rays.d.ts +3 -6
  7. package/dist/shaders/grain-gradient.d.ts +0 -2
  8. package/dist/shaders/liquid-metal.d.ts +10 -25
  9. package/dist/shaders/metaballs.d.ts +0 -3
  10. package/dist/shaders/neuro-noise.d.ts +4 -10
  11. package/dist/shaders/perlin-noise.d.ts +8 -8
  12. package/dist/shaders/spiral.d.ts +6 -6
  13. package/dist/shaders/swirl.d.ts +0 -2
  14. package/dist/shaders/voronoi.d.ts +5 -5
  15. package/dist/shaders/waves.d.ts +6 -6
  16. package/package.json +2 -2
  17. package/dist/get-shader-color-from-string.js +0 -93
  18. package/dist/get-shader-color-from-string.js.map +0 -7
  19. package/dist/get-shader-noise-texture.js +0 -23
  20. package/dist/get-shader-noise-texture.js.map +0 -7
  21. package/dist/index.js +0 -109
  22. package/dist/index.js.map +0 -7
  23. package/dist/shader-color-spaces.js +0 -96
  24. package/dist/shader-color-spaces.js.map +0 -7
  25. package/dist/shader-mount.js +0 -733
  26. package/dist/shader-mount.js.map +0 -7
  27. package/dist/shader-sizing.js +0 -193
  28. package/dist/shader-sizing.js.map +0 -7
  29. package/dist/shader-utils.js +0 -59
  30. package/dist/shader-utils.js.map +0 -7
  31. package/dist/shaders/dithering.js +0 -221
  32. package/dist/shaders/dithering.js.map +0 -7
  33. package/dist/shaders/dot-grid.js +0 -107
  34. package/dist/shaders/dot-grid.js.map +0 -7
  35. package/dist/shaders/dot-orbit.js +0 -124
  36. package/dist/shaders/dot-orbit.js.map +0 -7
  37. package/dist/shaders/god-rays.js +0 -133
  38. package/dist/shaders/god-rays.js.map +0 -7
  39. package/dist/shaders/grain-gradient.js +0 -243
  40. package/dist/shaders/grain-gradient.js.map +0 -7
  41. package/dist/shaders/liquid-metal.js +0 -221
  42. package/dist/shaders/liquid-metal.js.map +0 -7
  43. package/dist/shaders/mesh-gradient.js +0 -97
  44. package/dist/shaders/mesh-gradient.js.map +0 -7
  45. package/dist/shaders/metaballs.js +0 -110
  46. package/dist/shaders/metaballs.js.map +0 -7
  47. package/dist/shaders/neuro-noise.js +0 -81
  48. package/dist/shaders/neuro-noise.js.map +0 -7
  49. package/dist/shaders/perlin-noise.js +0 -201
  50. package/dist/shaders/perlin-noise.js.map +0 -7
  51. package/dist/shaders/pulsing-border.js +0 -218
  52. package/dist/shaders/pulsing-border.js.map +0 -7
  53. package/dist/shaders/simplex-noise.js +0 -103
  54. package/dist/shaders/simplex-noise.js.map +0 -7
  55. package/dist/shaders/smoke-ring.js +0 -141
  56. package/dist/shaders/smoke-ring.js.map +0 -7
  57. package/dist/shaders/spiral.js +0 -83
  58. package/dist/shaders/spiral.js.map +0 -7
  59. package/dist/shaders/swirl.js +0 -91
  60. package/dist/shaders/swirl.js.map +0 -7
  61. package/dist/shaders/voronoi.js +0 -143
  62. package/dist/shaders/voronoi.js.map +0 -7
  63. package/dist/shaders/warp.js +0 -128
  64. package/dist/shaders/warp.js.map +0 -7
  65. package/dist/shaders/waves.js +0 -68
  66. package/dist/shaders/waves.js.map +0 -7
  67. package/dist/types.js +0 -6
  68. package/dist/types.js.map +0 -7
package/README.md CHANGED
@@ -13,10 +13,13 @@ myDiv.style.width = '600px';
13
13
  myDiv.style.height = '400px';
14
14
 
15
15
  const shaderParams = {
16
- u_color1: getShaderColorFromString("#283BFC"),
17
- u_color2: getShaderColorFromString("#FF2828"),
18
- u_color3: getShaderColorFromString("#dddddd"),
19
- u_color4: getShaderColorFromString("#800080")
16
+ u_colorsCount: 4,
17
+ u_colors: [
18
+ getShaderColorFromString("#283bfc"),
19
+ getShaderColorFromString("#ff2828"),
20
+ getShaderColorFromString("#dddddd"),
21
+ getShaderColorFromString("#800080")
22
+ ],
20
23
  };
21
24
 
22
25
  const speed = 0.25;
package/dist/index.d.ts CHANGED
@@ -36,7 +36,7 @@ export { ditheringFragmentShader, DitheringShapes, DitheringTypes, type Ditherin
36
36
  /** N-color gradient applied to the abstract shapes w/ grainy overlay & distortion */
37
37
  export { grainGradientFragmentShader, grainGradientMeta, GrainGradientShapes, type GrainGradientParams, type GrainGradientUniforms, type GrainGradientShape, } from './shaders/grain-gradient';
38
38
  /** Liquid metal effect applied to the abstract shapes */
39
- export { liquidMetalFragmentShader, LiquidMetalShapes, type LiquidMetalParams, type LiquidMetalUniforms, type LiquidMetalShape, } from './shaders/liquid-metal';
39
+ export { liquidMetalFragmentShader, type LiquidMetalParams, type LiquidMetalUniforms } from './shaders/liquid-metal';
40
40
  /** Border with configurable size & radius ade of rotating pulsing light spots */
41
41
  export { pulsingBorderMeta, pulsingBorderFragmentShader, type PulsingBorderParams, type PulsingBorderUniforms, } from './shaders/pulsing-border';
42
42
  export { getShaderColorFromString } from './get-shader-color-from-string';
@@ -25,12 +25,6 @@ export declare class ShaderMount {
25
25
  private minPixelRatio;
26
26
  private maxPixelCount;
27
27
  private isSafari;
28
- private framebuffer;
29
- private framebufferTexture;
30
- private framebufferWidth;
31
- private framebufferHeight;
32
- private framebufferSamplingProgram;
33
- private framebufferSamplingUniformLocations;
34
28
  constructor(
35
29
  /** The div you'd like to mount the shader to. The shader will match its size. */
36
30
  parentElement: HTMLElement, fragmentShader: string, uniforms: ShaderMountUniforms, webGlContextAttributes?: WebGLContextAttributes,
@@ -69,9 +63,6 @@ export declare class ShaderMount {
69
63
  private handleVisualViewportChange;
70
64
  /** Resize handler for when the container div changes size or the max pixel count changes and we want to resize our canvas to match */
71
65
  private handleResize;
72
- private getCanvasSize;
73
- private handleResolutionChange;
74
- private ensureSceneTarget;
75
66
  private render;
76
67
  private requestRender;
77
68
  /** Creates a texture from an image and sets it into a uniform value */
@@ -6,8 +6,8 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
6
6
  * abstract shapes animation (7 animated shapes available)
7
7
  *
8
8
  * Uniforms include:
9
- * - u_colorBack: background color, RGBA
10
- * - u_colorFront: pixels color, RGBA
9
+ * - u_color1: background color, RGBA
10
+ * - u_color2: pixels color, RGBA
11
11
  *
12
12
  * - u_shape (float, used as int, 1 to 7):
13
13
  * --- shape = 1: Simplex noise pattern
@@ -29,15 +29,15 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
29
29
  */
30
30
  export declare const ditheringFragmentShader: string;
31
31
  export interface DitheringUniforms extends ShaderSizingUniforms {
32
- u_colorBack: [number, number, number, number];
33
- u_colorFront: [number, number, number, number];
32
+ u_color1: [number, number, number, number];
33
+ u_color2: [number, number, number, number];
34
34
  u_shape: (typeof DitheringShapes)[DitheringShape];
35
35
  u_type: (typeof DitheringTypes)[DitheringType];
36
36
  u_pxSize: number;
37
37
  }
38
38
  export interface DitheringParams extends ShaderSizingParams, ShaderMotionParams {
39
- colorBack?: string;
40
- colorFront?: string;
39
+ color1?: string;
40
+ color2?: string;
41
41
  shape?: DitheringShape;
42
42
  type?: DitheringType;
43
43
  pxSize?: number;
@@ -10,7 +10,6 @@ export declare const dotOrbitMeta: {
10
10
  * Renders a dot pattern with dot placed in the center of each cell of animated Voronoi diagram
11
11
  *
12
12
  * Uniforms include:
13
- * - u_colorBack (vec4): the background color of the scene
14
13
  * - u_colors (vec4[]): Input RGBA colors
15
14
  * - u_colorsCount (float): Number of active colors (`u_colors` length)
16
15
  * - u_stepsPerColor (float): Discretization of the color transition
@@ -20,7 +19,6 @@ export declare const dotOrbitMeta: {
20
19
  */
21
20
  export declare const dotOrbitFragmentShader: string;
22
21
  export interface DotOrbitUniforms extends ShaderSizingUniforms {
23
- u_colorBack: [number, number, number, number];
24
22
  u_colors: vec4[];
25
23
  u_colorsCount: number;
26
24
  u_size: number;
@@ -29,7 +27,6 @@ export interface DotOrbitUniforms extends ShaderSizingUniforms {
29
27
  u_stepsPerColor: number;
30
28
  }
31
29
  export interface DotOrbitParams extends ShaderSizingParams, ShaderMotionParams {
32
- colorBack?: string;
33
30
  colors?: string[];
34
31
  size?: number;
35
32
  sizeRange?: number;
@@ -12,19 +12,17 @@ export declare const godRaysMeta: {
12
12
  * Uniforms include:
13
13
  *
14
14
  * - u_colorBack: background RGBA color
15
- * - u_colorBloom:
16
15
  * - uColors (vec4[]): Input RGBA colors
17
16
  * - u_frequency: the frequency of rays (the number of sectors)
18
17
  * - u_spotty: the density of spots in the rings (higher = more spots)
19
18
  * - u_midSize: the size of the central shape within the rings
20
19
  * - u_midIntensity: the influence of the central shape on the rings
21
20
  * - u_density (0 .. 1): the number of visible rays
22
- * - u_bloom (0 .. 1): normal / additive bloom
21
+ * - u_blending (0 .. 1): normal / additive blending
23
22
  */
24
23
  export declare const godRaysFragmentShader: string;
25
24
  export interface GodRaysUniforms extends ShaderSizingUniforms {
26
25
  u_colorBack: [number, number, number, number];
27
- u_colorBloom: [number, number, number, number];
28
26
  u_colors: vec4[];
29
27
  u_colorsCount: number;
30
28
  u_spotty: number;
@@ -32,16 +30,15 @@ export interface GodRaysUniforms extends ShaderSizingUniforms {
32
30
  u_midIntensity: number;
33
31
  u_frequency: number;
34
32
  u_density: number;
35
- u_bloom: number;
33
+ u_blending: number;
36
34
  }
37
35
  export interface GodRaysParams extends ShaderSizingParams, ShaderMotionParams {
38
36
  colorBack?: string;
39
- colorBloom?: string;
40
37
  colors?: string[];
41
38
  spotty?: number;
42
39
  midSize?: number;
43
40
  midIntensity?: number;
44
41
  frequency?: number;
45
42
  density?: number;
46
- bloom?: number;
43
+ blending?: number;
47
44
  }
@@ -9,7 +9,6 @@ export declare const grainGradientMeta: {
9
9
  */
10
10
  export declare const grainGradientFragmentShader: string;
11
11
  export interface GrainGradientUniforms extends ShaderSizingUniforms {
12
- u_colorBack: [number, number, number, number];
13
12
  u_colors: vec4[];
14
13
  u_colorsCount: number;
15
14
  u_softness: number;
@@ -18,7 +17,6 @@ export interface GrainGradientUniforms extends ShaderSizingUniforms {
18
17
  u_shape: (typeof GrainGradientShapes)[GrainGradientShape];
19
18
  }
20
19
  export interface GrainGradientParams extends ShaderSizingParams, ShaderMotionParams {
21
- colorBack?: string;
22
20
  colors?: string[];
23
21
  softness?: number;
24
22
  intensity?: number;
@@ -4,31 +4,16 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
4
4
  */
5
5
  export declare const liquidMetalFragmentShader: string;
6
6
  export interface LiquidMetalUniforms extends ShaderSizingUniforms {
7
- u_colorBack: [number, number, number, number];
8
- u_colorTint: [number, number, number, number];
9
- u_softness: number;
10
- u_repetition: number;
11
- u_shiftRed: number;
12
- u_shiftBlue: number;
13
- u_distortion: number;
14
- u_contour: number;
15
- u_shape: (typeof LiquidMetalShapes)[LiquidMetalShape];
7
+ u_patternBlur: number;
8
+ u_patternScale: number;
9
+ u_dispersion: number;
10
+ u_liquid: number;
11
+ u_shape: number;
16
12
  }
17
13
  export interface LiquidMetalParams extends ShaderSizingParams, ShaderMotionParams {
18
- colorBack?: string;
19
- colorTint?: string;
20
- softness?: number;
21
- repetition?: number;
22
- shiftRed?: number;
23
- shiftBlue?: number;
24
- distortion?: number;
25
- contour?: number;
26
- shape?: LiquidMetalShape;
14
+ patternBlur?: number;
15
+ patternScale?: number;
16
+ dispersion?: number;
17
+ liquid?: number;
18
+ shape?: number;
27
19
  }
28
- export declare const LiquidMetalShapes: {
29
- readonly none: 0;
30
- readonly circle: 1;
31
- readonly daisy: 2;
32
- readonly metaballs: 3;
33
- };
34
- export type LiquidMetalShape = keyof typeof LiquidMetalShapes;
@@ -10,7 +10,6 @@ export declare const metaballsMeta: {
10
10
  * The artwork by Ksenia Kondrashova
11
11
  *
12
12
  * Uniforms include:
13
- * - u_colorBack: the background color of the scene
14
13
  * - uColors (vec4[]): Input RGBA colors
15
14
  * - uColorsCount (float): Number of active colors (`uColors` length)
16
15
  * - u_count (float)
@@ -18,14 +17,12 @@ export declare const metaballsMeta: {
18
17
  */
19
18
  export declare const metaballsFragmentShader: string;
20
19
  export interface MetaballsUniforms extends ShaderSizingUniforms {
21
- u_colorBack: [number, number, number, number];
22
20
  u_colors: vec4[];
23
21
  u_colorsCount: number;
24
22
  u_count: number;
25
23
  u_size: number;
26
24
  }
27
25
  export interface MetaballsParams extends ShaderSizingParams, ShaderMotionParams {
28
- colorBack?: string;
29
26
  colors?: string[];
30
27
  count?: number;
31
28
  size?: number;
@@ -2,28 +2,22 @@ import type { ShaderMotionParams } from '../shader-mount';
2
2
  import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';
3
3
  /**
4
4
  * Neuro Noise Pattern
5
- * Original algo: https://x.com/zozuar/status/1625182758745128981/
5
+ * The original artwork: https://codepen.io/ksenia-k/full/vYwgrWv by Ksenia Kondrashova
6
6
  * Renders a fractal-like structure made of several layers of since-arches
7
7
  *
8
8
  * Uniforms include:
9
- * u_colorFront - the highlights (overexposed noise areas)
10
- * u_colorMid - the base color of pattern
11
- * u_colorBack - the backgrond color of pattern
12
- * u_brightness - increase/decrease the weight of strong lines
13
- * u_contrast - show/hide the weak pattern lines
9
+ * u_colorFront - the front color of pattern
10
+ * u_colorBack - the back color of pattern
11
+ * u_brightness - the power (brightness) of pattern lines
14
12
  */
15
13
  export declare const neuroNoiseFragmentShader: string;
16
14
  export interface NeuroNoiseUniforms extends ShaderSizingUniforms {
17
15
  u_colorFront: [number, number, number, number];
18
- u_colorMid: [number, number, number, number];
19
16
  u_colorBack: [number, number, number, number];
20
17
  u_brightness: number;
21
- u_contrast: number;
22
18
  }
23
19
  export interface NeuroNoiseParams extends ShaderSizingParams, ShaderMotionParams {
24
20
  colorFront?: string;
25
- colorMid?: string;
26
21
  colorBack?: string;
27
22
  brightness?: number;
28
- contrast?: number;
29
23
  }
@@ -5,10 +5,10 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
5
5
  * Based on https://www.shadertoy.com/view/NlSGDz
6
6
  *
7
7
  * Uniforms include:
8
- * u_colorFront - the first mixed color
9
- * u_colorBack - the second mixed color
10
- * u_proportion (0 .. 1) - the proportion between u_colorFront and u_colorBack;
11
- * u_softness - the sharpness of the transition between u_colorFront and u_colorBack in the noise output
8
+ * u_color1 - the first mixed color
9
+ * u_color2 - the second mixed color
10
+ * u_proportion (0 .. 1) - the proportion between u_color1 and u_color2;
11
+ * u_softness - the sharpness of the transition between u_color1 and u_color2 in the noise output
12
12
  * u_octaveCount - the number of octaves for Perlin noise;
13
13
  * higher values increase the complexity of the noise
14
14
  * u_persistence (0 .. 1) - the amplitude of each successive octave of the noise;
@@ -18,8 +18,8 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
18
18
  */
19
19
  export declare const perlinNoiseFragmentShader: string;
20
20
  export interface PerlinNoiseUniforms extends ShaderSizingUniforms {
21
- u_colorFront: [number, number, number, number];
22
- u_colorBack: [number, number, number, number];
21
+ u_color1: [number, number, number, number];
22
+ u_color2: [number, number, number, number];
23
23
  u_proportion: number;
24
24
  u_softness: number;
25
25
  u_octaveCount: number;
@@ -27,8 +27,8 @@ export interface PerlinNoiseUniforms extends ShaderSizingUniforms {
27
27
  u_lacunarity: number;
28
28
  }
29
29
  export interface PerlinNoiseParams extends ShaderSizingParams, ShaderMotionParams {
30
- colorFront?: string;
31
- colorBack?: string;
30
+ color1?: string;
31
+ color2?: string;
32
32
  proportion?: number;
33
33
  softness?: number;
34
34
  octaveCount?: number;
@@ -9,8 +9,8 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
9
9
  * u_scale - controls the overall scale of the spiral (u_scale = 1 makes it fit the viewport height)
10
10
  * u_offsetX - left / right pan
11
11
  * u_offsetY - up / down pan
12
- * u_colorBack - the first color used in the spiral (stroke)
13
- * u_colorFront - the second color used in the spiral (back)
12
+ * u_color1 - the first color used in the spiral (stroke)
13
+ * u_color2 - the second color used in the spiral (back)
14
14
  * u_density (0 .. 1) - the spacing of the spiral arms
15
15
  * u_distortion (0 .. 1) - adds a wavy distortion effect to the spiral arms
16
16
  * u_strokeWidth (0 .. 1) - defines the thickness of the spiral lines.
@@ -22,8 +22,8 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
22
22
  */
23
23
  export declare const spiralFragmentShader: string;
24
24
  export interface SpiralUniforms extends ShaderSizingUniforms {
25
- u_colorBack: [number, number, number, number];
26
- u_colorFront: [number, number, number, number];
25
+ u_color1: [number, number, number, number];
26
+ u_color2: [number, number, number, number];
27
27
  u_density: number;
28
28
  u_distortion: number;
29
29
  u_strokeWidth: number;
@@ -34,8 +34,8 @@ export interface SpiralUniforms extends ShaderSizingUniforms {
34
34
  u_softness: number;
35
35
  }
36
36
  export interface SpiralParams extends ShaderSizingParams, ShaderMotionParams {
37
- colorBack?: string;
38
- colorFront?: string;
37
+ color1?: string;
38
+ color2?: string;
39
39
  density?: number;
40
40
  distortion?: number;
41
41
  strokeWidth?: number;
@@ -8,7 +8,6 @@ export declare const swirlMeta: {
8
8
  */
9
9
  export declare const swirlFragmentShader: string;
10
10
  export interface SwirlUniforms extends ShaderSizingUniforms {
11
- u_colorBack: [number, number, number, number];
12
11
  u_colors: vec4[];
13
12
  u_colorsCount: number;
14
13
  u_bandCount: number;
@@ -18,7 +17,6 @@ export interface SwirlUniforms extends ShaderSizingUniforms {
18
17
  u_noisePower: number;
19
18
  }
20
19
  export interface SwirlParams extends ShaderSizingParams, ShaderMotionParams {
21
- colorBack?: string;
22
20
  colors?: string[];
23
21
  bandCount?: number;
24
22
  twist?: number;
@@ -17,7 +17,7 @@ export declare const voronoiMeta: {
17
17
  * - `u_colorGlow` (`vec4`): RGBA color for the radial shape on the cell edges
18
18
  * - `u_distortion` (`float`, 0 – 0.5): Controls how far cell centers can be displaced from the regular grid
19
19
  * - `u_gap` (`float`): Width of the gaps between cells (gaps can't be removed completely due to artifacts of Voronoi cells)
20
- * - `u_glow` (`float`): Controls the size of the radial glow inside each cell
20
+ * - `u_innerGlow` (`float`): Controls the size of the radial glow inside each cell
21
21
  * - `u_stepsPerColor` (`float`): Discretization of the color transition
22
22
  * - `u_noiseTexture` (`sampler2D`): Replacement of standard hash function, added for better performance
23
23
  */
@@ -26,19 +26,19 @@ export interface VoronoiUniforms extends ShaderSizingUniforms {
26
26
  u_colors: vec4[];
27
27
  u_colorsCount: number;
28
28
  u_stepsPerColor: number;
29
- u_colorGap: [number, number, number, number];
29
+ u_colorBack: [number, number, number, number];
30
30
  u_colorGlow: [number, number, number, number];
31
31
  u_distortion: number;
32
32
  u_gap: number;
33
- u_glow: number;
33
+ u_innerGlow: number;
34
34
  u_noiseTexture?: HTMLImageElement;
35
35
  }
36
36
  export interface VoronoiParams extends ShaderSizingParams, ShaderMotionParams {
37
37
  colors?: string[];
38
38
  stepsPerColor?: number;
39
- colorGap?: string;
39
+ colorBack?: string;
40
40
  colorGlow?: string;
41
41
  distortion?: number;
42
42
  gap?: number;
43
- glow?: number;
43
+ innerGlow?: number;
44
44
  }
@@ -3,8 +3,8 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
3
3
  * Waves static pattern on the transparent background
4
4
  *
5
5
  * Uniforms include:
6
- * u_colorFront - the first color
7
- * u_colorBack - the second color
6
+ * u_color1 - the first color
7
+ * u_color2 - the second color
8
8
  * u_shape (0 ... 3) - the line shaping coefficient, non-integer
9
9
  values allowed and produce mixed shapes
10
10
  - u_shape = 0 is zigzag
@@ -19,8 +19,8 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
19
19
  */
20
20
  export declare const wavesFragmentShader: string;
21
21
  export interface WavesUniforms extends ShaderSizingUniforms {
22
- u_colorFront: [number, number, number, number];
23
- u_colorBack: [number, number, number, number];
22
+ u_color1: [number, number, number, number];
23
+ u_color2: [number, number, number, number];
24
24
  u_shape: number;
25
25
  u_frequency: number;
26
26
  u_amplitude: number;
@@ -29,8 +29,8 @@ export interface WavesUniforms extends ShaderSizingUniforms {
29
29
  u_softness: number;
30
30
  }
31
31
  export interface WavesParams extends ShaderSizingParams {
32
- colorFront?: string;
33
- colorBack?: string;
32
+ color1?: string;
33
+ color2?: string;
34
34
  rotation?: number;
35
35
  shape?: number;
36
36
  frequency?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paper-design/shaders",
3
- "version": "0.0.31-backbuffer-experiment.2",
3
+ "version": "0.0.32",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -24,4 +24,4 @@
24
24
  "type-check": "tsc --project tsconfig.json"
25
25
  },
26
26
  "dependencies": {}
27
- }
27
+ }
@@ -1,93 +0,0 @@
1
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
- * Paper Shaders *
3
- * https://github.com/paper-design/shaders *
4
- * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
-
6
- function getShaderColorFromString(colorString) {
7
- if (Array.isArray(colorString)) {
8
- if (colorString.length === 4) return colorString;
9
- if (colorString.length === 3) return [...colorString, 1];
10
- return fallbackColor;
11
- }
12
- if (typeof colorString !== "string") {
13
- return fallbackColor;
14
- }
15
- let r, g, b, a = 1;
16
- if (colorString.startsWith("#")) {
17
- [r, g, b, a] = hexToRgba(colorString);
18
- } else if (colorString.startsWith("rgb")) {
19
- [r, g, b, a] = parseRgba(colorString);
20
- } else if (colorString.startsWith("hsl")) {
21
- [r, g, b, a] = hslaToRgba(parseHsla(colorString));
22
- } else {
23
- console.error("Unsupported color format", colorString);
24
- return fallbackColor;
25
- }
26
- return [clamp(r, 0, 1), clamp(g, 0, 1), clamp(b, 0, 1), clamp(a, 0, 1)];
27
- }
28
- function hexToRgba(hex) {
29
- hex = hex.replace(/^#/, "");
30
- if (hex.length === 3) {
31
- hex = hex.split("").map((char) => char + char).join("");
32
- }
33
- if (hex.length === 6) {
34
- hex = hex + "ff";
35
- }
36
- const r = parseInt(hex.slice(0, 2), 16) / 255;
37
- const g = parseInt(hex.slice(2, 4), 16) / 255;
38
- const b = parseInt(hex.slice(4, 6), 16) / 255;
39
- const a = parseInt(hex.slice(6, 8), 16) / 255;
40
- return [r, g, b, a];
41
- }
42
- function parseRgba(rgba) {
43
- const match = rgba.match(/^rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([0-9.]+))?\s*\)$/i);
44
- if (!match) return [0, 0, 0, 1];
45
- return [
46
- parseInt(match[1] ?? "0") / 255,
47
- parseInt(match[2] ?? "0") / 255,
48
- parseInt(match[3] ?? "0") / 255,
49
- match[4] === void 0 ? 1 : parseFloat(match[4])
50
- ];
51
- }
52
- function parseHsla(hsla) {
53
- const match = hsla.match(/^hsla?\s*\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(?:,\s*([0-9.]+))?\s*\)$/i);
54
- if (!match) return [0, 0, 0, 1];
55
- return [
56
- parseInt(match[1] ?? "0"),
57
- parseInt(match[2] ?? "0"),
58
- parseInt(match[3] ?? "0"),
59
- match[4] === void 0 ? 1 : parseFloat(match[4])
60
- ];
61
- }
62
- function hslaToRgba(hsla) {
63
- const [h, s, l, a] = hsla;
64
- const hDecimal = h / 360;
65
- const sDecimal = s / 100;
66
- const lDecimal = l / 100;
67
- let r, g, b;
68
- if (s === 0) {
69
- r = g = b = lDecimal;
70
- } else {
71
- const hue2rgb = (p2, q2, t) => {
72
- if (t < 0) t += 1;
73
- if (t > 1) t -= 1;
74
- if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t;
75
- if (t < 1 / 2) return q2;
76
- if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6;
77
- return p2;
78
- };
79
- const q = lDecimal < 0.5 ? lDecimal * (1 + sDecimal) : lDecimal + sDecimal - lDecimal * sDecimal;
80
- const p = 2 * lDecimal - q;
81
- r = hue2rgb(p, q, hDecimal + 1 / 3);
82
- g = hue2rgb(p, q, hDecimal);
83
- b = hue2rgb(p, q, hDecimal - 1 / 3);
84
- }
85
- return [r, g, b, a];
86
- }
87
- const clamp = (n, min, max) => Math.min(Math.max(n, min), max);
88
- const fallbackColor = [0, 0, 0, 1];
89
- export {
90
- clamp,
91
- getShaderColorFromString
92
- };
93
- //# sourceMappingURL=get-shader-color-from-string.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/get-shader-color-from-string.ts"],
4
- "sourcesContent": ["/** Convert color string from HSL, RGB, or hex to 0-to-1-range-RGBA array */\nexport function getShaderColorFromString(\n colorString: string | [number, number, number] | [number, number, number, number] | undefined\n): [number, number, number, number] {\n // If the color string is already an array of 3 or 4 numbers, return it (with alpha=1 if needed)\n if (Array.isArray(colorString)) {\n if (colorString.length === 4) return colorString as [number, number, number, number];\n if (colorString.length === 3) return [...colorString, 1];\n return fallbackColor;\n }\n\n // If the color string is not a string, return the fallback\n if (typeof colorString !== 'string') {\n return fallbackColor;\n }\n\n let r: number,\n g: number,\n b: number,\n a = 1;\n if (colorString.startsWith('#')) {\n [r, g, b, a] = hexToRgba(colorString);\n } else if (colorString.startsWith('rgb')) {\n [r, g, b, a] = parseRgba(colorString);\n } else if (colorString.startsWith('hsl')) {\n [r, g, b, a] = hslaToRgba(parseHsla(colorString));\n } else {\n console.error('Unsupported color format', colorString);\n return fallbackColor;\n }\n\n return [clamp(r, 0, 1), clamp(g, 0, 1), clamp(b, 0, 1), clamp(a, 0, 1)];\n}\n\n/** Convert hex to RGBA (0 to 1 range) */\nfunction hexToRgba(hex: string): [number, number, number, number] {\n // Remove # if present\n hex = hex.replace(/^#/, '');\n\n // Expand three-letter hex to six-letter\n if (hex.length === 3) {\n hex = hex\n .split('')\n .map((char) => char + char)\n .join('');\n }\n // Expand six-letter hex to eight-letter (add full opacity if no alpha)\n if (hex.length === 6) {\n hex = hex + 'ff';\n }\n\n // Parse the components\n const r = parseInt(hex.slice(0, 2), 16) / 255;\n const g = parseInt(hex.slice(2, 4), 16) / 255;\n const b = parseInt(hex.slice(4, 6), 16) / 255;\n const a = parseInt(hex.slice(6, 8), 16) / 255;\n\n return [r, g, b, a];\n}\n\n/** Parse RGBA string to RGBA (0 to 1 range) */\nfunction parseRgba(rgba: string): [number, number, number, number] {\n // Match both rgb and rgba patterns\n const match = rgba.match(/^rgba?\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*([0-9.]+))?\\s*\\)$/i);\n if (!match) return [0, 0, 0, 1];\n\n return [\n parseInt(match[1] ?? '0') / 255,\n parseInt(match[2] ?? '0') / 255,\n parseInt(match[3] ?? '0') / 255,\n match[4] === undefined ? 1 : parseFloat(match[4]),\n ];\n}\n\n/** Parse HSLA string */\nfunction parseHsla(hsla: string): [number, number, number, number] {\n const match = hsla.match(/^hsla?\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)%\\s*,\\s*(\\d+)%\\s*(?:,\\s*([0-9.]+))?\\s*\\)$/i);\n if (!match) return [0, 0, 0, 1];\n\n return [\n parseInt(match[1] ?? '0'),\n parseInt(match[2] ?? '0'),\n parseInt(match[3] ?? '0'),\n match[4] === undefined ? 1 : parseFloat(match[4]),\n ];\n}\n\n/** Convert HSLA to RGBA (0 to 1 range) */\nfunction hslaToRgba(hsla: [number, number, number, number]): [number, number, number, number] {\n const [h, s, l, a] = hsla;\n const hDecimal = h / 360;\n const sDecimal = s / 100;\n const lDecimal = l / 100;\n let r, g, b;\n\n if (s === 0) {\n r = g = b = lDecimal; // achromatic\n } else {\n const hue2rgb = (p: number, q: number, t: number) => {\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n };\n\n const q = lDecimal < 0.5 ? lDecimal * (1 + sDecimal) : lDecimal + sDecimal - lDecimal * sDecimal;\n const p = 2 * lDecimal - q;\n r = hue2rgb(p, q, hDecimal + 1 / 3);\n g = hue2rgb(p, q, hDecimal);\n b = hue2rgb(p, q, hDecimal - 1 / 3);\n }\n\n return [r, g, b, a];\n}\n\nexport const clamp = (n: number, min: number, max: number): number => Math.min(Math.max(n, min), max);\n\nconst fallbackColor = [0, 0, 0, 1] as [0, 0, 0, 1];\n"],
5
- "mappings": "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",
6
- "names": ["p", "q"]
7
- }