@firecms/neat 0.6.0 → 0.7.0

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/src/math.ts ADDED
@@ -0,0 +1,162 @@
1
+ export class Matrix4 {
2
+ elements: Float32Array;
3
+ constructor() {
4
+ this.elements = new Float32Array([
5
+ 1, 0, 0, 0,
6
+ 0, 1, 0, 0,
7
+ 0, 0, 1, 0,
8
+ 0, 0, 0, 1
9
+ ]);
10
+ }
11
+ translate(tx: number, ty: number, tz: number) {
12
+ this.elements[12] += this.elements[0] * tx + this.elements[4] * ty + this.elements[8] * tz;
13
+ this.elements[13] += this.elements[1] * tx + this.elements[5] * ty + this.elements[9] * tz;
14
+ this.elements[14] += this.elements[2] * tx + this.elements[6] * ty + this.elements[10] * tz;
15
+ this.elements[15] += this.elements[3] * tx + this.elements[7] * ty + this.elements[11] * tz;
16
+ return this;
17
+ }
18
+ rotateX(angle: number) {
19
+ const c = Math.cos(angle);
20
+ const s = Math.sin(angle);
21
+ const m12 = this.elements[4], m22 = this.elements[5], m32 = this.elements[6], m42 = this.elements[7];
22
+ const m13 = this.elements[8], m23 = this.elements[9], m33 = this.elements[10], m43 = this.elements[11];
23
+ this.elements[4] = c * m12 + s * m13;
24
+ this.elements[5] = c * m22 + s * m23;
25
+ this.elements[6] = c * m32 + s * m33;
26
+ this.elements[7] = c * m42 + s * m43;
27
+ this.elements[8] = c * m13 - s * m12;
28
+ this.elements[9] = c * m23 - s * m22;
29
+ this.elements[10] = c * m33 - s * m32;
30
+ this.elements[11] = c * m43 - s * m42;
31
+ return this;
32
+ }
33
+ }
34
+
35
+ export class OrthographicCamera {
36
+ left: number;
37
+ right: number;
38
+ top: number;
39
+ bottom: number;
40
+ near: number;
41
+ far: number;
42
+ position: [number, number, number];
43
+ projectionMatrix: Matrix4;
44
+
45
+ constructor(left: number, right: number, top: number, bottom: number, near: number, far: number) {
46
+ this.left = left;
47
+ this.right = right;
48
+ this.top = top;
49
+ this.bottom = bottom;
50
+ this.near = near;
51
+ this.far = far;
52
+ this.position = [0, 0, 0];
53
+ this.projectionMatrix = new Matrix4();
54
+ this.updateProjectionMatrix();
55
+ }
56
+
57
+ updateProjectionMatrix() {
58
+ const w = 1.0 / (this.right - this.left);
59
+ const h = 1.0 / (this.top - this.bottom);
60
+ const p = 1.0 / (this.far - this.near);
61
+ const x = (this.right + this.left) * w;
62
+ const y = (this.top + this.bottom) * h;
63
+ const z = (this.far + this.near) * p;
64
+ this.projectionMatrix.elements = new Float32Array([
65
+ 2 * w, 0, 0, 0,
66
+ 0, 2 * h, 0, 0,
67
+ 0, 0, -2 * p, 0,
68
+ -x, -y, -z, 1
69
+ ]);
70
+ }
71
+ }
72
+
73
+ export function updateCamera(camera: OrthographicCamera, width: number, height: number, planeWidth: number = 50, planeHeight: number = 50) {
74
+ const viewPortAreaRatio = 1000000;
75
+ const areaViewPort = width * height;
76
+ const targetPlaneArea = areaViewPort / viewPortAreaRatio * planeWidth * planeHeight / 1.5;
77
+
78
+ const ratio = width / height;
79
+ const targetWidth = Math.sqrt(targetPlaneArea * ratio);
80
+ const targetHeight = targetPlaneArea / targetWidth;
81
+
82
+ let left = -planeWidth / 2;
83
+ let right = Math.min((left + targetWidth) / 1.5, planeWidth / 2);
84
+ let top = planeHeight / 4;
85
+ let bottom = Math.max((top - targetHeight) / 2, -planeHeight / 4);
86
+
87
+ if (ratio < 1) {
88
+ const horizontalScale = ratio;
89
+ left = left * horizontalScale;
90
+ right = right * horizontalScale;
91
+ const mobileZoomFactor = 1.05;
92
+ left = left * mobileZoomFactor;
93
+ right = right * mobileZoomFactor;
94
+ top = top * mobileZoomFactor;
95
+ bottom = bottom * mobileZoomFactor;
96
+ }
97
+
98
+ camera.left = left;
99
+ camera.right = right;
100
+ camera.top = top;
101
+ camera.bottom = bottom;
102
+ camera.near = -100;
103
+ camera.far = 1000;
104
+ camera.updateProjectionMatrix();
105
+ }
106
+
107
+ export function generatePlaneGeometry(width: number, height: number, widthSegments: number, heightSegments: number) {
108
+ const width_half = width / 2;
109
+ const height_half = height / 2;
110
+ const gridX = Math.floor(widthSegments);
111
+ const gridY = Math.floor(heightSegments);
112
+ const gridX1 = gridX + 1;
113
+ const gridY1 = gridY + 1;
114
+ const segment_width = width / gridX;
115
+ const segment_height = height / gridY;
116
+
117
+ const indices = [];
118
+ const vertices = [];
119
+ const normals = [];
120
+ const uvs = [];
121
+
122
+ for (let iy = 0; iy < gridY1; iy++) {
123
+ const y = iy * segment_height - height_half;
124
+ for (let ix = 0; ix < gridX1; ix++) {
125
+ const x = ix * segment_width - width_half;
126
+ vertices.push(x, -y, 0);
127
+ normals.push(0, 0, 1);
128
+ uvs.push(ix / gridX);
129
+ uvs.push(1 - (iy / gridY));
130
+ }
131
+ }
132
+
133
+ for (let iy = 0; iy < gridY; iy++) {
134
+ for (let ix = 0; ix < gridX; ix++) {
135
+ const a = ix + gridX1 * iy;
136
+ const b = ix + gridX1 * (iy + 1);
137
+ const c = (ix + 1) + gridX1 * (iy + 1);
138
+ const d = (ix + 1) + gridX1 * iy;
139
+ indices.push(a, b, d);
140
+ indices.push(b, c, d);
141
+ }
142
+ }
143
+
144
+ const isLarge = vertices.length / 3 > 65535;
145
+
146
+ // Generate wireframe indices: for each triangle (a,b,c), emit lines a→b, b→c, c→a
147
+ const wireframeIndices = [];
148
+ for (let i = 0; i < indices.length; i += 3) {
149
+ const a = indices[i];
150
+ const b = indices[i + 1];
151
+ const c = indices[i + 2];
152
+ wireframeIndices.push(a, b, b, c, c, a);
153
+ }
154
+
155
+ return {
156
+ position: new Float32Array(vertices),
157
+ normal: new Float32Array(normals),
158
+ uv: new Float32Array(uvs),
159
+ index: isLarge ? new Uint32Array(indices) : new Uint16Array(indices),
160
+ wireframeIndex: isLarge ? new Uint32Array(wireframeIndices) : new Uint16Array(wireframeIndices)
161
+ };
162
+ }
package/src/shaders.ts ADDED
@@ -0,0 +1,411 @@
1
+ export const vertexShaderSource = `void main() {
2
+ vUv = uv;
3
+
4
+ // SCROLLING LOGIC
5
+ // Separate multipliers for wave, color, and flow offsets
6
+ float waveOffset = -u_y_offset * u_y_offset_wave_multiplier;
7
+ float colorOffset = -u_y_offset * u_y_offset_color_multiplier;
8
+ float flowOffset = -u_y_offset * u_y_offset_flow_multiplier;
9
+
10
+ // 1. DISPLACEMENT (WAVES)
11
+ // We add waveOffset to Y to scroll the wave pattern
12
+ v_displacement_amount = cnoise( vec3(
13
+ u_wave_frequency_x * position.x + u_time,
14
+ u_wave_frequency_y * (position.y + waveOffset) + u_time,
15
+ u_time
16
+ ));
17
+
18
+ // 2. FLOW FIELD
19
+ // Apply flow offset to scroll the flow field mask
20
+ vec2 baseUv = vUv;
21
+ baseUv.y += flowOffset / u_plane_height; // Scale to match wave speed
22
+ vec2 flowUv = baseUv;
23
+
24
+ if (u_flow_enabled > 0.5) {
25
+ if (u_flow_ease > 0.0 || u_flow_distortion_a > 0.0) {
26
+ vec2 ppp = -1.0 + 2.0 * baseUv;
27
+ ppp += 0.1 * cos((1.5 * u_flow_scale) * ppp.yx + 1.1 * u_time + vec2(0.1, 1.1));
28
+ ppp += 0.1 * cos((2.3 * u_flow_scale) * ppp.yx + 1.3 * u_time + vec2(3.2, 3.4));
29
+ ppp += 0.1 * cos((2.2 * u_flow_scale) * ppp.yx + 1.7 * u_time + vec2(1.8, 5.2));
30
+ ppp += u_flow_distortion_a * cos((u_flow_distortion_b * u_flow_scale) * ppp.yx + 1.4 * u_time + vec2(6.3, 3.9));
31
+
32
+ float r = length(ppp);
33
+ flowUv = mix(baseUv, vec2(baseUv.x * (1.0 - u_flow_ease) + r * u_flow_ease, baseUv.y), u_flow_ease);
34
+ }
35
+ }
36
+
37
+ // Pass the standard flow UV to fragment shader (for texture)
38
+ vFlowUv = flowUv;
39
+
40
+ // 3. COLOR MIXING
41
+ // We take the computed flow UVs and apply the color offset
42
+ // Scale by plane height to match wave offset speed (world space vs UV space)
43
+ vec3 color = u_colors[0].color;
44
+ // ...
45
+ vec2 adjustedUv = flowUv;
46
+ adjustedUv.y += colorOffset / u_plane_height; // Scroll the color mixing pattern
47
+
48
+ vec2 noise_cord = adjustedUv * u_color_pressure;
49
+ const float minNoise = .0;
50
+ const float maxNoise = .9;
51
+
52
+ for (int i = 1; i < 6; i++) {
53
+ if (i < u_colors_count) {
54
+ if (u_colors[i].is_active > 0.5) {
55
+ float noiseFlow = (1. + float(i)) / 30.;
56
+ float noiseSpeed = (1. + float(i)) * 0.11;
57
+ float noiseSeed = 13. + float(i) * 7.;
58
+
59
+ float noise = snoise(
60
+ vec3(
61
+ noise_cord.x * u_color_pressure.x + u_time * noiseFlow * 2.,
62
+ noise_cord.y * u_color_pressure.y,
63
+ u_time * noiseSpeed
64
+ ) + noiseSeed
65
+ ) - (.1 * float(i)) + (.5 * u_color_blending);
66
+
67
+ noise = clamp(noise, minNoise, maxNoise + float(i) * 0.02);
68
+ color = mix(color, u_colors[i].color, smoothstep(0.0, u_color_blending, noise));
69
+ }
70
+ }
71
+ }
72
+
73
+ v_color = color;
74
+
75
+ // 4. VERTEX POSITION
76
+ vec3 newPosition = position + normal * v_displacement_amount * u_wave_amplitude;
77
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition, 1.0);
78
+ v_new_position = gl_Position;
79
+ }
80
+ `;
81
+
82
+ export const fragmentShaderSource = `float random(vec2 p) {
83
+ return fract(sin(dot(p, vec2(12.9898,78.233))) * 43758.5453);
84
+ }
85
+
86
+ float fbm(vec3 x) {
87
+ float value = 0.0;
88
+ float amplitude = 0.5;
89
+ float frequency = 1.0;
90
+ for (int i = 0; i < 4; i++) {
91
+ value += amplitude * snoise(x * frequency);
92
+ frequency *= 2.0;
93
+ amplitude *= 0.5;
94
+ }
95
+ return value;
96
+ }
97
+
98
+ void main() {
99
+ vec2 finalUv = vFlowUv;
100
+
101
+ vec3 baseColor;
102
+
103
+ if (u_enable_procedural_texture > 0.5) {
104
+ // Calculate flow field distance for ease effect
105
+ vec2 ppp = -1.0 + 2.0 * finalUv;
106
+ ppp += 0.1 * cos((1.5 * u_flow_scale) * ppp.yx + 1.1 * u_time + vec2(0.1, 1.1));
107
+ ppp += 0.1 * cos((2.3 * u_flow_scale) * ppp.yx + 1.3 * u_time + vec2(3.2, 3.4));
108
+ ppp += 0.1 * cos((2.2 * u_flow_scale) * ppp.yx + 1.7 * u_time + vec2(1.8, 5.2));
109
+ ppp += u_flow_distortion_a * cos((u_flow_distortion_b * u_flow_scale) * ppp.yx + 1.4 * u_time + vec2(6.3, 3.9));
110
+ float r = length(ppp); // Flow distance
111
+
112
+ // Ease blending: 0 = topographic (flow), 1 = image (UV)
113
+ float vx = (finalUv.x * u_texture_ease) + (r * (1.0 - u_texture_ease));
114
+ float vy = (finalUv.y * u_texture_ease) + (0.0 * (1.0 - u_texture_ease));
115
+ vec2 texUv = vec2(vx, vy);
116
+
117
+ // PARALLAX SCROLLING
118
+ // We manually apply a smaller offset here to make the texture lag behind
119
+ float parallaxFactor = 0.25; // 25% speed of the color mixing
120
+ texUv.y -= (u_y_offset * u_y_offset_color_multiplier / u_plane_height) * parallaxFactor;
121
+
122
+ texUv *= 1.5; // Tiling scale
123
+
124
+ vec4 texSample = texture2D(u_procedural_texture, texUv);
125
+ baseColor = texSample.rgb;
126
+ } else {
127
+ baseColor = v_color;
128
+ }
129
+
130
+ vec3 color = baseColor;
131
+
132
+ // Post-processing
133
+ color += v_displacement_amount * u_highlights;
134
+ // Replace pow() with direct multiplication to avoid negative base undefined behavior in GLSL
135
+ float shadowFactor = 1.0 - v_displacement_amount;
136
+ color -= shadowFactor * shadowFactor * u_shadows;
137
+ color = saturation(color, 1.0 + u_saturation);
138
+ color = color * u_brightness;
139
+
140
+ // Grain
141
+ vec2 noiseCoords = gl_FragCoord.xy / u_grain_scale;
142
+ float grain = 0.0;
143
+
144
+ // Completely bypass expensive noise generation if grain is disabled
145
+ if (u_grain_intensity > 0.0) {
146
+ if (u_grain_speed != 0.0) {
147
+ grain = fbm(vec3(noiseCoords, u_time * u_grain_speed));
148
+ } else {
149
+ grain = fbm(vec3(noiseCoords, 0.0));
150
+ }
151
+
152
+ grain = grain * 0.5 + 0.5;
153
+ grain -= 0.5;
154
+ grain = (grain > u_grain_sparsity) ? grain : 0.0;
155
+ grain *= u_grain_intensity;
156
+ }
157
+
158
+ color += vec3(grain);
159
+
160
+ gl_FragColor = vec4(color, 1.0);
161
+ }
162
+ `;
163
+
164
+ export function buildVertUniforms(): string {
165
+ return `precision highp float;
166
+
167
+ attribute vec3 position;
168
+ attribute vec3 normal;
169
+ attribute vec2 uv;
170
+
171
+ uniform mat4 modelViewMatrix;
172
+ uniform mat4 projectionMatrix;
173
+
174
+ varying vec2 vUv;
175
+ varying vec2 vFlowUv;
176
+ varying vec4 v_new_position;
177
+ varying vec3 v_color;
178
+ varying float v_displacement_amount;
179
+
180
+ uniform float u_time;
181
+ uniform vec2 u_resolution;
182
+ uniform vec2 u_color_pressure;
183
+ uniform float u_wave_frequency_x;
184
+ uniform float u_wave_frequency_y;
185
+ uniform float u_wave_amplitude;
186
+ uniform float u_plane_width;
187
+ uniform float u_plane_height;
188
+ uniform float u_color_blending;
189
+
190
+ uniform int u_colors_count;
191
+ struct ColorStop {
192
+ float is_active;
193
+ vec3 color;
194
+ float influence;
195
+ };
196
+ uniform ColorStop u_colors[6];
197
+
198
+ uniform float u_y_offset;
199
+ uniform float u_y_offset_wave_multiplier;
200
+ uniform float u_y_offset_color_multiplier;
201
+ uniform float u_y_offset_flow_multiplier;
202
+
203
+ // Flow field uniforms
204
+ uniform float u_flow_distortion_a;
205
+ uniform float u_flow_distortion_b;
206
+ uniform float u_flow_scale;
207
+ uniform float u_flow_ease;
208
+ uniform float u_flow_enabled;
209
+ `;
210
+ }
211
+
212
+ export function buildFragUniforms(): string {
213
+ return `precision highp float;
214
+
215
+ varying vec2 vUv;
216
+ varying vec2 vFlowUv;
217
+ varying vec3 v_color;
218
+ varying float v_displacement_amount;
219
+
220
+ uniform float u_time;
221
+ uniform float u_plane_height;
222
+
223
+ uniform float u_shadows;
224
+ uniform float u_highlights;
225
+ uniform float u_saturation;
226
+ uniform float u_brightness;
227
+ uniform float u_grain_intensity;
228
+ uniform float u_grain_sparsity;
229
+ uniform float u_grain_scale;
230
+ uniform float u_grain_speed;
231
+
232
+ uniform float u_y_offset;
233
+ uniform float u_y_offset_color_multiplier;
234
+
235
+ // Flow field uniforms
236
+ uniform float u_flow_distortion_a;
237
+ uniform float u_flow_distortion_b;
238
+ uniform float u_flow_scale;
239
+
240
+ // Procedural texture uniforms
241
+ uniform sampler2D u_procedural_texture;
242
+ uniform float u_enable_procedural_texture;
243
+ uniform float u_texture_ease;
244
+ `;
245
+ }
246
+
247
+ export function buildNoise(): string {
248
+ return `
249
+ // 1. REPLACEMENT PERMUTE:
250
+ // Uses a hash function (fract/sin) instead of a modular lookup table.
251
+ vec4 permute(vec4 x) {
252
+ return floor(fract(sin(x) * 43758.5453123) * 289.0);
253
+ }
254
+
255
+ // Taylor Inverse Sqrt
256
+ vec4 taylorInvSqrt(vec4 r) {
257
+ return 1.79284291400159 - 0.85373472095314 * r;
258
+ }
259
+
260
+ // Fade function
261
+ vec3 fade(vec3 t) {
262
+ return t*t*t*(t*(t*6.0-15.0)+10.0);
263
+ }
264
+
265
+ // 3D Simplex Noise
266
+ float snoise(vec3 v) {
267
+ const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
268
+ const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
269
+
270
+ // First corner
271
+ vec3 i = floor(v + dot(v, C.yyy) );
272
+ vec3 x0 = v - i + dot(i, C.xxx) ;
273
+
274
+ // Other corners
275
+ vec3 g = step(x0.yzx, x0.xyz);
276
+ vec3 l = 1.0 - g;
277
+ vec3 i1 = min( g.xyz, l.zxy );
278
+ vec3 i2 = max( g.xyz, l.zxy );
279
+
280
+ vec3 x1 = x0 - i1 + C.xxx;
281
+ vec3 x2 = x0 - i2 + C.yyy;
282
+ vec3 x3 = x0 - D.yyy;
283
+
284
+ // Permutations
285
+ vec4 p = permute( permute( permute(
286
+ i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
287
+ + i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
288
+ + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
289
+
290
+ // Gradients
291
+ float n_ = 0.142857142857; // 1.0/7.0
292
+ vec3 ns = n_ * D.wyz - D.xzx;
293
+
294
+ vec4 j = p - 49.0 * floor(p * ns.z * ns.z);
295
+
296
+ vec4 x_ = floor(j * ns.z);
297
+ vec4 y_ = floor(j - 7.0 * x_ );
298
+
299
+ vec4 x = x_ *ns.x + ns.yyyy;
300
+ vec4 y = y_ *ns.x + ns.yyyy;
301
+ vec4 h = 1.0 - abs(x) - abs(y);
302
+
303
+ vec4 b0 = vec4( x.xy, y.xy );
304
+ vec4 b1 = vec4( x.zw, y.zw );
305
+
306
+ vec4 s0 = floor(b0)*2.0 + 1.0;
307
+ vec4 s1 = floor(b1)*2.0 + 1.0;
308
+ vec4 sh = -step(h, vec4(0.0));
309
+
310
+ vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
311
+ vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
312
+
313
+ vec3 p0 = vec3(a0.xy,h.x);
314
+ vec3 p1 = vec3(a0.zw,h.y);
315
+ vec3 p2 = vec3(a1.xy,h.z);
316
+ vec3 p3 = vec3(a1.zw,h.w);
317
+
318
+ // Normalise gradients
319
+ vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
320
+ p0 *= norm.x;
321
+ p1 *= norm.y;
322
+ p2 *= norm.z;
323
+ p3 *= norm.w;
324
+
325
+ // Mix final noise value
326
+ vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
327
+ m = m * m;
328
+ return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
329
+ dot(p2,x2), dot(p3,x3) ) );
330
+ }
331
+
332
+ // Classic Perlin noise
333
+ float cnoise(vec3 P)
334
+ {
335
+ vec3 Pi0 = floor(P);
336
+ vec3 Pi1 = Pi0 + vec3(1.0);
337
+
338
+ vec3 Pf0 = fract(P);
339
+ vec3 Pf1 = Pf0 - vec3(1.0);
340
+ vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
341
+ vec4 iy = vec4(Pi0.yy, Pi1.yy);
342
+ vec4 iz0 = Pi0.zzzz;
343
+ vec4 iz1 = Pi1.zzzz;
344
+
345
+ vec4 ixy = permute(permute(ix) + iy);
346
+ vec4 ixy0 = permute(ixy + iz0);
347
+ vec4 ixy1 = permute(ixy + iz1);
348
+
349
+ vec4 gx0 = ixy0 * (1.0 / 7.0);
350
+ vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;
351
+ gx0 = fract(gx0);
352
+ vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);
353
+ vec4 sz0 = step(gz0, vec4(0.0));
354
+ gx0 -= sz0 * (step(0.0, gx0) - 0.5);
355
+ gy0 -= sz0 * (step(0.0, gy0) - 0.5);
356
+
357
+ vec4 gx1 = ixy1 * (1.0 / 7.0);
358
+ vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;
359
+ gx1 = fract(gx1);
360
+ vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);
361
+ vec4 sz1 = step(gz1, vec4(0.0));
362
+ gx1 -= sz1 * (step(0.0, gx1) - 0.5);
363
+ gy1 -= sz1 * (step(0.0, gy1) - 0.5);
364
+
365
+ vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);
366
+ vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);
367
+ vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);
368
+ vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);
369
+ vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);
370
+ vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);
371
+ vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);
372
+ vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);
373
+
374
+ vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
375
+ g000 *= norm0.x;
376
+ g010 *= norm0.y;
377
+ g100 *= norm0.z;
378
+ g110 *= norm0.w;
379
+ vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
380
+ g001 *= norm1.x;
381
+ g011 *= norm1.y;
382
+ g101 *= norm1.z;
383
+ g111 *= norm1.w;
384
+
385
+ float n000 = dot(g000, Pf0);
386
+ float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));
387
+ float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));
388
+ float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));
389
+ float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));
390
+ float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));
391
+ float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));
392
+ float n111 = dot(g111, Pf1);
393
+
394
+ vec3 fade_xyz = fade(Pf0);
395
+ vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);
396
+ vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);
397
+ float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
398
+ return 2.2 * n_xyz;
399
+ }
400
+ `;
401
+ }
402
+
403
+ export function buildColorFunctions(): string {
404
+ return `
405
+ vec3 saturation(vec3 rgb, float adjustment) {
406
+ const vec3 W = vec3(0.2125, 0.7154, 0.0721);
407
+ vec3 intensity = vec3(dot(rgb, W));
408
+ return mix(intensity, rgb, adjustment);
409
+ }
410
+ `;
411
+ }
package/src/types.ts ADDED
@@ -0,0 +1,54 @@
1
+ export type NeatConfig = {
2
+ resolution?: number;
3
+ speed?: number;
4
+ horizontalPressure?: number;
5
+ verticalPressure?: number;
6
+ waveFrequencyX?: number;
7
+ waveFrequencyY?: number;
8
+ waveAmplitude?: number;
9
+ highlights?: number;
10
+ shadows?: number;
11
+ colorSaturation?: number;
12
+ colorBrightness?: number;
13
+ colors: NeatColor[];
14
+ colorBlending?: number;
15
+ grainScale?: number;
16
+ grainIntensity?: number;
17
+ grainSparsity?: number;
18
+ grainSpeed?: number;
19
+ wireframe?: boolean;
20
+ backgroundColor?: string;
21
+ backgroundAlpha?: number;
22
+ yOffset?: number;
23
+ yOffsetWaveMultiplier?: number;
24
+ yOffsetColorMultiplier?: number;
25
+ yOffsetFlowMultiplier?: number;
26
+ flowDistortionA?: number;
27
+ flowDistortionB?: number;
28
+ flowScale?: number;
29
+ flowEase?: number;
30
+ flowEnabled?: boolean;
31
+ enableProceduralTexture?: boolean;
32
+ textureVoidLikelihood?: number;
33
+ textureVoidWidthMin?: number;
34
+ textureVoidWidthMax?: number;
35
+ textureBandDensity?: number;
36
+ textureColorBlending?: number;
37
+ textureSeed?: number;
38
+ textureEase?: number;
39
+ proceduralBackgroundColor?: string;
40
+ textureShapeTriangles?: number;
41
+ textureShapeCircles?: number;
42
+ textureShapeBars?: number;
43
+ textureShapeSquiggles?: number;
44
+ };
45
+
46
+ export type NeatColor = {
47
+ color: string;
48
+ enabled: boolean;
49
+ influence?: number;
50
+ }
51
+
52
+ export type NeatController = {
53
+ destroy: () => void;
54
+ }