@elementalfx/fluid 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +101 -2
- package/dist/chunks/chunk-FAVDIVND.js +775 -0
- package/dist/chunks/chunk-FAVDIVND.js.map +7 -0
- package/dist/element.d.ts +77 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +40 -0
- package/dist/element.js.map +7 -0
- package/dist/fluid.d.ts +31 -0
- package/dist/fluid.d.ts.map +1 -0
- package/dist/fluid.global.js +120 -0
- package/dist/global.d.ts +3 -0
- package/dist/global.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +7 -0
- package/dist/options.d.ts +62 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/shaders.d.ts +24 -0
- package/dist/shaders.d.ts.map +1 -0
- package/package.json +71 -3
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable-fluids passes (Stam 1999; GPU Gems ch. 38). Velocity is stored in
|
|
3
|
+
* simulation cells per second; walls reflect velocity at the edges.
|
|
4
|
+
*/
|
|
5
|
+
/** Moves a quantity along the velocity field (semi-Lagrangian) and fades it. */
|
|
6
|
+
export declare const ADVECT = "#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nin vec2 vUv;\nout vec4 outColor;\nuniform vec2 uTexel;\n\nuniform sampler2D uVelocity;\nuniform sampler2D uSource;\nuniform float uDt;\nuniform float uDissipation;\nvoid main() {\n vec2 back = vUv - uDt * texture(uVelocity, vUv).xy * uTexel;\n outColor = texture(uSource, back) / (1.0 + uDissipation * uDt);\n}";
|
|
7
|
+
export declare const DIVERGENCE = "#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nin vec2 vUv;\nout vec4 outColor;\nuniform vec2 uTexel;\n\nvec2 uvL() { return vUv - vec2(uTexel.x, 0.0); }\nvec2 uvR() { return vUv + vec2(uTexel.x, 0.0); }\nvec2 uvB() { return vUv - vec2(0.0, uTexel.y); }\nvec2 uvT() { return vUv + vec2(0.0, uTexel.y); }\n\nuniform sampler2D uVelocity;\nvoid main() {\n vec2 c = texture(uVelocity, vUv).xy;\n float l = texture(uVelocity, uvL()).x;\n float r = texture(uVelocity, uvR()).x;\n float b = texture(uVelocity, uvB()).y;\n float t = texture(uVelocity, uvT()).y;\n // Solid walls: mirror the normal component at the boundary.\n if (uvL().x < 0.0) l = -c.x;\n if (uvR().x > 1.0) r = -c.x;\n if (uvB().y < 0.0) b = -c.y;\n if (uvT().y > 1.0) t = -c.y;\n outColor = vec4(0.5 * (r - l + t - b), 0.0, 0.0, 1.0);\n}";
|
|
8
|
+
export declare const CURL = "#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nin vec2 vUv;\nout vec4 outColor;\nuniform vec2 uTexel;\n\nvec2 uvL() { return vUv - vec2(uTexel.x, 0.0); }\nvec2 uvR() { return vUv + vec2(uTexel.x, 0.0); }\nvec2 uvB() { return vUv - vec2(0.0, uTexel.y); }\nvec2 uvT() { return vUv + vec2(0.0, uTexel.y); }\n\nuniform sampler2D uVelocity;\nvoid main() {\n float l = texture(uVelocity, uvL()).y;\n float r = texture(uVelocity, uvR()).y;\n float b = texture(uVelocity, uvB()).x;\n float t = texture(uVelocity, uvT()).x;\n outColor = vec4(0.5 * (r - l - t + b), 0.0, 0.0, 1.0);\n}";
|
|
9
|
+
/** Vorticity confinement: re-injects the small swirls that numerical diffusion smooths away. */
|
|
10
|
+
export declare const VORTICITY = "#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nin vec2 vUv;\nout vec4 outColor;\nuniform vec2 uTexel;\n\nvec2 uvL() { return vUv - vec2(uTexel.x, 0.0); }\nvec2 uvR() { return vUv + vec2(uTexel.x, 0.0); }\nvec2 uvB() { return vUv - vec2(0.0, uTexel.y); }\nvec2 uvT() { return vUv + vec2(0.0, uTexel.y); }\n\nuniform sampler2D uVelocity;\nuniform sampler2D uCurl;\nuniform float uCurlStrength;\nuniform float uDt;\nvoid main() {\n float l = texture(uCurl, uvL()).x;\n float r = texture(uCurl, uvR()).x;\n float b = texture(uCurl, uvB()).x;\n float t = texture(uCurl, uvT()).x;\n float c = texture(uCurl, vUv).x;\n vec2 force = 0.5 * vec2(abs(t) - abs(b), abs(r) - abs(l));\n force /= length(force) + 1e-4;\n force *= uCurlStrength * c;\n force.y = -force.y;\n vec2 velocity = texture(uVelocity, vUv).xy + force * uDt;\n outColor = vec4(clamp(velocity, -1000.0, 1000.0), 0.0, 1.0);\n}";
|
|
11
|
+
/** Fades last frame's pressure; it's a good starting guess for this frame's solve. */
|
|
12
|
+
export declare const SCALE = "#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nin vec2 vUv;\nout vec4 outColor;\nuniform vec2 uTexel;\n\nuniform sampler2D uSource;\nuniform float uValue;\nvoid main() {\n outColor = texture(uSource, vUv) * uValue;\n}";
|
|
13
|
+
/** One Jacobi iteration of the pressure Poisson equation. */
|
|
14
|
+
export declare const PRESSURE = "#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nin vec2 vUv;\nout vec4 outColor;\nuniform vec2 uTexel;\n\nvec2 uvL() { return vUv - vec2(uTexel.x, 0.0); }\nvec2 uvR() { return vUv + vec2(uTexel.x, 0.0); }\nvec2 uvB() { return vUv - vec2(0.0, uTexel.y); }\nvec2 uvT() { return vUv + vec2(0.0, uTexel.y); }\n\nuniform sampler2D uPressure;\nuniform sampler2D uDivergence;\nvoid main() {\n float l = texture(uPressure, uvL()).x;\n float r = texture(uPressure, uvR()).x;\n float b = texture(uPressure, uvB()).x;\n float t = texture(uPressure, uvT()).x;\n float divergence = texture(uDivergence, vUv).x;\n outColor = vec4((l + r + b + t - divergence) * 0.25, 0.0, 0.0, 1.0);\n}";
|
|
15
|
+
/** Removes the pressure gradient, leaving a divergence-free (incompressible) velocity. */
|
|
16
|
+
export declare const GRADIENT_SUBTRACT = "#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nin vec2 vUv;\nout vec4 outColor;\nuniform vec2 uTexel;\n\nvec2 uvL() { return vUv - vec2(uTexel.x, 0.0); }\nvec2 uvR() { return vUv + vec2(uTexel.x, 0.0); }\nvec2 uvB() { return vUv - vec2(0.0, uTexel.y); }\nvec2 uvT() { return vUv + vec2(0.0, uTexel.y); }\n\nuniform sampler2D uPressure;\nuniform sampler2D uVelocity;\nvoid main() {\n float l = texture(uPressure, uvL()).x;\n float r = texture(uPressure, uvR()).x;\n float b = texture(uPressure, uvB()).x;\n float t = texture(uPressure, uvT()).x;\n vec2 velocity = texture(uVelocity, vUv).xy - 0.5 * vec2(r - l, t - b);\n outColor = vec4(velocity, 0.0, 1.0);\n}";
|
|
17
|
+
/** Adds a Gaussian blob of velocity or dye. */
|
|
18
|
+
export declare const SPLAT = "#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nin vec2 vUv;\nout vec4 outColor;\nuniform vec2 uTexel;\n\nuniform sampler2D uTarget;\nuniform float uAspect;\nuniform vec3 uValue;\nuniform vec2 uPoint;\nuniform float uRadius;\nvoid main() {\n vec2 p = vUv - uPoint;\n p.x *= uAspect;\n vec3 base = texture(uTarget, vUv).xyz;\n outColor = vec4(base + exp(-dot(p, p) / uRadius) * uValue, 1.0);\n}";
|
|
19
|
+
/**
|
|
20
|
+
* Draws the dye with transparency where there's none, so the page shows
|
|
21
|
+
* through. Optional shading reads dye density as a height for a soft 3D look.
|
|
22
|
+
*/
|
|
23
|
+
export declare const DISPLAY = "#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nin vec2 vUv;\nout vec4 outColor;\nuniform vec2 uTexel;\n\nvec2 uvL() { return vUv - vec2(uTexel.x, 0.0); }\nvec2 uvR() { return vUv + vec2(uTexel.x, 0.0); }\nvec2 uvB() { return vUv - vec2(0.0, uTexel.y); }\nvec2 uvT() { return vUv + vec2(0.0, uTexel.y); }\n\nuniform sampler2D uDye;\nuniform float uOpacity;\nuniform float uShading;\nvoid main() {\n vec3 color = texture(uDye, vUv).rgb;\n if (uShading > 0.0) {\n float dx = length(texture(uDye, uvR()).rgb) - length(texture(uDye, uvL()).rgb);\n float dy = length(texture(uDye, uvT()).rgb) - length(texture(uDye, uvB()).rgb);\n vec3 n = normalize(vec3(dx, dy, length(uTexel)));\n float diffuse = clamp(dot(n, vec3(0.0, 0.0, 1.0)) + 0.7, 0.7, 1.0);\n color *= mix(1.0, diffuse, uShading);\n }\n float alpha = clamp(max(color.r, max(color.g, color.b)), 0.0, 1.0) * uOpacity;\n // Premultiplied output: dye adds light where it's dense and fades to clear.\n outColor = vec4(min(color, vec3(1.0)) * uOpacity, alpha);\n}";
|
|
24
|
+
//# sourceMappingURL=shaders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shaders.d.ts","sourceRoot":"","sources":["../src/shaders.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkBH,gFAAgF;AAChF,eAAO,MAAM,MAAM,kYAQjB,CAAC;AAEH,eAAO,MAAM,UAAU,s0BAcrB,CAAC;AAEH,eAAO,MAAM,IAAI,8lBAQf,CAAC;AAEH,gGAAgG;AAChG,eAAO,MAAM,SAAS,u5BAiBpB,CAAC;AAEH,sFAAsF;AACtF,eAAO,MAAM,KAAK,qPAKhB,CAAC;AAEH,6DAA6D;AAC7D,eAAO,MAAM,QAAQ,+rBAUnB,CAAC;AAEH,0FAA0F;AAC1F,eAAO,MAAM,iBAAiB,orBAU5B,CAAC;AAEH,+CAA+C;AAC/C,eAAO,MAAM,KAAK,uaAWhB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,OAAO,miCAgBlB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,74 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementalfx/fluid",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Interactive WebGL fluid simulation: a smoke or ink cursor trail over your page, a living background behind your content, or splashes on demand.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": [
|
|
8
|
+
"./dist/element.js",
|
|
9
|
+
"./dist/*.global.js"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./element": {
|
|
17
|
+
"types": "./dist/element.d.ts",
|
|
18
|
+
"import": "./dist/element.js"
|
|
19
|
+
},
|
|
20
|
+
"./global": "./dist/fluid.global.js",
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"module": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"unpkg": "./dist/fluid.global.js",
|
|
27
|
+
"jsdelivr": "./dist/fluid.global.js",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"keywords": [
|
|
33
|
+
"fluid",
|
|
34
|
+
"fluid-simulation",
|
|
35
|
+
"webgl-fluid",
|
|
36
|
+
"smoke",
|
|
37
|
+
"ink",
|
|
38
|
+
"cursor-trail",
|
|
39
|
+
"cursor-effect",
|
|
40
|
+
"navier-stokes",
|
|
41
|
+
"interactive-background",
|
|
42
|
+
"elementalfx",
|
|
43
|
+
"effects",
|
|
44
|
+
"animation",
|
|
45
|
+
"web-animation",
|
|
46
|
+
"webgl",
|
|
47
|
+
"web-components",
|
|
48
|
+
"custom-elements",
|
|
49
|
+
"framework-agnostic",
|
|
50
|
+
"reduced-motion",
|
|
51
|
+
"typescript"
|
|
52
|
+
],
|
|
53
|
+
"homepage": "https://iyerav42.github.io/elementalfx/#fluid",
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "git+https://github.com/iyerav42/elementalfx.git",
|
|
57
|
+
"directory": "packages/fluid"
|
|
58
|
+
},
|
|
59
|
+
"bugs": {
|
|
60
|
+
"url": "https://github.com/iyerav42/elementalfx/issues"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@elementalfx/core": "^0.1.1",
|
|
64
|
+
"@elementalfx/gl": "^0.1.1"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
},
|
|
69
|
+
"elementalfx": {
|
|
70
|
+
"global": "fluid",
|
|
71
|
+
"globalEntry": "src/global.ts",
|
|
72
|
+
"sizeLimit": 12288
|
|
73
|
+
}
|
|
6
74
|
}
|