micugl 0.0.4 → 0.0.8

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 (69) hide show
  1. package/README.md +98 -1
  2. package/dist/MarbleScene.d.ts +27 -0
  3. package/dist/RippleScene.d.ts +20 -0
  4. package/dist/examples/Marble/MarbleScene.d.ts +20 -0
  5. package/dist/examples/Marble/MarbleScene.js +1 -0
  6. package/dist/examples/Marble/MarbleScene.mjs +71 -0
  7. package/dist/examples/Marble/marbleShaders.d.ts +2 -0
  8. package/dist/{MarbleScene-B1gMFEHc.js → examples/Marble/marbleShaders.js} +3 -3
  9. package/dist/{MarbleScene-DmZt4s6L.mjs → examples/Marble/marbleShaders.mjs} +5 -70
  10. package/dist/examples/Ripple/RippleScene.d.ts +13 -0
  11. package/dist/examples/Ripple/RippleScene.js +1 -0
  12. package/dist/examples/Ripple/RippleScene.mjs +109 -0
  13. package/dist/examples/Ripple/rippleShaders.d.ts +3 -0
  14. package/dist/examples/Ripple/rippleShaders.js +80 -0
  15. package/dist/examples/Ripple/rippleShaders.mjs +94 -0
  16. package/dist/examples/index.d.ts +4 -4
  17. package/dist/examples/index.js +1 -1
  18. package/dist/examples/index.mjs +9 -7
  19. package/dist/index.d.ts +35 -9
  20. package/dist/index.js +1 -1
  21. package/dist/index.mjs +35 -146
  22. package/dist/marbleShaders.d.ts +5 -0
  23. package/dist/rippleShaders.d.ts +7 -0
  24. package/dist/src/core/lib/createShaderConfig.js +1 -0
  25. package/dist/src/core/lib/createShaderConfig.mjs +34 -0
  26. package/dist/src/core/lib/vectorUtils.js +1 -0
  27. package/dist/src/core/lib/vectorUtils.mjs +36 -0
  28. package/dist/src/core/managers/FBOManager.js +1 -0
  29. package/dist/src/core/managers/FBOManager.mjs +120 -0
  30. package/dist/src/core/managers/WebGLManager.js +1 -0
  31. package/dist/src/core/managers/WebGLManager.mjs +273 -0
  32. package/dist/src/core/systems/Passes.js +1 -0
  33. package/dist/src/core/systems/Passes.mjs +78 -0
  34. package/dist/src/core/systems/Postprocessing.js +1 -0
  35. package/dist/src/core/systems/Postprocessing.mjs +128 -0
  36. package/dist/src/react/components/base/BasePingPongShaderComponent.js +1 -0
  37. package/dist/src/react/components/base/BasePingPongShaderComponent.mjs +48 -0
  38. package/dist/src/react/components/base/BaseShaderComponent.js +1 -0
  39. package/dist/src/react/components/base/BaseShaderComponent.mjs +34 -0
  40. package/dist/src/react/components/engine/PingPongShaderEngine.js +1 -0
  41. package/dist/src/react/components/engine/PingPongShaderEngine.mjs +68 -0
  42. package/dist/src/react/components/engine/ShaderEngine.js +1 -0
  43. package/dist/src/react/components/engine/ShaderEngine.mjs +106 -0
  44. package/dist/src/react/hooks/useDarkMode.js +1 -0
  45. package/dist/src/react/hooks/useDarkMode.mjs +22 -0
  46. package/dist/src/react/hooks/usePingPongPasses.js +1 -0
  47. package/dist/src/react/hooks/usePingPongPasses.mjs +93 -0
  48. package/dist/src/react/hooks/useUniformUpdaters.js +1 -0
  49. package/dist/src/react/hooks/useUniformUpdaters.mjs +12 -0
  50. package/dist/src/react/lib/createUniformUpdater.js +1 -0
  51. package/dist/src/react/lib/createUniformUpdater.mjs +28 -0
  52. package/dist/types.d.ts +204 -0
  53. package/dist/types.js +1 -0
  54. package/dist/types.mjs +1 -0
  55. package/package.json +46 -10
  56. package/dist/BasePingPongShaderComponent-BvRm7-g5.js +0 -1
  57. package/dist/BasePingPongShaderComponent-FY62Kl02.mjs +0 -273
  58. package/dist/BaseShaderComponent-BSBIvn4B.js +0 -1
  59. package/dist/BaseShaderComponent-Be_evz2F.mjs +0 -151
  60. package/dist/SimpleRippleScene--B1BrlxP.js +0 -80
  61. package/dist/SimpleRippleScene-Ba-EPdTJ.mjs +0 -197
  62. package/dist/examples/Marble/index.d.ts +0 -3
  63. package/dist/examples/Marble/index.js +0 -1
  64. package/dist/examples/Marble/index.mjs +0 -6
  65. package/dist/examples/SimpleRipple/index.d.ts +0 -3
  66. package/dist/examples/SimpleRipple/index.js +0 -1
  67. package/dist/examples/SimpleRipple/index.mjs +0 -7
  68. package/dist/useUniformUpdaters-D5WtqZpp.mjs +0 -456
  69. package/dist/useUniformUpdaters-DGX0mf9g.js +0 -1
package/README.md CHANGED
@@ -1,3 +1,100 @@
1
1
  # micugl
2
2
 
3
- Lightweight React shader library
3
+ miccull's shader library for simple React shaders.
4
+
5
+ Includes a WebGL manager, core utilities, and two React components for single‑pass and ping‑pong shaders.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install micugl
11
+ # or
12
+ bun add micugl
13
+ ```
14
+
15
+ ## Getting Started
16
+
17
+ ```tsx
18
+ import React from "react";
19
+ import { BaseShaderComponent, createShaderConfig } from "micugl";
20
+
21
+ import vertexShader from "./shaders.vert";
22
+ import fragmentShader from "./shaders.frag";
23
+
24
+ const shaderConfig = createShaderConfig({
25
+ vertexShader,
26
+ fragmentShader,
27
+ uniformNames: {
28
+ u_myColor: "vec3",
29
+ },
30
+ });
31
+
32
+ export default function App() {
33
+ return (
34
+ <BaseShaderComponent
35
+ programId="my-shader"
36
+ shaderConfig={shaderConfig}
37
+ uniforms={{
38
+ time: { type: "float", value: (t) => t * 0.001 },
39
+ resolution: {
40
+ type: "vec2",
41
+ value: () => [window.innerWidth, window.innerHeight],
42
+ },
43
+ myColor: { type: "vec3", value: [1, 0, 0] },
44
+ }}
45
+ style={{ width: "100vw", height: "100vh" }}
46
+ />
47
+ );
48
+ }
49
+ ```
50
+
51
+ ## Core
52
+
53
+ - **WebGLManager**
54
+ Low‑level wrapper around WebGLRenderingContext.
55
+
56
+ - `new WebGLManager(canvas, options?)`
57
+ - `createProgram(id, config)` → compile/link shaders
58
+ - `createBuffer(programId, attribute, data)`
59
+ - `setUniform(programId, name, value, type)`
60
+ - `prepareRender(programId, { clear?, clearColor? })`
61
+ - `drawArrays(...)`, `drawElements(...)`
62
+ - `fbo: FBOManager` for ping‑pong framebuffers
63
+
64
+ - **`createShaderConfig`**
65
+ - Builds a ShaderProgramConfig with defaults (`u_time`, `u_resolution`).
66
+ - `createShaderConfig({ vertexShader, fragmentShader, uniformNames?, attributeConfigs? })`
67
+
68
+ - **Utilities**
69
+ - `FBOManager` for multi‑render targets
70
+ - `Passes` / `Postprocessing` to sequence render passes
71
+
72
+ ## React Components
73
+
74
+ ### BaseShaderComponent
75
+
76
+ | Prop | Type | Notes |
77
+ | ------------------- | ------------------------------------------- | ----------------------------- |
78
+ | programId | string | identifier for the shader |
79
+ | shaderConfig | ShaderProgramConfig | from createShaderConfig |
80
+ | uniforms | { [name]: { type: UniformType; value } } | static value or updater fn |
81
+ | renderOptions | { clear?: boolean; clearColor?: [r,g,b,a] } | default clears to black |
82
+ | useFastPath | boolean | skip callback for simple draw |
83
+ | useDevicePixelRatio | boolean | adapt canvas to DPR |
84
+
85
+ ### BasePingPongShaderComponent
86
+
87
+ | Prop | Type | Notes |
88
+ | --------------------- | ----------------------------------------------- | ----------------------------------- |
89
+ | programId | string | first‑pass shader |
90
+ | secondaryShaderConfig | ShaderProgramConfig | ping‑pong second pass |
91
+ | iterations | number (default 1) | update/display cycles |
92
+ | uniforms | { [name]: { type; value } } | for primary pass |
93
+ | secondaryUniforms | { [name]: { type; value } } | for secondary pass |
94
+ | framebufferOptions | { width; height; textureCount; textureOptions } | default full‑canvas two‑texture FBO |
95
+
96
+ ### Hooks
97
+
98
+ - **useUniformUpdaters(programId, uniforms)** → React memoized uniform updaters
99
+ - **usePingPongPasses(options)** → { passes, framebuffers } for engine
100
+ - **useDarkMode()** → boolean dark‑mode flag
@@ -0,0 +1,27 @@
1
+ import { CSSProperties } from 'react';
2
+ import { JSX } from 'react/jsx-runtime';
3
+
4
+ declare const Marble: ({ marbleScale, tileScale, turbulence, swirl, veinFrequency, veinWidth, colorStart, colorEnd, veinColor, colorStartDark, colorEndDark, veinColorDark, className, style }: MarbleProps) => JSX.Element;
5
+ export { Marble }
6
+ export default Marble;
7
+
8
+ export declare interface MarbleProps {
9
+ marbleScale?: number;
10
+ tileScale?: number;
11
+ turbulence?: number;
12
+ swirl?: number;
13
+ colorStart?: Vec3;
14
+ colorEnd?: Vec3;
15
+ veinColor?: Vec3;
16
+ colorStartDark?: Vec3;
17
+ colorEndDark?: Vec3;
18
+ veinColorDark?: Vec3;
19
+ veinFrequency?: number;
20
+ veinWidth?: number;
21
+ className?: string;
22
+ style?: CSSProperties;
23
+ }
24
+
25
+ declare type Vec3 = [number, number, number];
26
+
27
+ export { }
@@ -0,0 +1,20 @@
1
+ import { CSSProperties } from 'react';
2
+ import { JSX } from 'react/jsx-runtime';
3
+
4
+ declare const Ripple: ({ damping, mouseForce, color1, color2, iterations, className, style }: RippleProps) => JSX.Element;
5
+ export { Ripple }
6
+ export default Ripple;
7
+
8
+ export declare interface RippleProps {
9
+ damping?: number;
10
+ mouseForce?: number;
11
+ color1?: Vec3;
12
+ color2?: Vec3;
13
+ iterations?: number;
14
+ className?: string;
15
+ style?: CSSProperties;
16
+ }
17
+
18
+ declare type Vec3 = [number, number, number];
19
+
20
+ export { }
@@ -0,0 +1,20 @@
1
+ import { CSSProperties } from 'react';
2
+ type Vec3 = [number, number, number];
3
+ export interface MarbleProps {
4
+ marbleScale?: number;
5
+ tileScale?: number;
6
+ turbulence?: number;
7
+ swirl?: number;
8
+ colorStart?: Vec3;
9
+ colorEnd?: Vec3;
10
+ veinColor?: Vec3;
11
+ colorStartDark?: Vec3;
12
+ colorEndDark?: Vec3;
13
+ veinColorDark?: Vec3;
14
+ veinFrequency?: number;
15
+ veinWidth?: number;
16
+ className?: string;
17
+ style?: CSSProperties;
18
+ }
19
+ export declare const Marble: ({ marbleScale, tileScale, turbulence, swirl, veinFrequency, veinWidth, colorStart, colorEnd, veinColor, colorStartDark, colorEndDark, veinColorDark, className, style }: MarbleProps) => import("react/jsx-runtime").JSX.Element;
20
+ export default Marble;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("react/jsx-runtime"),C=require("../../src/core/lib/createShaderConfig.js"),r=require("../../src/core/lib/vectorUtils.js"),O=require("../../src/react/components/base/BaseShaderComponent.js"),y=require("../../src/react/hooks/useDarkMode.js"),t=require("./marbleShaders.js"),R=[.8,.8,.9],g=[.3,.3,.6],q=[.1,.1,.3],D=[.2,.2,.3],M=[.1,.1,.2],E=[.05,.05,.1],a=({marbleScale:o=3,tileScale:l=1,turbulence:u=.5,swirl:n=6,veinFrequency:c=6,veinWidth:s=2,colorStart:i=R,colorEnd:v=g,veinColor:d=q,colorStartDark:_=D,colorEndDark:f=M,veinColorDark:S=E,className:m="",style:p})=>{const e=y.useDarkMode(),b=C.createShaderConfig({vertexShader:t.marbleVertexShader,fragmentShader:t.marbleFragmentShader,uniformNames:{u_marbleScale:"float",u_tileScale:"float",u_turbulence:"float",u_swirl:"float",u_colorStart:"vec3",u_colorEnd:"vec3",u_veinColor:"vec3",u_veinFrequency:"float",u_veinWidth:"float"}});return h.jsx(O.BaseShaderComponent,{programId:"marble-shader",shaderConfig:b,className:m,style:p,uniforms:{marbleScale:{value:o,type:"float"},tileScale:{value:l,type:"float"},turbulence:{value:u,type:"float"},swirl:{value:n,type:"float"},veinFrequency:{value:c,type:"float"},veinWidth:{value:s,type:"float"},colorStart:{type:"vec3",value:r.vec3(e?_:i)},colorEnd:{type:"vec3",value:r.vec3(e?f:v)},veinColor:{type:"vec3",value:r.vec3(e?S:d)}}})};exports.Marble=a;exports.default=a;
@@ -0,0 +1,71 @@
1
+ import { jsx as S } from "react/jsx-runtime";
2
+ import { createShaderConfig as O } from "../../src/core/lib/createShaderConfig.mjs";
3
+ import { vec3 as o } from "../../src/core/lib/vectorUtils.mjs";
4
+ import { BaseShaderComponent as y } from "../../src/react/components/base/BaseShaderComponent.mjs";
5
+ import { useDarkMode as C } from "../../src/react/hooks/useDarkMode.mjs";
6
+ import { marbleVertexShader as R, marbleFragmentShader as h } from "./marbleShaders.mjs";
7
+ const b = [0.8, 0.8, 0.9], D = [0.3, 0.3, 0.6], E = [0.1, 0.1, 0.3], L = [0.2, 0.2, 0.3], g = [0.1, 0.1, 0.2], A = [0.05, 0.05, 0.1], M = ({
8
+ marbleScale: t = 3,
9
+ tileScale: r = 1,
10
+ turbulence: a = 0.5,
11
+ swirl: l = 6,
12
+ veinFrequency: n = 6,
13
+ veinWidth: c = 2,
14
+ colorStart: u = b,
15
+ colorEnd: f = D,
16
+ veinColor: m = E,
17
+ colorStartDark: i = L,
18
+ colorEndDark: v = g,
19
+ veinColorDark: s = A,
20
+ className: p = "",
21
+ style: _
22
+ }) => {
23
+ const e = C(), d = O({
24
+ vertexShader: R,
25
+ fragmentShader: h,
26
+ uniformNames: {
27
+ u_marbleScale: "float",
28
+ u_tileScale: "float",
29
+ u_turbulence: "float",
30
+ u_swirl: "float",
31
+ u_colorStart: "vec3",
32
+ u_colorEnd: "vec3",
33
+ u_veinColor: "vec3",
34
+ u_veinFrequency: "float",
35
+ u_veinWidth: "float"
36
+ }
37
+ });
38
+ return /* @__PURE__ */ S(
39
+ y,
40
+ {
41
+ programId: "marble-shader",
42
+ shaderConfig: d,
43
+ className: p,
44
+ style: _,
45
+ uniforms: {
46
+ marbleScale: { value: t, type: "float" },
47
+ tileScale: { value: r, type: "float" },
48
+ turbulence: { value: a, type: "float" },
49
+ swirl: { value: l, type: "float" },
50
+ veinFrequency: { value: n, type: "float" },
51
+ veinWidth: { value: c, type: "float" },
52
+ colorStart: {
53
+ type: "vec3",
54
+ value: o(e ? i : u)
55
+ },
56
+ colorEnd: {
57
+ type: "vec3",
58
+ value: o(e ? v : f)
59
+ },
60
+ veinColor: {
61
+ type: "vec3",
62
+ value: o(e ? s : m)
63
+ }
64
+ }
65
+ }
66
+ );
67
+ };
68
+ export {
69
+ M as Marble,
70
+ M as default
71
+ };
@@ -0,0 +1,2 @@
1
+ export declare const marbleVertexShader = "\n attribute vec2 a_position;\n varying vec2 v_texCoord;\n\n void main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n v_texCoord = a_position * 0.5 + 0.5;\n }\n";
2
+ export declare const marbleFragmentShader = "\nprecision highp float;\n \nuniform vec2 u_resolution;\nuniform float u_time;\nuniform float u_marbleScale;\nuniform float u_turbulence;\nuniform float u_swirl;\nuniform vec3 u_colorStart;\nuniform vec3 u_colorEnd;\nuniform vec3 u_veinColor;\nuniform float u_veinFrequency;\nuniform float u_veinWidth;\nuniform float u_tileScale;\n \nvarying vec2 v_texCoord;\n \nfloat hash(float n) {\n return fract(sin(n) * 43758.5453123);\n}\n \nfloat hash(vec2 p) {\n return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453123);\n}\n \nfloat noise(vec2 x) {\n vec2 i = floor(x);\n vec2 f = fract(x);\n \n float a = hash(i);\n float b = hash(i + vec2(1.0, 0.0));\n float c = hash(i + vec2(0.0, 1.0));\n float d = hash(i + vec2(1.0, 1.0));\n \n vec2 u = f * f * (3.0 - 2.0 * f);\n \n return clamp(mix(mix(a, b, u.x), mix(c, d, u.x), u.y), 0.0, 1.0);\n}\n \nfloat fbm(vec2 p, int octaves) {\n float value = 0.0;\n float amplitude = 0.5;\n float frequency = 1.0;\n float maxValue = 0.0;\n \n for (int i = 0; i < 10; i++) {\n if (i >= octaves) break;\n value += amplitude * noise(p * frequency);\n maxValue += amplitude;\n frequency *= 2.0;\n amplitude *= 0.5;\n }\n \n return value / maxValue;\n}\n \nvec2 swirl(vec2 p, float strength) {\n float theta = fbm(p, 3) * strength;\n float c = cos(theta);\n float s = sin(theta);\n return vec2(\n p.x * c - p.y * s,\n p.x * s + p.y * c\n );\n}\n\nvec2 applyTilePixelation(vec2 uv, float tileScale) {\n vec2 cell = floor(uv * tileScale);\n float cellHash = (1.3 * fbm(u_time * 0.00002 * vec2(pow(pow(cell.x * cell.y, 2.0), 0.5), 2.0) + cell, 1) + 0.8 * hash(cell)) * 0.5;\n float hashValue = cellHash * 3.0;\n float pixelSize = 1.0;\n\n if (hashValue < 1.0) pixelSize = 32.0;\n else if (hashValue < 1.3) pixelSize = 16.0;\n else if (hashValue < 1.8) pixelSize = 64.0;\n else if (hashValue < 1.85) pixelSize = 16.0;\n else if (hashValue < 2.2) pixelSize = 64.0;\n else if (hashValue < 2.3) pixelSize = 16.0;\n else if (hashValue < 2.6) pixelSize = 32.0;\n else pixelSize = 128.0;\n\n return floor(uv * pixelSize) / pixelSize;\n}\n \nvoid main() {\n vec2 uv = v_texCoord * 2.0 - 1.0;\n uv = uv * u_resolution / min(u_resolution.x, u_resolution.y);\n \n vec2 pixelatedUv = applyTilePixelation(uv, u_tileScale);\n \n float time = u_time * 0.25;\n \n vec2 swirlUv = swirl(pixelatedUv + vec2(time * 0.0005, time * 0.00083), max(0.0, min(10.0, u_swirl)));\n \n float baseNoise = fbm(swirlUv * max(0.1, u_marbleScale) + vec2(time * 0.1, time * 0.13), 5);\n \n float turbulenceAmount = max(0.0, min(1.0, u_turbulence));\n float turbulence = turbulenceAmount * fbm(swirlUv * max(0.1, u_marbleScale) * 2.0 + vec2(time * -0.15), 2);\n baseNoise = clamp(baseNoise + turbulence, 0.0, 1.0);\n \n float veinFreq = max(0.1, u_veinFrequency);\n float veinW = max(0.1, min(5.0, u_veinWidth));\n float veins = abs(sin(baseNoise * veinFreq * 3.14159));\n veins = pow(veins, veinW);\n veins = clamp(veins, 0.0, 1.0);\n \n vec3 baseColor = mix(u_colorStart, u_colorEnd, baseNoise);\n \n vec3 marbleColor = mix(baseColor, u_veinColor, veins);\n \n float highlight = pow(fbm(swirlUv * max(0.1, u_marbleScale) * 4.0, 2), 3.0) * 0.2;\n \n marbleColor = floor(marbleColor * 32.0) / 32.0;\n marbleColor = mix(marbleColor, u_veinColor, veins * 0.5);\n marbleColor = marbleColor + 0.0425;\n marbleColor = clamp(marbleColor, 0.0, 1.0);\n\n marbleColor = mix(marbleColor, u_veinColor, 0.7);\n gl_FragColor = vec4(marbleColor, 1.0);\n}\n";
@@ -1,4 +1,4 @@
1
- "use strict";const C=require("react/jsx-runtime"),y=require("./useUniformUpdaters-DGX0mf9g.js"),a=require("./BaseShaderComponent-BSBIvn4B.js"),o=`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=`
2
2
  attribute vec2 a_position;
3
3
  varying vec2 v_texCoord;
4
4
 
@@ -6,7 +6,7 @@
6
6
  gl_Position = vec4(a_position, 0.0, 1.0);
7
7
  v_texCoord = a_position * 0.5 + 0.5;
8
8
  }
9
- `,i=`
9
+ `,l=`
10
10
  precision highp float;
11
11
 
12
12
  uniform vec2 u_resolution;
@@ -126,4 +126,4 @@ void main() {
126
126
  marbleColor = mix(marbleColor, u_veinColor, 0.7);
127
127
  gl_FragColor = vec4(marbleColor, 1.0);
128
128
  }
129
- `,g=[.8,.8,.9],w=[.3,.3,.6],V=[.1,.1,.3],q=[.2,.2,.3],O=[.1,.1,.2],R=[.05,.05,.1],z=({marbleScale:t=3,tileScale:r=1,turbulence:u=.5,swirl:n=6,veinFrequency:c=6,veinWidth:s=2,colorStart:v=g,colorEnd:f=w,veinColor:m=V,colorStartDark:h=q,colorEndDark:p=O,veinColorDark:_=R,className:b="",style:x})=>{const e=a.useDarkMode(),l=S=>()=>new Float32Array(S),d=y.createShaderConfig({vertexShader:o,fragmentShader:i,uniformNames:{u_marbleScale:"float",u_tileScale:"float",u_turbulence:"float",u_swirl:"float",u_colorStart:"vec3",u_colorEnd:"vec3",u_veinColor:"vec3",u_veinFrequency:"float",u_veinWidth:"float"}});return C.jsx(a.BaseShaderComponent,{programId:"marble-shader",shaderConfig:d,className:b,style:x,uniforms:{marbleScale:{value:t,type:"float"},tileScale:{value:r,type:"float"},turbulence:{value:u,type:"float"},swirl:{value:n,type:"float"},veinFrequency:{value:c,type:"float"},veinWidth:{value:s,type:"float"},colorStart:{type:"vec3",value:l(e?h:v)},colorEnd:{type:"vec3",value:l(e?p:f)},veinColor:{type:"vec3",value:l(e?_:m)}}})};exports.Marble=z;exports.marbleFragmentShader=i;exports.marbleVertexShader=o;
129
+ `;exports.marbleFragmentShader=l;exports.marbleVertexShader=e;
@@ -1,7 +1,4 @@
1
- import { jsx as b } from "react/jsx-runtime";
2
- import { c as S } from "./useUniformUpdaters-D5WtqZpp.mjs";
3
- import { u as d, B as C } from "./BaseShaderComponent-Be_evz2F.mjs";
4
- const y = (
1
+ const e = (
5
2
  /* glsl */
6
3
  `
7
4
  attribute vec2 a_position;
@@ -12,7 +9,7 @@ const y = (
12
9
  v_texCoord = a_position * 0.5 + 0.5;
13
10
  }
14
11
  `
15
- ), g = (
12
+ ), l = (
16
13
  /* glsl */
17
14
  `
18
15
  precision highp float;
@@ -135,70 +132,8 @@ void main() {
135
132
  gl_FragColor = vec4(marbleColor, 1.0);
136
133
  }
137
134
  `
138
- ), w = [0.8, 0.8, 0.9], V = [0.3, 0.3, 0.6], O = [0.1, 0.1, 0.3], z = [0.2, 0.2, 0.3], R = [0.1, 0.1, 0.2], F = [0.05, 0.05, 0.1], E = ({
139
- marbleScale: a = 3,
140
- tileScale: o = 1,
141
- turbulence: i = 0.5,
142
- swirl: t = 6,
143
- veinFrequency: r = 6,
144
- veinWidth: u = 2,
145
- colorStart: n = w,
146
- colorEnd: c = V,
147
- veinColor: s = O,
148
- colorStartDark: v = z,
149
- colorEndDark: f = R,
150
- veinColorDark: m = F,
151
- className: p = "",
152
- style: _
153
- }) => {
154
- const e = d(), l = (x) => () => new Float32Array(x), h = S({
155
- vertexShader: y,
156
- fragmentShader: g,
157
- uniformNames: {
158
- u_marbleScale: "float",
159
- u_tileScale: "float",
160
- u_turbulence: "float",
161
- u_swirl: "float",
162
- u_colorStart: "vec3",
163
- u_colorEnd: "vec3",
164
- u_veinColor: "vec3",
165
- u_veinFrequency: "float",
166
- u_veinWidth: "float"
167
- }
168
- });
169
- return /* @__PURE__ */ b(
170
- C,
171
- {
172
- programId: "marble-shader",
173
- shaderConfig: h,
174
- className: p,
175
- style: _,
176
- uniforms: {
177
- marbleScale: { value: a, type: "float" },
178
- tileScale: { value: o, type: "float" },
179
- turbulence: { value: i, type: "float" },
180
- swirl: { value: t, type: "float" },
181
- veinFrequency: { value: r, type: "float" },
182
- veinWidth: { value: u, type: "float" },
183
- colorStart: {
184
- type: "vec3",
185
- value: l(e ? v : n)
186
- // value: toF32(isDarkMode ? colorStartDark : colorStart)
187
- },
188
- colorEnd: {
189
- type: "vec3",
190
- value: l(e ? f : c)
191
- },
192
- veinColor: {
193
- type: "vec3",
194
- value: l(e ? m : s)
195
- }
196
- }
197
- }
198
- );
199
- };
135
+ );
200
136
  export {
201
- E as M,
202
- g as a,
203
- y as m
137
+ l as marbleFragmentShader,
138
+ e as marbleVertexShader
204
139
  };
@@ -0,0 +1,13 @@
1
+ import { CSSProperties } from 'react';
2
+ type Vec3 = [number, number, number];
3
+ export interface RippleProps {
4
+ damping?: number;
5
+ mouseForce?: number;
6
+ color1?: Vec3;
7
+ color2?: Vec3;
8
+ iterations?: number;
9
+ className?: string;
10
+ style?: CSSProperties;
11
+ }
12
+ export declare const Ripple: ({ damping, mouseForce, color1, color2, iterations, className, style }: RippleProps) => import("react/jsx-runtime").JSX.Element;
13
+ export default Ripple;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const M=require("react/jsx-runtime"),u=require("react"),f=require("../../src/core/lib/createShaderConfig.js"),a=require("../../src/core/lib/vectorUtils.js"),O=require("../../src/react/components/base/BasePingPongShaderComponent.js"),s=require("./rippleShaders.js"),P=[.1,.3,.1],q=[.3,.2,.4],g=({damping:S=.99,mouseForce:L=.5,color1:_=P,color2:C=q,iterations:x=2,className:E="",style:R})=>{const c=u.useRef([.5,.5]),n=u.useRef(!1),y=f.createShaderConfig({vertexShader:s.rippleVertexShader,fragmentShader:s.rippleSimulationShader,uniformNames:{u_texture0:"sampler2D",u_mouse:"vec2",u_mouseForce:"float",u_damping:"float"}}),w=f.createShaderConfig({vertexShader:s.rippleVertexShader,fragmentShader:s.rippleRenderShader,uniformNames:{u_texture0:"sampler2D",u_color1:"vec3",u_color2:"vec3"}});return u.useEffect(()=>{const i=e=>{const t=e.target.getBoundingClientRect(),o=(e.clientX-t.left)/t.width,r=1-(e.clientY-t.top)/t.height;c.current=[o,r]},d=()=>{n.current=!0},l=()=>{n.current=!1},m=e=>{if(e.touches.length>0){e.preventDefault();const t=e.target.getBoundingClientRect(),o=(e.touches[0].clientX-t.left)/t.width,r=1-(e.touches[0].clientY-t.top)/t.height;c.current=[o,r],n.current=!0}},h=e=>{if(e.touches.length>0&&n.current){e.preventDefault();const t=e.target.getBoundingClientRect(),o=(e.touches[0].clientX-t.left)/t.width,r=1-(e.touches[0].clientY-t.top)/t.height;c.current=[o,r]}},v=()=>{n.current=!1};return document.addEventListener("mousemove",i),document.addEventListener("mousedown",d),document.addEventListener("mouseup",l),document.addEventListener("touchstart",m,{passive:!1}),document.addEventListener("touchmove",h,{passive:!1}),document.addEventListener("touchend",v),()=>{document.removeEventListener("mousemove",i),document.removeEventListener("mousedown",d),document.removeEventListener("mouseup",l),document.removeEventListener("touchstart",m),document.removeEventListener("touchmove",h),document.removeEventListener("touchend",v)}},[]),M.jsx(O.BasePingPongShaderComponent,{programId:"ripple-simulation",shaderConfig:y,secondaryProgramId:"ripple-render",secondaryShaderConfig:w,iterations:x,className:E,style:R,framebufferOptions:{width:0,height:0,textureCount:2,textureOptions:{minFilter:WebGLRenderingContext.LINEAR,magFilter:WebGLRenderingContext.LINEAR}},uniforms:{u_mouse:{type:"vec2",value:a.vec2(c.current)},u_mouseForce:{type:"float",value:()=>n.current?L:0},u_damping:{type:"float",value:S}},secondaryUniforms:{u_color1:{type:"vec3",value:a.vec3(_)},u_color2:{type:"vec3",value:a.vec3(C)}}})};exports.Ripple=g;exports.default=g;
@@ -0,0 +1,109 @@
1
+ import { jsx as w } from "react/jsx-runtime";
2
+ import { useRef as v, useEffect as D } from "react";
3
+ import { createShaderConfig as h } from "../../src/core/lib/createShaderConfig.mjs";
4
+ import { vec3 as p, vec2 as M } from "../../src/core/lib/vectorUtils.mjs";
5
+ import { BasePingPongShaderComponent as O } from "../../src/react/components/base/BasePingPongShaderComponent.mjs";
6
+ import { rippleVertexShader as f, rippleSimulationShader as B, rippleRenderShader as F } from "./rippleShaders.mjs";
7
+ const I = [0.1, 0.3, 0.1], N = [0.3, 0.2, 0.4], G = ({
8
+ damping: g = 0.99,
9
+ mouseForce: L = 0.5,
10
+ color1: E = I,
11
+ color2: x = N,
12
+ iterations: C = 2,
13
+ className: S = "",
14
+ style: _
15
+ }) => {
16
+ const c = v([0.5, 0.5]), n = v(!1), R = h({
17
+ vertexShader: f,
18
+ fragmentShader: B,
19
+ uniformNames: {
20
+ u_texture0: "sampler2D",
21
+ u_mouse: "vec2",
22
+ u_mouseForce: "float",
23
+ u_damping: "float"
24
+ }
25
+ }), y = h({
26
+ vertexShader: f,
27
+ fragmentShader: F,
28
+ uniformNames: {
29
+ u_texture0: "sampler2D",
30
+ u_color1: "vec3",
31
+ u_color2: "vec3"
32
+ }
33
+ });
34
+ return D(() => {
35
+ const s = (e) => {
36
+ const t = e.target.getBoundingClientRect(), o = (e.clientX - t.left) / t.width, r = 1 - (e.clientY - t.top) / t.height;
37
+ c.current = [o, r];
38
+ }, u = () => {
39
+ n.current = !0;
40
+ }, a = () => {
41
+ n.current = !1;
42
+ }, i = (e) => {
43
+ if (e.touches.length > 0) {
44
+ e.preventDefault();
45
+ const t = e.target.getBoundingClientRect(), o = (e.touches[0].clientX - t.left) / t.width, r = 1 - (e.touches[0].clientY - t.top) / t.height;
46
+ c.current = [o, r], n.current = !0;
47
+ }
48
+ }, d = (e) => {
49
+ if (e.touches.length > 0 && n.current) {
50
+ e.preventDefault();
51
+ const t = e.target.getBoundingClientRect(), o = (e.touches[0].clientX - t.left) / t.width, r = 1 - (e.touches[0].clientY - t.top) / t.height;
52
+ c.current = [o, r];
53
+ }
54
+ }, m = () => {
55
+ n.current = !1;
56
+ };
57
+ return document.addEventListener("mousemove", s), document.addEventListener("mousedown", u), document.addEventListener("mouseup", a), document.addEventListener("touchstart", i, { passive: !1 }), document.addEventListener("touchmove", d, { passive: !1 }), document.addEventListener("touchend", m), () => {
58
+ document.removeEventListener("mousemove", s), document.removeEventListener("mousedown", u), document.removeEventListener("mouseup", a), document.removeEventListener("touchstart", i), document.removeEventListener("touchmove", d), document.removeEventListener("touchend", m);
59
+ };
60
+ }, []), /* @__PURE__ */ w(
61
+ O,
62
+ {
63
+ programId: "ripple-simulation",
64
+ shaderConfig: R,
65
+ secondaryProgramId: "ripple-render",
66
+ secondaryShaderConfig: y,
67
+ iterations: C,
68
+ className: S,
69
+ style: _,
70
+ framebufferOptions: {
71
+ width: 0,
72
+ height: 0,
73
+ textureCount: 2,
74
+ textureOptions: {
75
+ minFilter: WebGLRenderingContext.LINEAR,
76
+ magFilter: WebGLRenderingContext.LINEAR
77
+ }
78
+ },
79
+ uniforms: {
80
+ u_mouse: {
81
+ type: "vec2",
82
+ value: M(c.current)
83
+ },
84
+ u_mouseForce: {
85
+ type: "float",
86
+ value: () => n.current ? L : 0
87
+ },
88
+ u_damping: {
89
+ type: "float",
90
+ value: g
91
+ }
92
+ },
93
+ secondaryUniforms: {
94
+ u_color1: {
95
+ type: "vec3",
96
+ value: p(E)
97
+ },
98
+ u_color2: {
99
+ type: "vec3",
100
+ value: p(x)
101
+ }
102
+ }
103
+ }
104
+ );
105
+ };
106
+ export {
107
+ G as Ripple,
108
+ G as default
109
+ };
@@ -0,0 +1,3 @@
1
+ export declare const rippleVertexShader = "\n attribute vec2 a_position;\n varying vec2 v_texCoord;\n void main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n v_texCoord = a_position * 0.5 + 0.5;\n }\n";
2
+ export declare const rippleSimulationShader = "\n precision highp float;\n \n uniform vec2 u_resolution;\n uniform float u_time;\n uniform sampler2D u_texture0;\n uniform vec2 u_mouse;\n uniform float u_mouseForce;\n uniform float u_damping;\n \n varying vec2 v_texCoord;\n \n void main() {\n vec2 uv = v_texCoord;\n vec2 texelSize = 1.0 / u_resolution;\n \n vec4 state = texture2D(u_texture0, uv);\n float height = state.r;\n float velocity = state.g;\n \n float north = texture2D(u_texture0, uv + vec2(0.0, texelSize.y)).r;\n float south = texture2D(u_texture0, uv - vec2(0.0, texelSize.y)).r;\n float east = texture2D(u_texture0, uv + vec2(texelSize.x, 0.0)).r;\n float west = texture2D(u_texture0, uv - vec2(texelSize.x, 0.0)).r;\n \n float newVelocity = velocity + ((north + south + east + west) / 4.0 - height) * 2.0;\n newVelocity *= u_damping;\n \n float newHeight = height + newVelocity;\n \n vec2 mouseVec = u_mouse - uv;\n float mouseDistance = length(mouseVec);\n if (mouseDistance < 0.05 && u_mouseForce > 0.0) {\n newHeight += 0.5;\n }\n \n float startTime = mod(u_time * 0.001, 10.0);\n if (startTime < 0.2) {\n vec2 center = vec2(0.5, 0.5);\n float centerDist = length(uv - center);\n if (centerDist < 0.05) {\n newHeight += 0.5 * (1.0 - startTime * 5.0);\n }\n }\n \n gl_FragColor = vec4(newHeight, newVelocity, 0.0, 1.0);\n }\n";
3
+ export declare const rippleRenderShader = "\n precision highp float;\n \n uniform vec2 u_resolution;\n uniform float u_time;\n uniform sampler2D u_texture0;\n uniform vec3 u_color1;\n uniform vec3 u_color2;\n \n varying vec2 v_texCoord;\n \n void main() {\n vec2 uv = v_texCoord;\n \n vec4 state = texture2D(u_texture0, uv);\n float height = state.r;\n \n vec3 color = mix(u_color1, u_color2, (height + 1.0) * 0.5);\n \n float t = u_time * 0.001;\n float brightness = 1.0 + 0.1 * sin(uv.x * 10.0 + t) * sin(uv.y * 10.0 + t);\n color *= brightness;\n \n gl_FragColor = vec4(color, 1.0);\n }\n";
@@ -0,0 +1,80 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=`
2
+ attribute vec2 a_position;
3
+ varying vec2 v_texCoord;
4
+ void main() {
5
+ gl_Position = vec4(a_position, 0.0, 1.0);
6
+ v_texCoord = a_position * 0.5 + 0.5;
7
+ }
8
+ `,t=`
9
+ precision highp float;
10
+
11
+ uniform vec2 u_resolution;
12
+ uniform float u_time;
13
+ uniform sampler2D u_texture0;
14
+ uniform vec2 u_mouse;
15
+ uniform float u_mouseForce;
16
+ uniform float u_damping;
17
+
18
+ varying vec2 v_texCoord;
19
+
20
+ void main() {
21
+ vec2 uv = v_texCoord;
22
+ vec2 texelSize = 1.0 / u_resolution;
23
+
24
+ vec4 state = texture2D(u_texture0, uv);
25
+ float height = state.r;
26
+ float velocity = state.g;
27
+
28
+ float north = texture2D(u_texture0, uv + vec2(0.0, texelSize.y)).r;
29
+ float south = texture2D(u_texture0, uv - vec2(0.0, texelSize.y)).r;
30
+ float east = texture2D(u_texture0, uv + vec2(texelSize.x, 0.0)).r;
31
+ float west = texture2D(u_texture0, uv - vec2(texelSize.x, 0.0)).r;
32
+
33
+ float newVelocity = velocity + ((north + south + east + west) / 4.0 - height) * 2.0;
34
+ newVelocity *= u_damping;
35
+
36
+ float newHeight = height + newVelocity;
37
+
38
+ vec2 mouseVec = u_mouse - uv;
39
+ float mouseDistance = length(mouseVec);
40
+ if (mouseDistance < 0.05 && u_mouseForce > 0.0) {
41
+ newHeight += 0.5;
42
+ }
43
+
44
+ float startTime = mod(u_time * 0.001, 10.0);
45
+ if (startTime < 0.2) {
46
+ vec2 center = vec2(0.5, 0.5);
47
+ float centerDist = length(uv - center);
48
+ if (centerDist < 0.05) {
49
+ newHeight += 0.5 * (1.0 - startTime * 5.0);
50
+ }
51
+ }
52
+
53
+ gl_FragColor = vec4(newHeight, newVelocity, 0.0, 1.0);
54
+ }
55
+ `,o=`
56
+ precision highp float;
57
+
58
+ uniform vec2 u_resolution;
59
+ uniform float u_time;
60
+ uniform sampler2D u_texture0;
61
+ uniform vec3 u_color1;
62
+ uniform vec3 u_color2;
63
+
64
+ varying vec2 v_texCoord;
65
+
66
+ void main() {
67
+ vec2 uv = v_texCoord;
68
+
69
+ vec4 state = texture2D(u_texture0, uv);
70
+ float height = state.r;
71
+
72
+ vec3 color = mix(u_color1, u_color2, (height + 1.0) * 0.5);
73
+
74
+ float t = u_time * 0.001;
75
+ float brightness = 1.0 + 0.1 * sin(uv.x * 10.0 + t) * sin(uv.y * 10.0 + t);
76
+ color *= brightness;
77
+
78
+ gl_FragColor = vec4(color, 1.0);
79
+ }
80
+ `;exports.rippleRenderShader=o;exports.rippleSimulationShader=t;exports.rippleVertexShader=e;