vireuikit 0.4.0 → 0.5.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/NOTICE +2 -5
- package/README.md +4 -84
- package/dist/index.cjs +0 -1143
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -96
- package/dist/index.d.ts +1 -96
- package/dist/index.js +1 -1
- package/package.json +2 -14
- package/dist/chunk-VY22O2II.js +0 -1148
- package/dist/chunk-VY22O2II.js.map +0 -1
- package/dist/dynamics-DqGk_f1n.d.cts +0 -415
- package/dist/dynamics-DqGk_f1n.d.ts +0 -415
- package/dist/web/index.cjs +0 -1865
- package/dist/web/index.cjs.map +0 -1
- package/dist/web/index.d.cts +0 -152
- package/dist/web/index.d.ts +0 -152
- package/dist/web/index.js +0 -899
- package/dist/web/index.js.map +0 -1
package/dist/chunk-VY22O2II.js
DELETED
|
@@ -1,1148 +0,0 @@
|
|
|
1
|
-
// src/medium/oklab.ts
|
|
2
|
-
var LINEAR_TO_LMS = [
|
|
3
|
-
[0.4122214708, 0.5363325363, 0.0514459929],
|
|
4
|
-
[0.2119034982, 0.6806995451, 0.1073969566],
|
|
5
|
-
[0.0883024619, 0.2817188376, 0.6299787005]
|
|
6
|
-
];
|
|
7
|
-
var LMS_TO_OKLAB = [
|
|
8
|
-
[0.2104542553, 0.793617785, -0.0040720468],
|
|
9
|
-
[1.9779984951, -2.428592205, 0.4505937099],
|
|
10
|
-
[0.0259040371, 0.7827717662, -0.808675766]
|
|
11
|
-
];
|
|
12
|
-
var OKLAB_TO_LMS = [
|
|
13
|
-
[1, 0.3963377774, 0.2158037573],
|
|
14
|
-
[1, -0.1055613458, -0.0638541728],
|
|
15
|
-
[1, -0.0894841775, -1.291485548]
|
|
16
|
-
];
|
|
17
|
-
var LMS_TO_LINEAR = [
|
|
18
|
-
[4.0767416621, -3.3077115913, 0.2309699292],
|
|
19
|
-
[-1.2684380046, 2.6097574011, -0.3413193965],
|
|
20
|
-
[-0.0041960863, -0.7034186147, 1.707614701]
|
|
21
|
-
];
|
|
22
|
-
var glsl = (v) => Number.isInteger(v) ? v.toFixed(1) : String(v);
|
|
23
|
-
var row = (m, i, vars) => m[i].map((k, j) => `${glsl(k)} * ${vars[j]}`).join(" + ");
|
|
24
|
-
var VG_OKLAB_TO_SRGB = `
|
|
25
|
-
float3 vgLinearToSrgb(float3 c) {
|
|
26
|
-
float3 lo = c * 12.92;
|
|
27
|
-
float3 hi = 1.055 * pow(max(c, float3(0.0)), float3(1.0 / 2.4)) - 0.055;
|
|
28
|
-
return mix(lo, hi, step(float3(0.0031308), c));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
float3 vgOklabToLinear(float3 lab) {
|
|
32
|
-
float l_ = ${row(OKLAB_TO_LMS, 0, ["lab.x", "lab.y", "lab.z"])};
|
|
33
|
-
float m_ = ${row(OKLAB_TO_LMS, 1, ["lab.x", "lab.y", "lab.z"])};
|
|
34
|
-
float s_ = ${row(OKLAB_TO_LMS, 2, ["lab.x", "lab.y", "lab.z"])};
|
|
35
|
-
float l = l_ * l_ * l_;
|
|
36
|
-
float m = m_ * m_ * m_;
|
|
37
|
-
float s = s_ * s_ * s_;
|
|
38
|
-
return float3(
|
|
39
|
-
${row(LMS_TO_LINEAR, 0, ["l", "m", "s"])},
|
|
40
|
-
${row(LMS_TO_LINEAR, 1, ["l", "m", "s"])},
|
|
41
|
-
${row(LMS_TO_LINEAR, 2, ["l", "m", "s"])}
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
`;
|
|
45
|
-
var apply = (m, v) => [
|
|
46
|
-
m[0][0] * v[0] + m[0][1] * v[1] + m[0][2] * v[2],
|
|
47
|
-
m[1][0] * v[0] + m[1][1] * v[1] + m[1][2] * v[2],
|
|
48
|
-
m[2][0] * v[0] + m[2][1] * v[1] + m[2][2] * v[2]
|
|
49
|
-
];
|
|
50
|
-
var srgbChannelToLinear = (c) => c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
51
|
-
var linearChannelToSrgb = (c) => c <= 31308e-7 ? c * 12.92 : 1.055 * Math.pow(Math.max(c, 0), 1 / 2.4) - 0.055;
|
|
52
|
-
function srgbToOklab(rgb) {
|
|
53
|
-
const linear = rgb.map(srgbChannelToLinear);
|
|
54
|
-
const lms = apply(LINEAR_TO_LMS, linear);
|
|
55
|
-
return apply(LMS_TO_OKLAB, lms.map((v) => Math.cbrt(Math.max(v, 0))));
|
|
56
|
-
}
|
|
57
|
-
function oklabToSrgb(lab) {
|
|
58
|
-
const lms = apply(OKLAB_TO_LMS, lab).map((v) => v * v * v);
|
|
59
|
-
return apply(LMS_TO_LINEAR, lms).map(linearChannelToSrgb);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// src/medium/species.ts
|
|
63
|
-
var MEDIUM_SPECIES_LIGHTNESS = 0.44;
|
|
64
|
-
var MEDIUM_SPECIES_HUE_SPREAD = 32;
|
|
65
|
-
var clamp01 = (v) => Math.min(1, Math.max(0, v));
|
|
66
|
-
function characterOf(color) {
|
|
67
|
-
const [lightness, a, b] = srgbToOklab(color);
|
|
68
|
-
return {
|
|
69
|
-
hue: Math.atan2(b, a) * 180 / Math.PI,
|
|
70
|
-
chroma: Math.hypot(a, b),
|
|
71
|
-
lightness
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function speciesFamily(character, spreadDeg = MEDIUM_SPECIES_HUE_SPREAD) {
|
|
75
|
-
const { hue, chroma, lightness } = character;
|
|
76
|
-
const tone = (deg) => {
|
|
77
|
-
const rad = deg * Math.PI / 180;
|
|
78
|
-
return oklabToSrgb([lightness, chroma * Math.cos(rad), chroma * Math.sin(rad)]).map(
|
|
79
|
-
clamp01
|
|
80
|
-
);
|
|
81
|
-
};
|
|
82
|
-
return [tone(hue - spreadDeg), tone(hue), tone(hue + spreadDeg)];
|
|
83
|
-
}
|
|
84
|
-
function neutralSpecies(baseColor) {
|
|
85
|
-
const { hue, chroma } = characterOf(baseColor);
|
|
86
|
-
return speciesFamily({ hue, chroma, lightness: MEDIUM_SPECIES_LIGHTNESS });
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// src/medium/params.ts
|
|
90
|
-
var MEDIUM_MAX_LIGHTS = 3;
|
|
91
|
-
var BASE_COLOR = [0.07, 0.08, 0.1];
|
|
92
|
-
var normalize2 = (v) => {
|
|
93
|
-
const len = Math.hypot(v[0], v[1]) || 1;
|
|
94
|
-
return [v[0] / len, v[1] / len];
|
|
95
|
-
};
|
|
96
|
-
var MEDIUM_DEFAULT_LIGHT_COLOR = [0.78, 0.85, 0.94];
|
|
97
|
-
var MEDIUM_DEFAULT_LIGHTS = [
|
|
98
|
-
{
|
|
99
|
-
position: [0.5, 0],
|
|
100
|
-
direction: [0, 1],
|
|
101
|
-
coneAngle: Math.PI,
|
|
102
|
-
falloff: 16,
|
|
103
|
-
color: MEDIUM_DEFAULT_LIGHT_COLOR,
|
|
104
|
-
intensity: 0.28
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
position: [0.12, 1.45],
|
|
108
|
-
direction: normalize2([0.38, -1.03]),
|
|
109
|
-
coneAngle: 9 * Math.PI / 180,
|
|
110
|
-
falloff: 0.7,
|
|
111
|
-
color: MEDIUM_DEFAULT_LIGHT_COLOR,
|
|
112
|
-
intensity: 1.1
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
position: [0.9, 1.4],
|
|
116
|
-
direction: normalize2([-0.4, -0.98]),
|
|
117
|
-
coneAngle: 8 * Math.PI / 180,
|
|
118
|
-
falloff: 0.75,
|
|
119
|
-
color: MEDIUM_DEFAULT_LIGHT_COLOR,
|
|
120
|
-
intensity: 0.9
|
|
121
|
-
}
|
|
122
|
-
];
|
|
123
|
-
var MEDIUM_DEFAULTS = {
|
|
124
|
-
// A stamped track has to visibly broaden and fade within the reference's "roughly one to two
|
|
125
|
-
// seconds", not the ~11s half-life a 0.06 decay gives — measured against check-medium.mjs's track
|
|
126
|
-
// gate (birth vs +1.5s cross-section width and total density): 1.1 leaves ~30% of the peak at 1s
|
|
127
|
-
// and ~17% at 1.5s, comfortably faded without dying before MacCormack's own diffusion has time to
|
|
128
|
-
// visibly broaden the stamp.
|
|
129
|
-
decay: 1.1,
|
|
130
|
-
curlFreq: 0.045,
|
|
131
|
-
curlSpeed: 0.12,
|
|
132
|
-
advectSpeed: 26,
|
|
133
|
-
turbulence: 1,
|
|
134
|
-
condensationRate: 0.18,
|
|
135
|
-
condensationFloor: 0.12,
|
|
136
|
-
evaporationRate: 0.2,
|
|
137
|
-
condensateSettleSpeed: 8,
|
|
138
|
-
condensateSettleWiggle: 0.4,
|
|
139
|
-
condensateSpreadRate: 0.08,
|
|
140
|
-
condensateTint: 0.2,
|
|
141
|
-
condensateGain: 5,
|
|
142
|
-
condensateColor: [0.94, 0.95, 0.97],
|
|
143
|
-
channelColors: neutralSpecies(BASE_COLOR),
|
|
144
|
-
channelScatter: [1, 1, 1],
|
|
145
|
-
baseColor: BASE_COLOR,
|
|
146
|
-
baseWeight: 0.9,
|
|
147
|
-
depthFarScale: 1.6,
|
|
148
|
-
depthFarOffsetFrac: [0.47, 0.53],
|
|
149
|
-
depthFarBlurRadius: 5,
|
|
150
|
-
depthFarWeight: 0.5,
|
|
151
|
-
gravityVaporDrift: 0.6,
|
|
152
|
-
gravityBottomBoost: 2,
|
|
153
|
-
gravityBottomBoostStart: 0.75,
|
|
154
|
-
lights: MEDIUM_DEFAULT_LIGHTS,
|
|
155
|
-
shadowExtinction: 3,
|
|
156
|
-
trackLightFloor: 0.8,
|
|
157
|
-
trackLayerAmount: 1
|
|
158
|
-
};
|
|
159
|
-
function depthFarOffsetPx(offsetFrac, gridWidth, gridHeight) {
|
|
160
|
-
return [offsetFrac[0] * gridWidth, offsetFrac[1] * gridHeight];
|
|
161
|
-
}
|
|
162
|
-
function wrappedDistanceFromZero(value, period) {
|
|
163
|
-
const wrapped = (value % period + period) % period;
|
|
164
|
-
return Math.min(wrapped, period - wrapped);
|
|
165
|
-
}
|
|
166
|
-
var MEDIUM_PROBE_FLOOR_PX = 22;
|
|
167
|
-
var MEDIUM_DEFAULT_CELL_PX = 26;
|
|
168
|
-
var MEDIUM_TRACK_PRESETS = {
|
|
169
|
-
alpha: {
|
|
170
|
-
lengthFrac: 0.22,
|
|
171
|
-
headWidthFrac: 0.05,
|
|
172
|
-
tailWidthFrac: 0.12,
|
|
173
|
-
raggedFrac: 0,
|
|
174
|
-
raggedFreq: 0,
|
|
175
|
-
settleFrac: 0.02,
|
|
176
|
-
tailDim: 0.55,
|
|
177
|
-
intensity: 1.15
|
|
178
|
-
},
|
|
179
|
-
electron: {
|
|
180
|
-
lengthFrac: 0.42,
|
|
181
|
-
headWidthFrac: 0.018,
|
|
182
|
-
tailWidthFrac: 0.05,
|
|
183
|
-
raggedFrac: 0.045,
|
|
184
|
-
raggedFreq: 5,
|
|
185
|
-
settleFrac: 0.05,
|
|
186
|
-
tailDim: 0.45,
|
|
187
|
-
intensity: 0.6
|
|
188
|
-
},
|
|
189
|
-
muon: {
|
|
190
|
-
lengthFrac: 0.7,
|
|
191
|
-
headWidthFrac: 0.012,
|
|
192
|
-
tailWidthFrac: 0.02,
|
|
193
|
-
raggedFrac: 0,
|
|
194
|
-
raggedFreq: 0,
|
|
195
|
-
settleFrac: 0.01,
|
|
196
|
-
tailDim: 0.75,
|
|
197
|
-
intensity: 0.5
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
var MEDIUM_DRIFT_TURBULENCE = 0.045;
|
|
201
|
-
var MEDIUM_PLAYING_TURBULENCE_RANGE = [0.55, 1.15];
|
|
202
|
-
var MEDIUM_TURBULENCE_TAU = 2.5;
|
|
203
|
-
var MEDIUM_EMISSION_BEATS = 4;
|
|
204
|
-
var MEDIUM_EMISSION_PROBABILITY = 0.55;
|
|
205
|
-
var MEDIUM_MIN_EMISSION_INTERVAL = 1.2;
|
|
206
|
-
var MEDIUM_NATURAL_INTERVAL = 8;
|
|
207
|
-
var MEDIUM_NATURAL_JITTER = 12;
|
|
208
|
-
var MEDIUM_SENSITIVE_TOP = 0.55;
|
|
209
|
-
var MEDIUM_SENSITIVE_BOTTOM = 0.95;
|
|
210
|
-
var MEDIUM_ALPHA_BURST_RAYS = [8, 16];
|
|
211
|
-
var MEDIUM_ALPHA_RAY_LENGTH_SCALE = [0.55, 1];
|
|
212
|
-
var MEDIUM_TRACK_DEPTH_WIDTH_RANGE = [0.55, 1.2];
|
|
213
|
-
var MEDIUM_TRACK_DEPTH_INTENSITY_RANGE = [0.4, 1];
|
|
214
|
-
var MEDIUM_TRACK_LAYER_LIFE_SECONDS = {
|
|
215
|
-
alpha: 1.8,
|
|
216
|
-
electron: 1.4,
|
|
217
|
-
muon: 2.2
|
|
218
|
-
};
|
|
219
|
-
var MEDIUM_TRACK_LAYER_MAX_TRACKS = 64;
|
|
220
|
-
var MEDIUM_TRACK_LAYER_LOOK = {
|
|
221
|
-
alpha: {
|
|
222
|
-
sigmaFrac: 22e-4,
|
|
223
|
-
endSigmaMul: 1.9,
|
|
224
|
-
broaden: 3.2,
|
|
225
|
-
wiggleFrac: 0,
|
|
226
|
-
beadFrac: 6e-3,
|
|
227
|
-
dropletFrac: 35e-4,
|
|
228
|
-
dropletChance: 0.5,
|
|
229
|
-
startFrac: 0.035,
|
|
230
|
-
gain: 1.8
|
|
231
|
-
},
|
|
232
|
-
electron: {
|
|
233
|
-
sigmaFrac: 9e-4,
|
|
234
|
-
endSigmaMul: 1.3,
|
|
235
|
-
broaden: 6,
|
|
236
|
-
wiggleFrac: 0.012,
|
|
237
|
-
beadFrac: 8e-3,
|
|
238
|
-
dropletFrac: 6e-3,
|
|
239
|
-
dropletChance: 0.55,
|
|
240
|
-
startFrac: 0,
|
|
241
|
-
gain: 2.2
|
|
242
|
-
},
|
|
243
|
-
muon: {
|
|
244
|
-
sigmaFrac: 8e-4,
|
|
245
|
-
endSigmaMul: 1,
|
|
246
|
-
broaden: 5,
|
|
247
|
-
wiggleFrac: 0,
|
|
248
|
-
beadFrac: 7e-3,
|
|
249
|
-
dropletFrac: 5e-3,
|
|
250
|
-
dropletChance: 0.5,
|
|
251
|
-
startFrac: 0,
|
|
252
|
-
gain: 2.2
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
var MEDIUM_TRACK_LAYER_BURST_SPREAD = 1.6;
|
|
256
|
-
var MEDIUM_TRACK_LAYER_BURST_ACCENT = 3;
|
|
257
|
-
var MEDIUM_TRACK_LAYER_FADE_GAMMA = 1.6;
|
|
258
|
-
var MEDIUM_TRACK_LAYER_GRAVITY_SAG = 0.018;
|
|
259
|
-
var MEDIUM_TRACK_LAYER_CURL_PUSH = 0.05;
|
|
260
|
-
|
|
261
|
-
// src/medium/noise.ts
|
|
262
|
-
var VG_VALUE_NOISE = `
|
|
263
|
-
float vgHash21(float2 p) {
|
|
264
|
-
float h = dot(p, float2(127.1, 311.7));
|
|
265
|
-
return fract(sin(h) * 43758.5453123);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
float vgValueNoise(float2 p) {
|
|
269
|
-
float2 i = floor(p);
|
|
270
|
-
float2 f = fract(p);
|
|
271
|
-
float a = vgHash21(i);
|
|
272
|
-
float b = vgHash21(i + float2(1.0, 0.0));
|
|
273
|
-
float c = vgHash21(i + float2(0.0, 1.0));
|
|
274
|
-
float d = vgHash21(i + float2(1.0, 1.0));
|
|
275
|
-
float2 u = f * f * (3.0 - 2.0 * f);
|
|
276
|
-
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y) * 2.0 - 1.0;
|
|
277
|
-
}
|
|
278
|
-
`;
|
|
279
|
-
var glslFloat = (v) => Number.isInteger(v) ? v.toFixed(1) : String(v);
|
|
280
|
-
var MEDIUM_TIME_PERIOD = 1e3;
|
|
281
|
-
var MEDIUM_TIME_OCTAVES = [
|
|
282
|
-
{ rate: 0.6, offset: 0, scale: 1 },
|
|
283
|
-
{ rate: 1.7, offset: 11, scale: 2.03 },
|
|
284
|
-
{ rate: 0.9, offset: 37, scale: 4.11 },
|
|
285
|
-
{ rate: 0.15, offset: 5, scale: 0.35 }
|
|
286
|
-
];
|
|
287
|
-
function mediumOctavePeriod(rate) {
|
|
288
|
-
const period = rate * MEDIUM_TIME_PERIOD;
|
|
289
|
-
if (!Number.isInteger(period)) {
|
|
290
|
-
throw new Error(
|
|
291
|
-
`medium noise: octave rate ${rate} * MEDIUM_TIME_PERIOD ${MEDIUM_TIME_PERIOD} = ${period}, not an integer \u2014 the phase wrap would not be seamless`
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
return period;
|
|
295
|
-
}
|
|
296
|
-
var glslOctave = (o) => ({
|
|
297
|
-
rate: glslFloat(o.rate),
|
|
298
|
-
offset: glslFloat(o.offset),
|
|
299
|
-
scale: glslFloat(o.scale),
|
|
300
|
-
period: glslFloat(mediumOctavePeriod(o.rate))
|
|
301
|
-
});
|
|
302
|
-
var [VG_OCT0, VG_OCT1, VG_OCT2, VG_OCT3] = MEDIUM_TIME_OCTAVES.map(glslOctave);
|
|
303
|
-
var VG_CURL_NOISE = `
|
|
304
|
-
${VG_VALUE_NOISE}
|
|
305
|
-
|
|
306
|
-
float vgHash31(float3 p) {
|
|
307
|
-
float h = dot(p, float3(127.1, 311.7, 74.7));
|
|
308
|
-
return fract(sin(h) * 43758.5453123);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// 3D value-noise: time is a third grid axis, not a coordinate shift. A shift would just SLIDE the
|
|
312
|
-
// pattern (a "traveling" look, when motion is meant to read as random), while trilinear
|
|
313
|
-
// interpolation over t CHANGES the pattern itself between grid nodes \u2014 nearby moments look alike,
|
|
314
|
-
// distant ones don't, and no repeat ever shows up.
|
|
315
|
-
float vgValueNoise3(float3 p) {
|
|
316
|
-
float3 i = floor(p);
|
|
317
|
-
float3 f = fract(p);
|
|
318
|
-
float3 u = f * f * (3.0 - 2.0 * f);
|
|
319
|
-
float n000 = vgHash31(i);
|
|
320
|
-
float n100 = vgHash31(i + float3(1.0, 0.0, 0.0));
|
|
321
|
-
float n010 = vgHash31(i + float3(0.0, 1.0, 0.0));
|
|
322
|
-
float n110 = vgHash31(i + float3(1.0, 1.0, 0.0));
|
|
323
|
-
float n001 = vgHash31(i + float3(0.0, 0.0, 1.0));
|
|
324
|
-
float n101 = vgHash31(i + float3(1.0, 0.0, 1.0));
|
|
325
|
-
float n011 = vgHash31(i + float3(0.0, 1.0, 1.0));
|
|
326
|
-
float n111 = vgHash31(i + float3(1.0, 1.0, 1.0));
|
|
327
|
-
float nx00 = mix(n000, n100, u.x);
|
|
328
|
-
float nx10 = mix(n010, n110, u.x);
|
|
329
|
-
float nx01 = mix(n001, n101, u.x);
|
|
330
|
-
float nx11 = mix(n011, n111, u.x);
|
|
331
|
-
float nxy0 = mix(nx00, nx10, u.y);
|
|
332
|
-
float nxy1 = mix(nx01, nx11, u.y);
|
|
333
|
-
return mix(nxy0, nxy1, u.z) * 2.0 - 1.0;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// Same as vgValueNoise3, but the z axis wraps at \`period\`: BOTH z-lattice neighbors (i.z and
|
|
337
|
-
// i.z + 1.0) are folded into [0, period) before hashing, so this is EXACTLY the same function of
|
|
338
|
-
// z and of z + period \u2014 not just close. vgPotential below calls this once per octave, each with
|
|
339
|
-
// the period matching its own rate (MEDIUM_TIME_OCTAVES), so a phase that wraps at
|
|
340
|
-
// MEDIUM_TIME_PERIOD reproduces the identical field instead of jumping to a new one.
|
|
341
|
-
float vgValueNoise3Periodic(float3 p, float period) {
|
|
342
|
-
float3 i = floor(p);
|
|
343
|
-
float3 f = fract(p);
|
|
344
|
-
float3 u = f * f * (3.0 - 2.0 * f);
|
|
345
|
-
float z0 = mod(i.z, period);
|
|
346
|
-
float z1 = mod(i.z + 1.0, period);
|
|
347
|
-
float n000 = vgHash31(float3(i.xy, z0));
|
|
348
|
-
float n100 = vgHash31(float3(i.xy + float2(1.0, 0.0), z0));
|
|
349
|
-
float n010 = vgHash31(float3(i.xy + float2(0.0, 1.0), z0));
|
|
350
|
-
float n110 = vgHash31(float3(i.xy + float2(1.0, 1.0), z0));
|
|
351
|
-
float n001 = vgHash31(float3(i.xy, z1));
|
|
352
|
-
float n101 = vgHash31(float3(i.xy + float2(1.0, 0.0), z1));
|
|
353
|
-
float n011 = vgHash31(float3(i.xy + float2(0.0, 1.0), z1));
|
|
354
|
-
float n111 = vgHash31(float3(i.xy + float2(1.0, 1.0), z1));
|
|
355
|
-
float nx00 = mix(n000, n100, u.x);
|
|
356
|
-
float nx10 = mix(n010, n110, u.x);
|
|
357
|
-
float nx01 = mix(n001, n101, u.x);
|
|
358
|
-
float nx11 = mix(n011, n111, u.x);
|
|
359
|
-
float nxy0 = mix(nx00, nx10, u.y);
|
|
360
|
-
float nxy1 = mix(nx01, nx11, u.y);
|
|
361
|
-
return mix(nxy0, nxy1, u.z) * 2.0 - 1.0;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// The potential is an fbm of three octaves, each evolving over the field's PHASE at its own speed
|
|
365
|
-
// (unrelated to the others, plus a phase offset): no single phase shift can align them all at
|
|
366
|
-
// once, so no traveling pattern remains. Each octave wraps its own z-lattice at the period that
|
|
367
|
-
// matches its rate (see MEDIUM_TIME_OCTAVES/vgValueNoise3Periodic), so
|
|
368
|
-
// vgPotential(p, phase) === vgPotential(p, phase + ${glslFloat(MEDIUM_TIME_PERIOD)}) exactly \u2014 a
|
|
369
|
-
// CPU-side phase accumulator can wrap at that period with no visible jump (see web/medium.ts). The
|
|
370
|
-
// large-scale factor is a slow non-uniformity layered over the sum \u2014 without it, a field that's
|
|
371
|
-
// uniform by statistics still reads as a regular cell pattern.
|
|
372
|
-
float vgPotential(float2 p, float phase) {
|
|
373
|
-
float v = vgValueNoise3Periodic(float3(p * ${VG_OCT0.scale}, phase * ${VG_OCT0.rate} + ${VG_OCT0.offset}), ${VG_OCT0.period}) * 0.5;
|
|
374
|
-
v += vgValueNoise3Periodic(float3(p * ${VG_OCT1.scale}, phase * ${VG_OCT1.rate} + ${VG_OCT1.offset}), ${VG_OCT1.period}) * 0.25;
|
|
375
|
-
v += vgValueNoise3Periodic(float3(p * ${VG_OCT2.scale}, phase * ${VG_OCT2.rate} + ${VG_OCT2.offset}), ${VG_OCT2.period}) * 0.125;
|
|
376
|
-
float macro = vgValueNoise3Periodic(float3(p * ${VG_OCT3.scale}, phase * ${VG_OCT3.rate} + ${VG_OCT3.offset}), ${VG_OCT3.period});
|
|
377
|
-
return v * (0.7 + 0.3 * macro);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// Velocity = (dPsi/dy, -dPsi/dx) \u2014 the curl of a scalar field, solenoidal for any Psi. Central
|
|
381
|
-
// differences instead of an analytic derivative: the potential is a sum of three value-noise
|
|
382
|
-
// calls, and there is no cheaper way to differentiate it by hand than four extra samples.
|
|
383
|
-
float2 vgCurlVelocity(float2 p, float phase) {
|
|
384
|
-
float e = 0.6;
|
|
385
|
-
float px1 = vgPotential(p + float2(e, 0.0), phase);
|
|
386
|
-
float px0 = vgPotential(p - float2(e, 0.0), phase);
|
|
387
|
-
float py1 = vgPotential(p + float2(0.0, e), phase);
|
|
388
|
-
float py0 = vgPotential(p - float2(0.0, e), phase);
|
|
389
|
-
return float2(py1 - py0, -(px1 - px0)) / (2.0 * e);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// vgPotential above is periodic in TIME only: the simulation domain is a torus (gl.REPEAT), but
|
|
393
|
-
// the lattice itself never wraps in x/y, so velocity jumps at the domain seam and dye on either
|
|
394
|
-
// side of it is transported differently \u2014 a straight seam, made worse wherever something re-reads
|
|
395
|
-
// the field at a different scale (the far depth plane's tile boundary). vgValueNoise3Seamless
|
|
396
|
-
// wraps ALL THREE lattice axes: xyPeriod/zPeriod fold BOTH neighbors of a cell into their own
|
|
397
|
-
// period before hashing, so the field is EXACTLY the same one period over, in space exactly as it
|
|
398
|
-
// already was in time.
|
|
399
|
-
//
|
|
400
|
-
// The period has to be an integer number of lattice cells, or the wrap would jump instead of
|
|
401
|
-
// closing seamlessly (the same requirement MEDIUM_TIME_OCTAVES/mediumOctavePeriod enforces for
|
|
402
|
-
// time) \u2014 but unlike time, the spatial period depends on the GRID SIZE, which this shader has no
|
|
403
|
-
// notion of. So xyPeriod travels together with a per-octave spatial frequency the CPU computes to
|
|
404
|
-
// make gridSize * frequency land on that exact integer (see computeMediumSpatialPeriods below);
|
|
405
|
-
// both arrive together as one uniform per octave (u_spatialN.xy = frequency, .zw = period),
|
|
406
|
-
// recomputed by web/medium.ts whenever the grid resizes.
|
|
407
|
-
float vgValueNoise3Seamless(float3 p, float2 xyPeriod, float zPeriod) {
|
|
408
|
-
float3 i = floor(p);
|
|
409
|
-
float3 f = fract(p);
|
|
410
|
-
float3 u = f * f * (3.0 - 2.0 * f);
|
|
411
|
-
float x0 = mod(i.x, xyPeriod.x);
|
|
412
|
-
float x1 = mod(i.x + 1.0, xyPeriod.x);
|
|
413
|
-
float y0 = mod(i.y, xyPeriod.y);
|
|
414
|
-
float y1 = mod(i.y + 1.0, xyPeriod.y);
|
|
415
|
-
float z0 = mod(i.z, zPeriod);
|
|
416
|
-
float z1 = mod(i.z + 1.0, zPeriod);
|
|
417
|
-
float n000 = vgHash31(float3(x0, y0, z0));
|
|
418
|
-
float n100 = vgHash31(float3(x1, y0, z0));
|
|
419
|
-
float n010 = vgHash31(float3(x0, y1, z0));
|
|
420
|
-
float n110 = vgHash31(float3(x1, y1, z0));
|
|
421
|
-
float n001 = vgHash31(float3(x0, y0, z1));
|
|
422
|
-
float n101 = vgHash31(float3(x1, y0, z1));
|
|
423
|
-
float n011 = vgHash31(float3(x0, y1, z1));
|
|
424
|
-
float n111 = vgHash31(float3(x1, y1, z1));
|
|
425
|
-
float nx00 = mix(n000, n100, u.x);
|
|
426
|
-
float nx10 = mix(n010, n110, u.x);
|
|
427
|
-
float nx01 = mix(n001, n101, u.x);
|
|
428
|
-
float nx11 = mix(n011, n111, u.x);
|
|
429
|
-
float nxy0 = mix(nx00, nx10, u.y);
|
|
430
|
-
float nxy1 = mix(nx01, nx11, u.y);
|
|
431
|
-
return mix(nxy0, nxy1, u.z) * 2.0 - 1.0;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// Same four-octave fbm as vgPotential, but every octave reads the seamless lattice above at its
|
|
435
|
-
// OWN (frequency, period) pair \u2014 sN.xy replaces that octave's compile-time \`scale\` constant (it
|
|
436
|
-
// has to be a uniform now: the adjustment depends on the live grid size), sN.zw is the matching
|
|
437
|
-
// integer period. \`p\` is still curlFreq-scaled exactly as vgPotential's caller scales it \u2014 only
|
|
438
|
-
// the per-octave multiplier changed from a constant to a grid-dependent uniform, so the finite
|
|
439
|
-
// difference in vgCurlVelocitySeamless below needs no epsilon change of its own.
|
|
440
|
-
float vgPotentialSeamless(float2 p, float phase, float4 s0, float4 s1, float4 s2, float4 s3) {
|
|
441
|
-
float v = vgValueNoise3Seamless(float3(p * s0.xy, phase * ${VG_OCT0.rate} + ${VG_OCT0.offset}), s0.zw, ${VG_OCT0.period}) * 0.5;
|
|
442
|
-
v += vgValueNoise3Seamless(float3(p * s1.xy, phase * ${VG_OCT1.rate} + ${VG_OCT1.offset}), s1.zw, ${VG_OCT1.period}) * 0.25;
|
|
443
|
-
v += vgValueNoise3Seamless(float3(p * s2.xy, phase * ${VG_OCT2.rate} + ${VG_OCT2.offset}), s2.zw, ${VG_OCT2.period}) * 0.125;
|
|
444
|
-
float macro = vgValueNoise3Seamless(float3(p * s3.xy, phase * ${VG_OCT3.rate} + ${VG_OCT3.offset}), s3.zw, ${VG_OCT3.period});
|
|
445
|
-
return v * (0.7 + 0.3 * macro);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
float2 vgCurlVelocitySeamless(float2 p, float phase, float4 s0, float4 s1, float4 s2, float4 s3) {
|
|
449
|
-
float e = 0.6;
|
|
450
|
-
float px1 = vgPotentialSeamless(p + float2(e, 0.0), phase, s0, s1, s2, s3);
|
|
451
|
-
float px0 = vgPotentialSeamless(p - float2(e, 0.0), phase, s0, s1, s2, s3);
|
|
452
|
-
float py1 = vgPotentialSeamless(p + float2(0.0, e), phase, s0, s1, s2, s3);
|
|
453
|
-
float py0 = vgPotentialSeamless(p - float2(0.0, e), phase, s0, s1, s2, s3);
|
|
454
|
-
return float2(py1 - py0, -(px1 - px0)) / (2.0 * e);
|
|
455
|
-
}
|
|
456
|
-
`;
|
|
457
|
-
function hash31JS(x, y, z) {
|
|
458
|
-
const h = x * 127.1 + y * 311.7 + z * 74.7;
|
|
459
|
-
const s = Math.sin(h) * 43758.5453123;
|
|
460
|
-
return s - Math.floor(s);
|
|
461
|
-
}
|
|
462
|
-
var smoothstep3JS = (f) => f * f * (3 - 2 * f);
|
|
463
|
-
var glslMod = (x, y) => x - y * Math.floor(x / y);
|
|
464
|
-
function vgValueNoise3PeriodicJS(px, py, pz, period) {
|
|
465
|
-
const ix = Math.floor(px);
|
|
466
|
-
const iy = Math.floor(py);
|
|
467
|
-
const iz = Math.floor(pz);
|
|
468
|
-
const ux = smoothstep3JS(px - ix);
|
|
469
|
-
const uy = smoothstep3JS(py - iy);
|
|
470
|
-
const uz = smoothstep3JS(pz - iz);
|
|
471
|
-
const z0 = glslMod(iz, period);
|
|
472
|
-
const z1 = glslMod(iz + 1, period);
|
|
473
|
-
const n000 = hash31JS(ix, iy, z0);
|
|
474
|
-
const n100 = hash31JS(ix + 1, iy, z0);
|
|
475
|
-
const n010 = hash31JS(ix, iy + 1, z0);
|
|
476
|
-
const n110 = hash31JS(ix + 1, iy + 1, z0);
|
|
477
|
-
const n001 = hash31JS(ix, iy, z1);
|
|
478
|
-
const n101 = hash31JS(ix + 1, iy, z1);
|
|
479
|
-
const n011 = hash31JS(ix, iy + 1, z1);
|
|
480
|
-
const n111 = hash31JS(ix + 1, iy + 1, z1);
|
|
481
|
-
const nx00 = n000 + (n100 - n000) * ux;
|
|
482
|
-
const nx10 = n010 + (n110 - n010) * ux;
|
|
483
|
-
const nx01 = n001 + (n101 - n001) * ux;
|
|
484
|
-
const nx11 = n011 + (n111 - n011) * ux;
|
|
485
|
-
const nxy0 = nx00 + (nx10 - nx00) * uy;
|
|
486
|
-
const nxy1 = nx01 + (nx11 - nx01) * uy;
|
|
487
|
-
return (nxy0 + (nxy1 - nxy0) * uz) * 2 - 1;
|
|
488
|
-
}
|
|
489
|
-
function vgPotentialJS(px, py, phase) {
|
|
490
|
-
const [o0, o1, o2, o3] = MEDIUM_TIME_OCTAVES;
|
|
491
|
-
let v = vgValueNoise3PeriodicJS(px * o0.scale, py * o0.scale, phase * o0.rate + o0.offset, mediumOctavePeriod(o0.rate)) * 0.5;
|
|
492
|
-
v += vgValueNoise3PeriodicJS(px * o1.scale, py * o1.scale, phase * o1.rate + o1.offset, mediumOctavePeriod(o1.rate)) * 0.25;
|
|
493
|
-
v += vgValueNoise3PeriodicJS(px * o2.scale, py * o2.scale, phase * o2.rate + o2.offset, mediumOctavePeriod(o2.rate)) * 0.125;
|
|
494
|
-
const macro = vgValueNoise3PeriodicJS(
|
|
495
|
-
px * o3.scale,
|
|
496
|
-
py * o3.scale,
|
|
497
|
-
phase * o3.rate + o3.offset,
|
|
498
|
-
mediumOctavePeriod(o3.rate)
|
|
499
|
-
);
|
|
500
|
-
return v * (0.7 + 0.3 * macro);
|
|
501
|
-
}
|
|
502
|
-
var MIN_SPATIAL_PERIOD = 2;
|
|
503
|
-
function computeMediumSpatialPeriods(gridWidth, gridHeight, curlFreq) {
|
|
504
|
-
const freq = Math.max(curlFreq, 1e-6);
|
|
505
|
-
return MEDIUM_TIME_OCTAVES.map((o) => {
|
|
506
|
-
const rawX = gridWidth * freq * o.scale;
|
|
507
|
-
const rawY = gridHeight * freq * o.scale;
|
|
508
|
-
const minRaw = Math.min(rawX, rawY);
|
|
509
|
-
const scaleUp = minRaw > 0 && minRaw < MIN_SPATIAL_PERIOD ? MIN_SPATIAL_PERIOD / minRaw : 1;
|
|
510
|
-
const periodX = Math.max(MIN_SPATIAL_PERIOD, Math.round(rawX * scaleUp));
|
|
511
|
-
const periodY = Math.max(MIN_SPATIAL_PERIOD, Math.round(rawY * scaleUp));
|
|
512
|
-
return {
|
|
513
|
-
freqX: periodX / (gridWidth * freq),
|
|
514
|
-
freqY: periodY / (gridHeight * freq),
|
|
515
|
-
periodX,
|
|
516
|
-
periodY
|
|
517
|
-
};
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
// src/medium/seed-shader.ts
|
|
522
|
-
var MEDIUM_SEED_SHADER = `
|
|
523
|
-
uniform float2 u_spot0;
|
|
524
|
-
uniform float2 u_spot1;
|
|
525
|
-
uniform float2 u_spot2;
|
|
526
|
-
uniform float u_spotRadius;
|
|
527
|
-
|
|
528
|
-
float vgSpot(float2 p, float2 c, float r) {
|
|
529
|
-
float d = length(p - c) / max(r, 1.0);
|
|
530
|
-
return exp(-d * d * 2.0);
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
half4 main(float2 xy) {
|
|
534
|
-
float3 dye = float3(
|
|
535
|
-
vgSpot(xy, u_spot0, u_spotRadius),
|
|
536
|
-
vgSpot(xy, u_spot1, u_spotRadius),
|
|
537
|
-
vgSpot(xy, u_spot2, u_spotRadius)
|
|
538
|
-
);
|
|
539
|
-
return half4(half3(dye), half(1.0));
|
|
540
|
-
}
|
|
541
|
-
`;
|
|
542
|
-
|
|
543
|
-
// src/medium/resample-shader.ts
|
|
544
|
-
var MEDIUM_RESAMPLE_SHADER = `
|
|
545
|
-
uniform shader u_src;
|
|
546
|
-
|
|
547
|
-
half4 main(float2 xy) {
|
|
548
|
-
float2 uv = xy / u_resolution;
|
|
549
|
-
float2 src = uv * u_srcSize;
|
|
550
|
-
return u_src.eval(float2(src.x, u_srcSize.y - src.y));
|
|
551
|
-
}
|
|
552
|
-
`;
|
|
553
|
-
|
|
554
|
-
// src/medium/advect-shader.ts
|
|
555
|
-
var MEDIUM_ADVECT_UNIFORMS = `
|
|
556
|
-
uniform shader u_dye;
|
|
557
|
-
uniform float u_dt;
|
|
558
|
-
uniform float u_phase;
|
|
559
|
-
uniform float u_curlFreq;
|
|
560
|
-
uniform float u_advectSpeed;
|
|
561
|
-
uniform float u_turbulence;
|
|
562
|
-
// One float4 per MEDIUM_TIME_OCTAVES entry: xy is that octave's seamless spatial frequency, zw its
|
|
563
|
-
// matching integer lattice period \u2014 both grid-size-dependent, so they can't be compile-time
|
|
564
|
-
// constants (see vgPotentialSeamless/computeMediumSpatialPeriods in noise.ts). Recomputed by
|
|
565
|
-
// web/medium.ts's bindVelocityUniforms every frame from the live grid dimensions.
|
|
566
|
-
uniform float4 u_spatial0;
|
|
567
|
-
uniform float4 u_spatial1;
|
|
568
|
-
uniform float4 u_spatial2;
|
|
569
|
-
uniform float4 u_spatial3;
|
|
570
|
-
|
|
571
|
-
${VG_CURL_NOISE}
|
|
572
|
-
`;
|
|
573
|
-
var MEDIUM_ADVECT_VELOCITY = `
|
|
574
|
-
float2 curl = vgCurlVelocitySeamless(xy * u_curlFreq, u_phase, u_spatial0, u_spatial1, u_spatial2, u_spatial3);
|
|
575
|
-
float2 vel = curl * u_advectSpeed * u_turbulence;
|
|
576
|
-
`;
|
|
577
|
-
var MEDIUM_ADVECT_VELOCITY_SETTLE = `
|
|
578
|
-
${MEDIUM_ADVECT_VELOCITY}
|
|
579
|
-
vel.y += u_settleSpeed;
|
|
580
|
-
vel.x += curl.x * u_advectSpeed * u_settleWiggle;
|
|
581
|
-
`;
|
|
582
|
-
var MEDIUM_ADVECT_VELOCITY_VAPOR = `
|
|
583
|
-
${MEDIUM_ADVECT_VELOCITY}
|
|
584
|
-
vel.y += u_vaporDrift;
|
|
585
|
-
`;
|
|
586
|
-
var MEDIUM_VAPOR_FORWARD_SHADER = `
|
|
587
|
-
${MEDIUM_ADVECT_UNIFORMS}
|
|
588
|
-
uniform float u_vaporDrift;
|
|
589
|
-
|
|
590
|
-
half4 main(float2 xy) {
|
|
591
|
-
${MEDIUM_ADVECT_VELOCITY_VAPOR}
|
|
592
|
-
float2 src = xy - vel * u_dt;
|
|
593
|
-
return u_dye.eval(float2(src.x, u_dyeSize.y - src.y));
|
|
594
|
-
}
|
|
595
|
-
`;
|
|
596
|
-
var MEDIUM_CONDENSATE_FORWARD_SHADER = `
|
|
597
|
-
${MEDIUM_ADVECT_UNIFORMS}
|
|
598
|
-
uniform float u_settleSpeed;
|
|
599
|
-
uniform float u_settleWiggle;
|
|
600
|
-
|
|
601
|
-
half4 main(float2 xy) {
|
|
602
|
-
${MEDIUM_ADVECT_VELOCITY_SETTLE}
|
|
603
|
-
float2 src = xy - vel * u_dt;
|
|
604
|
-
return u_dye.eval(float2(src.x, u_dyeSize.y - src.y));
|
|
605
|
-
}
|
|
606
|
-
`;
|
|
607
|
-
var MEDIUM_MACCORMACK_CORRECT = `
|
|
608
|
-
float2 srcForward = xy - vel * u_dt;
|
|
609
|
-
float2 srcReverse = xy + vel * u_dt;
|
|
610
|
-
half4 forwardSelf = u_forward.eval(float2(xy.x, u_forwardSize.y - xy.y));
|
|
611
|
-
half4 forwardReverse = u_forward.eval(float2(srcReverse.x, u_forwardSize.y - srcReverse.y));
|
|
612
|
-
half4 prevSelf = u_dye.eval(float2(xy.x, u_dyeSize.y - xy.y));
|
|
613
|
-
half4 corrected = forwardSelf + half4(0.5) * (prevSelf - forwardReverse);
|
|
614
|
-
|
|
615
|
-
float2 src = float2(srcForward.x, u_dyeSize.y - srcForward.y);
|
|
616
|
-
float2 base = floor(src - 0.5);
|
|
617
|
-
half4 c00 = u_dye.eval(base + float2(0.5, 0.5));
|
|
618
|
-
half4 c10 = u_dye.eval(base + float2(1.5, 0.5));
|
|
619
|
-
half4 c01 = u_dye.eval(base + float2(0.5, 1.5));
|
|
620
|
-
half4 c11 = u_dye.eval(base + float2(1.5, 1.5));
|
|
621
|
-
half4 lo = min(min(c00, c10), min(c01, c11));
|
|
622
|
-
half4 hi = max(max(c00, c10), max(c01, c11));
|
|
623
|
-
half4 limited = clamp(corrected, lo, hi);
|
|
624
|
-
`;
|
|
625
|
-
var MEDIUM_VAPOR_CORRECT_SHADER = `
|
|
626
|
-
${MEDIUM_ADVECT_UNIFORMS}
|
|
627
|
-
uniform shader u_forward;
|
|
628
|
-
uniform float u_vaporDrift;
|
|
629
|
-
|
|
630
|
-
half4 main(float2 xy) {
|
|
631
|
-
${MEDIUM_ADVECT_VELOCITY_VAPOR}
|
|
632
|
-
${MEDIUM_MACCORMACK_CORRECT}
|
|
633
|
-
return limited;
|
|
634
|
-
}
|
|
635
|
-
`;
|
|
636
|
-
var MEDIUM_CONDENSATE_CORRECT_SHADER = `
|
|
637
|
-
${MEDIUM_ADVECT_UNIFORMS}
|
|
638
|
-
uniform float u_settleSpeed;
|
|
639
|
-
uniform float u_settleWiggle;
|
|
640
|
-
uniform shader u_forward;
|
|
641
|
-
|
|
642
|
-
half4 main(float2 xy) {
|
|
643
|
-
${MEDIUM_ADVECT_VELOCITY_SETTLE}
|
|
644
|
-
${MEDIUM_MACCORMACK_CORRECT}
|
|
645
|
-
return limited;
|
|
646
|
-
}
|
|
647
|
-
`;
|
|
648
|
-
var MEDIUM_VAPOR_REACT_SHADER = `
|
|
649
|
-
uniform shader u_transported;
|
|
650
|
-
uniform shader u_condensateTransported;
|
|
651
|
-
uniform float u_dt;
|
|
652
|
-
uniform float u_condensationRate;
|
|
653
|
-
uniform float u_condensationFloor;
|
|
654
|
-
uniform float u_evaporationRate;
|
|
655
|
-
uniform float u_totalScale;
|
|
656
|
-
|
|
657
|
-
half4 main(float2 xy) {
|
|
658
|
-
float3 prevVapor = float3(u_transported.eval(float2(xy.x, u_transportedSize.y - xy.y)).rgb);
|
|
659
|
-
float condensateAtXy = float(u_condensateTransported.eval(float2(xy.x, u_condensateTransportedSize.y - xy.y)).r);
|
|
660
|
-
float vaporTotal = prevVapor.r + prevVapor.g + prevVapor.b;
|
|
661
|
-
|
|
662
|
-
// Only the EXCESS of vapor above the background floor condenses, not any nonzero density \u2014
|
|
663
|
-
// otherwise condensate would exactly retrace the vapor spot's shape (the same outline, or
|
|
664
|
-
// softer from blur), leaving the two phases nowhere to visually diverge: vapor is already soft,
|
|
665
|
-
// and condensate needs to read brighter and sharper than it. The floor concentrates condensate
|
|
666
|
-
// in dense turbulence cores, leaving the sparse vapor around it uncondensed \u2014 that's where the
|
|
667
|
-
// contrast comes from.
|
|
668
|
-
float excess = max(0.0, vaporTotal - u_condensationFloor);
|
|
669
|
-
float condensedAmount = excess * (1.0 - exp(-u_condensationRate * u_dt));
|
|
670
|
-
float lossFraction = vaporTotal > 1e-6 ? condensedAmount / vaporTotal : 0.0;
|
|
671
|
-
float3 afterLoss = prevVapor * (1.0 - lossFraction);
|
|
672
|
-
|
|
673
|
-
float condKeep = exp(-u_evaporationRate * u_dt);
|
|
674
|
-
float returned = condensateAtXy * (1.0 - condKeep);
|
|
675
|
-
|
|
676
|
-
// Evaporated water is distributed by the CURRENT vapor proportion \u2014 the condensation/
|
|
677
|
-
// evaporation cycle doesn't shift the hue, water only oscillates between phases (color belongs
|
|
678
|
-
// to vapor).
|
|
679
|
-
float sumAfterLoss = afterLoss.r + afterLoss.g + afterLoss.b;
|
|
680
|
-
float3 hueShare = sumAfterLoss > 1e-6 ? afterLoss / sumAfterLoss : float3(1.0 / 3.0);
|
|
681
|
-
float3 vapor = (afterLoss + hueShare * returned) * u_totalScale;
|
|
682
|
-
return half4(half3(vapor), half(1.0));
|
|
683
|
-
}
|
|
684
|
-
`;
|
|
685
|
-
var MEDIUM_CONDENSATE_REACT_SHADER = `
|
|
686
|
-
uniform shader u_transported;
|
|
687
|
-
uniform shader u_vaporTransported;
|
|
688
|
-
uniform shader u_dye;
|
|
689
|
-
uniform float u_dt;
|
|
690
|
-
uniform float u_condensationRate;
|
|
691
|
-
uniform float u_condensationFloor;
|
|
692
|
-
uniform float u_evaporationRate;
|
|
693
|
-
uniform float u_spreadRate;
|
|
694
|
-
uniform float u_totalScale;
|
|
695
|
-
|
|
696
|
-
half4 main(float2 xy) {
|
|
697
|
-
float prevCondensate = float(u_transported.eval(float2(xy.x, u_transportedSize.y - xy.y)).r);
|
|
698
|
-
float3 vaporAtXy = float3(u_vaporTransported.eval(float2(xy.x, u_vaporTransportedSize.y - xy.y)).rgb);
|
|
699
|
-
float vaporTotal = vaporAtXy.r + vaporAtXy.g + vaporAtXy.b;
|
|
700
|
-
|
|
701
|
-
float excess = max(0.0, vaporTotal - u_condensationFloor);
|
|
702
|
-
float condensed = excess * (1.0 - exp(-u_condensationRate * u_dt));
|
|
703
|
-
float condKeep = exp(-u_evaporationRate * u_dt);
|
|
704
|
-
float afterReaction = prevCondensate * condKeep + condensed;
|
|
705
|
-
|
|
706
|
-
// Growth is an Euler step separate from transport: the neighbors are sampled at THIS cell's own
|
|
707
|
-
// xy in the ORIGINAL (pre-transport-this-frame) field u_dye, not the already
|
|
708
|
-
// transported/corrected value. On a non-uniform flow, warping compresses the domain in some
|
|
709
|
-
// places and stretches it in others, and blurring at a warped point stacks those distortions \u2014
|
|
710
|
-
// the error accumulates frame over frame (measured: condensate steadily gained about 5% extra
|
|
711
|
-
// water alongside its own mass growth). Right on the grid, with no warp, the same blur is an
|
|
712
|
-
// honest averaging kernel that conserves the sum on a periodic domain.
|
|
713
|
-
float2 selfSrc = float2(xy.x, u_dyeSize.y - xy.y);
|
|
714
|
-
float n0 = float(u_dye.eval(float2(selfSrc.x + 1.0, selfSrc.y)).r);
|
|
715
|
-
float n1 = float(u_dye.eval(float2(selfSrc.x - 1.0, selfSrc.y)).r);
|
|
716
|
-
float n2 = float(u_dye.eval(float2(selfSrc.x, selfSrc.y - 1.0)).r);
|
|
717
|
-
float n3 = float(u_dye.eval(float2(selfSrc.x, selfSrc.y + 1.0)).r);
|
|
718
|
-
float neighborAvg = (n0 + n1 + n2 + n3) * 0.25;
|
|
719
|
-
float spreadWeight = 1.0 - exp(-u_spreadRate * u_dt);
|
|
720
|
-
float grown = mix(afterReaction, neighborAvg, spreadWeight) * u_totalScale;
|
|
721
|
-
|
|
722
|
-
return half4(half3(grown, 0.0, 0.0), half(1.0));
|
|
723
|
-
}
|
|
724
|
-
`;
|
|
725
|
-
var MEDIUM_TRACK_ADVECT_SHADER = `
|
|
726
|
-
${MEDIUM_ADVECT_UNIFORMS}
|
|
727
|
-
uniform float u_decay;
|
|
728
|
-
|
|
729
|
-
half4 main(float2 xy) {
|
|
730
|
-
${MEDIUM_ADVECT_VELOCITY}
|
|
731
|
-
float2 back = xy - vel * u_dt;
|
|
732
|
-
half4 prev = u_dye.eval(float2(back.x, u_dyeSize.y - back.y));
|
|
733
|
-
float3 decayed = float3(prev.rgb) * exp(-u_decay * u_dt);
|
|
734
|
-
return half4(half3(decayed), half(1.0));
|
|
735
|
-
}
|
|
736
|
-
`;
|
|
737
|
-
|
|
738
|
-
// src/medium/composite-shader.ts
|
|
739
|
-
var VG_CUBIC_WEIGHTS = `
|
|
740
|
-
float4 vgCubicWeights(float v) {
|
|
741
|
-
float4 n = float4(1.0, 2.0, 3.0, 4.0) - v;
|
|
742
|
-
float4 s = n * n * n;
|
|
743
|
-
float x = s.x;
|
|
744
|
-
float y = s.y - 4.0 * s.x;
|
|
745
|
-
float z = s.z - 4.0 * s.y + 6.0 * s.x;
|
|
746
|
-
float w = 6.0 - x - y - z;
|
|
747
|
-
return float4(x, y, z, w) * (1.0 / 6.0);
|
|
748
|
-
}
|
|
749
|
-
`;
|
|
750
|
-
function vgBicubicSampler(fnName, textureName) {
|
|
751
|
-
return `
|
|
752
|
-
half4 ${fnName}(float2 px) {
|
|
753
|
-
float2 shifted = px - 0.5;
|
|
754
|
-
float2 fxy = fract(shifted);
|
|
755
|
-
float2 base = shifted - fxy;
|
|
756
|
-
float4 xw = vgCubicWeights(fxy.x);
|
|
757
|
-
float4 yw = vgCubicWeights(fxy.y);
|
|
758
|
-
float2 sx = float2(xw.x + xw.y, xw.z + xw.w);
|
|
759
|
-
float2 sy = float2(yw.x + yw.y, yw.z + yw.w);
|
|
760
|
-
float2 offsetX = float2(base.x - 0.5 + xw.y / sx.x, base.x + 1.5 + xw.w / sx.y);
|
|
761
|
-
float2 offsetY = float2(base.y - 0.5 + yw.y / sy.x, base.y + 1.5 + yw.w / sy.y);
|
|
762
|
-
half4 s00 = ${textureName}.eval(float2(offsetX.x, offsetY.x));
|
|
763
|
-
half4 s10 = ${textureName}.eval(float2(offsetX.y, offsetY.x));
|
|
764
|
-
half4 s01 = ${textureName}.eval(float2(offsetX.x, offsetY.y));
|
|
765
|
-
half4 s11 = ${textureName}.eval(float2(offsetX.y, offsetY.y));
|
|
766
|
-
float wx = sx.x / (sx.x + sx.y);
|
|
767
|
-
float wy = sy.x / (sy.x + sy.y);
|
|
768
|
-
return mix(mix(s11, s01, wx), mix(s10, s00, wx), wy);
|
|
769
|
-
}
|
|
770
|
-
`;
|
|
771
|
-
}
|
|
772
|
-
var VG_LIGHT = `
|
|
773
|
-
float vgLightAmount(float2 xy, float2 lightPosFrac, float2 lightDir, float cosCone, float falloff, float2 resolution, float seed) {
|
|
774
|
-
float2 rel = xy - lightPosFrac * resolution;
|
|
775
|
-
// A cone of 180\xB0 or more is an edge strip: light spreads from a line, not a point.
|
|
776
|
-
if (cosCone <= -0.999) {
|
|
777
|
-
float depth = max(dot(rel, lightDir), 0.0);
|
|
778
|
-
return exp(-(depth / max(resolution.y, 1.0)) * falloff);
|
|
779
|
-
}
|
|
780
|
-
float dist = length(rel);
|
|
781
|
-
float2 dirN = dist > 1e-4 ? rel / dist : lightDir;
|
|
782
|
-
float cosAngle = dot(dirN, lightDir);
|
|
783
|
-
// A soft lobe with half intensity at the cone angle and no boundary at all: a lamp in haze has
|
|
784
|
-
// no drawn edge.
|
|
785
|
-
float lobe = log(0.5) / log(clamp(cosCone, 0.05, 0.999));
|
|
786
|
-
float edge = pow(max(cosAngle, 0.0), lobe);
|
|
787
|
-
float atten = exp(-(dist / max(resolution.y, 1.0)) * falloff);
|
|
788
|
-
if (edge * atten < 0.001) return 0.0;
|
|
789
|
-
// Static shafts inside the beam: brightness varies with the angle around the lamp, so streaks
|
|
790
|
-
// fan out from the source the way light through dusty air does.
|
|
791
|
-
float angle = atan(dirN.x * lightDir.y - dirN.y * lightDir.x, cosAngle);
|
|
792
|
-
float shafts = 0.6 + 0.32 * vgValueNoise(float2(angle * 14.0, seed)) + 0.18 * vgValueNoise(float2(angle * 33.0, seed + 5.3));
|
|
793
|
-
return edge * atten * clamp(shafts, 0.0, 1.0);
|
|
794
|
-
}
|
|
795
|
-
`;
|
|
796
|
-
var MEDIUM_COMPOSITE_SHADER = `
|
|
797
|
-
uniform shader u_vapor;
|
|
798
|
-
uniform shader u_condensate;
|
|
799
|
-
uniform shader u_track;
|
|
800
|
-
uniform shader u_shadow;
|
|
801
|
-
uniform float2 u_dyeScale;
|
|
802
|
-
uniform float3 u_lab0;
|
|
803
|
-
uniform float3 u_lab1;
|
|
804
|
-
uniform float3 u_lab2;
|
|
805
|
-
uniform float3 u_labBg;
|
|
806
|
-
uniform float3 u_labCondensate;
|
|
807
|
-
uniform float u_baseWeight;
|
|
808
|
-
uniform float u_condensateTint;
|
|
809
|
-
uniform float u_condensateGain;
|
|
810
|
-
uniform float u_farScale;
|
|
811
|
-
uniform float2 u_farOffset;
|
|
812
|
-
uniform float u_farBlurRadius;
|
|
813
|
-
uniform float u_farWeight;
|
|
814
|
-
uniform float u_gravityBoost;
|
|
815
|
-
uniform float u_gravityBoostStart;
|
|
816
|
-
uniform float3 u_channelScatter;
|
|
817
|
-
uniform float2 u_light0Pos;
|
|
818
|
-
uniform float2 u_light0Dir;
|
|
819
|
-
uniform float u_light0CosCone;
|
|
820
|
-
uniform float u_light0Falloff;
|
|
821
|
-
uniform float3 u_light0Color;
|
|
822
|
-
uniform float u_light0Intensity;
|
|
823
|
-
uniform float2 u_light1Pos;
|
|
824
|
-
uniform float2 u_light1Dir;
|
|
825
|
-
uniform float u_light1CosCone;
|
|
826
|
-
uniform float u_light1Falloff;
|
|
827
|
-
uniform float3 u_light1Color;
|
|
828
|
-
uniform float u_light1Intensity;
|
|
829
|
-
uniform float2 u_light2Pos;
|
|
830
|
-
uniform float2 u_light2Dir;
|
|
831
|
-
uniform float u_light2CosCone;
|
|
832
|
-
uniform float u_light2Falloff;
|
|
833
|
-
uniform float3 u_light2Color;
|
|
834
|
-
uniform float u_light2Intensity;
|
|
835
|
-
uniform float u_trackLightFloor;
|
|
836
|
-
|
|
837
|
-
${VG_OKLAB_TO_SRGB}
|
|
838
|
-
${VG_CUBIC_WEIGHTS}
|
|
839
|
-
${vgBicubicSampler("vgBicubicVapor", "u_vapor")}
|
|
840
|
-
${vgBicubicSampler("vgBicubicCondensate", "u_condensate")}
|
|
841
|
-
${VG_VALUE_NOISE}
|
|
842
|
-
${VG_LIGHT}
|
|
843
|
-
|
|
844
|
-
half4 main(float2 xy) {
|
|
845
|
-
float2 baseSrc = xy * u_dyeScale;
|
|
846
|
-
|
|
847
|
-
// Near plane \u2014 the calibrated look lives here. Bicubic (see the file header) on vapor and
|
|
848
|
-
// condensate; track stays a plain bilinear read.
|
|
849
|
-
half4 vapor = vgBicubicVapor(baseSrc);
|
|
850
|
-
half4 condensate = vgBicubicCondensate(baseSrc);
|
|
851
|
-
half4 track = u_track.eval(baseSrc);
|
|
852
|
-
|
|
853
|
-
// Far plane \u2014 the identical field, scaled and offset (see the file header). An 8-tap ring, not
|
|
854
|
-
// the near plane's \xB1x/\xB1y box: axis-aligned taps read the SAME column/row on both sides of any
|
|
855
|
-
// residual axis-aligned structure (a seam, a resize artifact), which is exactly how a straight
|
|
856
|
-
// line gets doubled into four parallel copies instead of softened away \u2014 measured directly via
|
|
857
|
-
// check-medium.mjs's isotropy gate (see its report). The ring is rotated a half-step (22.5\xB0) off
|
|
858
|
-
// the axes so no tap direction ever coincides with a grid row or column. Radius stays in the same
|
|
859
|
-
// far-plane texture-space unit as before (u_farBlurRadius, grid-px) \u2014 only the tap PATTERN
|
|
860
|
-
// changed, not what it measures in.
|
|
861
|
-
float2 farSrc = baseSrc * u_farScale + u_farOffset;
|
|
862
|
-
float2 ring0 = float2( 0.9238795, 0.3826834) * u_farBlurRadius;
|
|
863
|
-
float2 ring1 = float2( 0.3826834, 0.9238795) * u_farBlurRadius;
|
|
864
|
-
float2 ring2 = float2(-0.3826834, 0.9238795) * u_farBlurRadius;
|
|
865
|
-
float2 ring3 = float2(-0.9238795, 0.3826834) * u_farBlurRadius;
|
|
866
|
-
float2 ring4 = float2(-0.9238795, -0.3826834) * u_farBlurRadius;
|
|
867
|
-
float2 ring5 = float2(-0.3826834, -0.9238795) * u_farBlurRadius;
|
|
868
|
-
float2 ring6 = float2( 0.3826834, -0.9238795) * u_farBlurRadius;
|
|
869
|
-
float2 ring7 = float2( 0.9238795, -0.3826834) * u_farBlurRadius;
|
|
870
|
-
half4 vaporFar = (u_vapor.eval(farSrc + ring0) + u_vapor.eval(farSrc + ring1) +
|
|
871
|
-
u_vapor.eval(farSrc + ring2) + u_vapor.eval(farSrc + ring3) +
|
|
872
|
-
u_vapor.eval(farSrc + ring4) + u_vapor.eval(farSrc + ring5) +
|
|
873
|
-
u_vapor.eval(farSrc + ring6) + u_vapor.eval(farSrc + ring7)) * half4(0.125);
|
|
874
|
-
half4 condensateFar = (u_condensate.eval(farSrc + ring0) + u_condensate.eval(farSrc + ring1) +
|
|
875
|
-
u_condensate.eval(farSrc + ring2) + u_condensate.eval(farSrc + ring3) +
|
|
876
|
-
u_condensate.eval(farSrc + ring4) + u_condensate.eval(farSrc + ring5) +
|
|
877
|
-
u_condensate.eval(farSrc + ring6) + u_condensate.eval(farSrc + ring7)) * half4(0.125);
|
|
878
|
-
|
|
879
|
-
// Gravity's "denser layer at the bottom of the chamber" \u2014 a compositing-only boost (see
|
|
880
|
-
// MEDIUM_DEFAULTS.gravityBottomBoost): it scales how density already in the conserved buffers is
|
|
881
|
-
// DISPLAYED, never the buffers themselves, so it can't threaten water conservation. Shared by
|
|
882
|
-
// both planes: the chamber's floor is denser everywhere along its depth, not just up close.
|
|
883
|
-
//
|
|
884
|
-
// Verified with a headless render, not assumed: ramping this with xy.y directly lit up the TOP
|
|
885
|
-
// of the frame, not the bottom (contentTexture's own orientation contract flips y once more
|
|
886
|
-
// between this pass and the final scene \u2014 see the file header) \u2014 hence the 1.0 - below.
|
|
887
|
-
float bottomFrac = 1.0 - xy.y / u_resolution.y;
|
|
888
|
-
float bottomT = smoothstep(u_gravityBoostStart, 1.0, bottomFrac);
|
|
889
|
-
float bottomBoost = 1.0 + u_gravityBoost * bottomT;
|
|
890
|
-
|
|
891
|
-
float gasR = (float(vapor.r) + float(vaporFar.r) * u_farWeight) * bottomBoost;
|
|
892
|
-
float gasG = (float(vapor.g) + float(vaporFar.g) * u_farWeight) * bottomBoost;
|
|
893
|
-
float gasB = (float(vapor.b) + float(vaporFar.b) * u_farWeight) * bottomBoost;
|
|
894
|
-
float w0 = gasR + float(track.r);
|
|
895
|
-
float w1 = gasG + float(track.g);
|
|
896
|
-
float w2 = gasB + float(track.b);
|
|
897
|
-
float wBg = u_baseWeight;
|
|
898
|
-
|
|
899
|
-
// A faint condensate hint from the LOCAL vapor, not its own color (droplets scatter light
|
|
900
|
-
// rather than tint it) \u2014 a fraction of the way from white to the vapor tone sampled right here.
|
|
901
|
-
float vaporLocal = max(w0 + w1 + w2, 1e-4);
|
|
902
|
-
float3 vaporHue = (u_lab0 * w0 + u_lab1 * w1 + u_lab2 * w2) / vaporLocal;
|
|
903
|
-
float3 condensateLab = mix(u_labCondensate, vaporHue, u_condensateTint);
|
|
904
|
-
float wCondensate =
|
|
905
|
-
(float(condensate.r) + float(condensateFar.r) * u_farWeight) * u_condensateGain * bottomBoost;
|
|
906
|
-
|
|
907
|
-
float total = max(w0 + w1 + w2 + wBg + wCondensate, 1e-4);
|
|
908
|
-
float3 mixLab =
|
|
909
|
-
(u_labBg * wBg + u_lab0 * w0 + u_lab1 * w1 + u_lab2 * w2 + condensateLab * wCondensate) / total;
|
|
910
|
-
// The dark ambient base \u2014 this is where the OLD mechanism stops (see the file header on
|
|
911
|
-
// VG_LIGHT): unclamped here, clamped once at the very end, after the lit layer adds in.
|
|
912
|
-
float3 rgbLinearBase = vgOklabToLinear(mixLab);
|
|
913
|
-
|
|
914
|
-
// Spotlights reach this point dimmed by the gas in front of them (shadow-shader.ts).
|
|
915
|
-
half4 shadow = u_shadow.eval(baseSrc);
|
|
916
|
-
float light0 = vgLightAmount(xy, u_light0Pos, u_light0Dir, u_light0CosCone, u_light0Falloff, u_resolution, 1.7) * u_light0Intensity;
|
|
917
|
-
float light1 = vgLightAmount(xy, u_light1Pos, u_light1Dir, u_light1CosCone, u_light1Falloff, u_resolution, 4.1) * u_light1Intensity
|
|
918
|
-
* float(shadow.r);
|
|
919
|
-
float light2 = vgLightAmount(xy, u_light2Pos, u_light2Dir, u_light2CosCone, u_light2Falloff, u_resolution, 8.3) * u_light2Intensity
|
|
920
|
-
* float(shadow.g);
|
|
921
|
-
float3 illum = u_light0Color * light0 + u_light1Color * light1 + u_light2Color * light2;
|
|
922
|
-
|
|
923
|
-
float totalScatter = gasR * u_channelScatter.x + gasG * u_channelScatter.y + gasB * u_channelScatter.z;
|
|
924
|
-
float fogDensity = totalScatter + wCondensate;
|
|
925
|
-
float mist = 0.006 + fogDensity * 0.2;
|
|
926
|
-
|
|
927
|
-
// TRACKS: lit the same way as the mist, plus a floor so a track already on screen never vanishes
|
|
928
|
-
// entirely just because it drifted out of a cone (a fresh ionization trail reads brighter than
|
|
929
|
-
// ambient mist in a real chamber). The floor is added to ITS OWN color, not multiplied into illum:
|
|
930
|
-
// illum is exactly [0,0,0] in a fully unlit spot (every light's amount is 0 there), so a floor
|
|
931
|
-
// multiplied by illum would vanish exactly where it exists to help \u2014 it needs a color of its own
|
|
932
|
-
// (a neutral, self-luminous glow) rather than borrowing whichever light happens to be nearby.
|
|
933
|
-
float trackDensity = max(float(track.r), max(float(track.g), float(track.b)));
|
|
934
|
-
float3 trackGlow = (1.0 - exp(-trackDensity * 0.4)) * (illum + float3(u_trackLightFloor)) * 0.08;
|
|
935
|
-
|
|
936
|
-
float3 rgbLinear = rgbLinearBase * 0.025 + illum * mist + trackGlow;
|
|
937
|
-
rgbLinear = float3(1.0) - exp(-rgbLinear * 1.0);
|
|
938
|
-
float3 srgb = vgLinearToSrgb(rgbLinear);
|
|
939
|
-
return half4(half3(srgb), half(1.0));
|
|
940
|
-
}
|
|
941
|
-
`;
|
|
942
|
-
|
|
943
|
-
// src/medium/emit-shader.ts
|
|
944
|
-
var MEDIUM_EMIT_SHADER = `
|
|
945
|
-
uniform float2 u_source;
|
|
946
|
-
uniform float2 u_head;
|
|
947
|
-
uniform float u_headWidth;
|
|
948
|
-
uniform float u_tailWidth;
|
|
949
|
-
uniform float u_raggedAmp;
|
|
950
|
-
uniform float u_raggedFreq;
|
|
951
|
-
uniform float u_settle;
|
|
952
|
-
uniform float u_tailDim;
|
|
953
|
-
uniform float u_intensity;
|
|
954
|
-
uniform float u_seed;
|
|
955
|
-
|
|
956
|
-
${VG_VALUE_NOISE}
|
|
957
|
-
|
|
958
|
-
half4 main(float2 xy) {
|
|
959
|
-
float2 dir = u_head - u_source;
|
|
960
|
-
float len = max(length(dir), 1.0);
|
|
961
|
-
float2 side = float2(-dir.y, dir.x) / len;
|
|
962
|
-
|
|
963
|
-
float best = 0.0;
|
|
964
|
-
const int STEPS = 12;
|
|
965
|
-
for (int i = 0; i < STEPS; i++) {
|
|
966
|
-
float s = float(i) / float(STEPS - 1);
|
|
967
|
-
float tailness = 1.0 - s;
|
|
968
|
-
float ragged = u_raggedAmp * tailness * vgValueNoise(float2(s * u_raggedFreq + u_seed, u_seed * 3.7));
|
|
969
|
-
float2 p = mix(u_source, u_head, s) + side * ragged + float2(0.0, u_settle * tailness * tailness);
|
|
970
|
-
float w = max(mix(u_tailWidth, u_headWidth, s), 0.5);
|
|
971
|
-
float amp = mix(u_tailDim, 1.0, s);
|
|
972
|
-
float d = length(xy - p);
|
|
973
|
-
float v = amp * exp(-(d * d) / (2.0 * w * w));
|
|
974
|
-
best = max(best, v);
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
float3 dye = float3(best * u_intensity);
|
|
978
|
-
return half4(half3(dye), half(1.0));
|
|
979
|
-
}
|
|
980
|
-
`;
|
|
981
|
-
|
|
982
|
-
// src/medium/shadow-shader.ts
|
|
983
|
-
var MEDIUM_SHADOW_SHADER = `
|
|
984
|
-
uniform shader u_vapor;
|
|
985
|
-
uniform shader u_condensate;
|
|
986
|
-
uniform float u_condensateGain;
|
|
987
|
-
uniform float2 u_light1Grid;
|
|
988
|
-
uniform float2 u_light2Grid;
|
|
989
|
-
uniform float u_extinction;
|
|
990
|
-
|
|
991
|
-
float vgOpticalDepth(float2 p, float2 lightP) {
|
|
992
|
-
float2 toLight = lightP - p;
|
|
993
|
-
float optical = 0.0;
|
|
994
|
-
for (int i = 1; i <= 24; i++) {
|
|
995
|
-
float2 q = p + toLight * (float(i) / 24.0);
|
|
996
|
-
float inside = step(0.0, q.x) * step(q.x, u_resolution.x) * step(0.0, q.y) * step(q.y, u_resolution.y);
|
|
997
|
-
half4 v = u_vapor.eval(q);
|
|
998
|
-
half4 c = u_condensate.eval(q);
|
|
999
|
-
optical += inside * (float(v.r + v.g + v.b) + float(c.r) * u_condensateGain);
|
|
1000
|
-
}
|
|
1001
|
-
return optical * length(toLight) / 24.0 / max(u_resolution.y, 1.0);
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
half4 main(float2 xy) {
|
|
1005
|
-
float2 p = float2(xy.x, u_resolution.y - xy.y);
|
|
1006
|
-
float t1 = exp(-vgOpticalDepth(p, u_light1Grid) * u_extinction);
|
|
1007
|
-
float t2 = exp(-vgOpticalDepth(p, u_light2Grid) * u_extinction);
|
|
1008
|
-
return half4(half(t1), half(t2), half(0.0), half(1.0));
|
|
1009
|
-
}
|
|
1010
|
-
`;
|
|
1011
|
-
|
|
1012
|
-
// src/medium/dynamics.ts
|
|
1013
|
-
function hash01(n) {
|
|
1014
|
-
const s = Math.sin(n * 12.9898) * 43758.5453;
|
|
1015
|
-
return s - Math.floor(s);
|
|
1016
|
-
}
|
|
1017
|
-
function lerp(range, t) {
|
|
1018
|
-
return range[0] + (range[1] - range[0]) * t;
|
|
1019
|
-
}
|
|
1020
|
-
function applyTrackDepth(preset, depth) {
|
|
1021
|
-
const widthScale = lerp(MEDIUM_TRACK_DEPTH_WIDTH_RANGE, depth);
|
|
1022
|
-
const intensityScale = lerp(MEDIUM_TRACK_DEPTH_INTENSITY_RANGE, depth);
|
|
1023
|
-
return {
|
|
1024
|
-
...preset,
|
|
1025
|
-
headWidthFrac: preset.headWidthFrac * widthScale,
|
|
1026
|
-
tailWidthFrac: preset.tailWidthFrac * widthScale,
|
|
1027
|
-
intensity: preset.intensity * intensityScale
|
|
1028
|
-
};
|
|
1029
|
-
}
|
|
1030
|
-
function buildEmission(presetName, source, seed, intensityScale, angleOverride, lengthScale = 1) {
|
|
1031
|
-
const preset = MEDIUM_TRACK_PRESETS[presetName];
|
|
1032
|
-
const depth = hash01(seed * 4.63);
|
|
1033
|
-
const depthApplied = applyTrackDepth(preset, depth);
|
|
1034
|
-
return {
|
|
1035
|
-
...depthApplied,
|
|
1036
|
-
lengthFrac: depthApplied.lengthFrac * lengthScale,
|
|
1037
|
-
intensity: depthApplied.intensity * intensityScale,
|
|
1038
|
-
source,
|
|
1039
|
-
angle: angleOverride ?? hash01(seed * 7.31) * Math.PI * 2,
|
|
1040
|
-
seed,
|
|
1041
|
-
depth,
|
|
1042
|
-
kind: presetName
|
|
1043
|
-
};
|
|
1044
|
-
}
|
|
1045
|
-
function createMediumDynamics() {
|
|
1046
|
-
let turbulence = MEDIUM_DRIFT_TURBULENCE;
|
|
1047
|
-
let lastBar = -1;
|
|
1048
|
-
let idleClock = 0;
|
|
1049
|
-
let naturalIndex = 0;
|
|
1050
|
-
let nextNaturalAt = MEDIUM_NATURAL_INTERVAL * 0.5;
|
|
1051
|
-
let simTime = 0;
|
|
1052
|
-
let lastEmissionAt = -Infinity;
|
|
1053
|
-
function step(input) {
|
|
1054
|
-
const { state, bpm, amplitude, positionSeconds, sourcePoint, dt } = input;
|
|
1055
|
-
simTime += dt;
|
|
1056
|
-
const amp = Math.max(0, Math.min(1, amplitude));
|
|
1057
|
-
const target = state === "playing" ? MEDIUM_PLAYING_TURBULENCE_RANGE[0] + (MEDIUM_PLAYING_TURBULENCE_RANGE[1] - MEDIUM_PLAYING_TURBULENCE_RANGE[0]) * amp : MEDIUM_DRIFT_TURBULENCE;
|
|
1058
|
-
turbulence += (target - turbulence) * (1 - Math.exp(-dt / MEDIUM_TURBULENCE_TAU));
|
|
1059
|
-
const emissions = [];
|
|
1060
|
-
if (state === "playing" && bpm > 0) {
|
|
1061
|
-
const beats = positionSeconds * bpm / 60;
|
|
1062
|
-
const bar = Math.floor(beats / MEDIUM_EMISSION_BEATS);
|
|
1063
|
-
if (bar !== lastBar) {
|
|
1064
|
-
lastBar = bar;
|
|
1065
|
-
const eligible = hash01(bar * 0.618) < MEDIUM_EMISSION_PROBABILITY && simTime - lastEmissionAt >= MEDIUM_MIN_EMISSION_INTERVAL;
|
|
1066
|
-
if (eligible) {
|
|
1067
|
-
lastEmissionAt = simTime;
|
|
1068
|
-
const rayCount = Math.round(lerp(MEDIUM_ALPHA_BURST_RAYS, hash01(bar * 9.17)));
|
|
1069
|
-
for (let i = 0; i < rayCount; i += 1) {
|
|
1070
|
-
const raySeed = bar + (i + 1) * 0.0137;
|
|
1071
|
-
const angle = (i + hash01(raySeed * 5.23)) / rayCount * Math.PI * 2;
|
|
1072
|
-
const lengthScale = lerp(MEDIUM_ALPHA_RAY_LENGTH_SCALE, hash01(raySeed * 2.91));
|
|
1073
|
-
emissions.push(
|
|
1074
|
-
buildEmission("alpha", sourcePoint, raySeed, 0.6 + 0.4 * amp, angle, lengthScale)
|
|
1075
|
-
);
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
} else if (state === "idle") {
|
|
1080
|
-
idleClock += dt;
|
|
1081
|
-
if (idleClock >= nextNaturalAt) {
|
|
1082
|
-
const idx = naturalIndex;
|
|
1083
|
-
naturalIndex += 1;
|
|
1084
|
-
const randomSource = [
|
|
1085
|
-
hash01(idx * 2.1 + 0.5),
|
|
1086
|
-
MEDIUM_SENSITIVE_TOP + hash01(idx * 5.9 + 1.7) * (MEDIUM_SENSITIVE_BOTTOM - MEDIUM_SENSITIVE_TOP)
|
|
1087
|
-
];
|
|
1088
|
-
const presetName = hash01(idx * 3.14) < 0.5 ? "electron" : "muon";
|
|
1089
|
-
emissions.push(buildEmission(presetName, randomSource, idx, 1));
|
|
1090
|
-
nextNaturalAt = idleClock + MEDIUM_NATURAL_INTERVAL + hash01(idx * 1.7) * MEDIUM_NATURAL_JITTER;
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
return { turbulence, emissions };
|
|
1094
|
-
}
|
|
1095
|
-
return { step };
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
// src/medium/light-rig.ts
|
|
1099
|
-
var clamp012 = (v) => Math.min(1, Math.max(0, v));
|
|
1100
|
-
var EDGE_STRIP_CONE_ANGLE = Math.PI - 1e-6;
|
|
1101
|
-
var EDGE_STRIP_TINT_MIX = 0.22;
|
|
1102
|
-
var GEL_LIGHTNESS = 0.7;
|
|
1103
|
-
var LIGHT_HUE_SPREAD = MEDIUM_SPECIES_HUE_SPREAD / 2;
|
|
1104
|
-
function retint(base, hueDeg, chroma, mix) {
|
|
1105
|
-
const [baseL, a, b] = srgbToOklab(base);
|
|
1106
|
-
const l = baseL + (Math.min(baseL, GEL_LIGHTNESS) - baseL) * mix;
|
|
1107
|
-
const rad = hueDeg * Math.PI / 180;
|
|
1108
|
-
const targetA = chroma * Math.cos(rad);
|
|
1109
|
-
const targetB = chroma * Math.sin(rad);
|
|
1110
|
-
const mixedA = a + (targetA - a) * mix;
|
|
1111
|
-
const mixedB = b + (targetB - b) * mix;
|
|
1112
|
-
let lo = 0;
|
|
1113
|
-
let hi = 1;
|
|
1114
|
-
if (inGamut(oklabToSrgb([l, mixedA, mixedB]))) lo = 1;
|
|
1115
|
-
else {
|
|
1116
|
-
for (let i = 0; i < 12; i += 1) {
|
|
1117
|
-
const mid = (lo + hi) / 2;
|
|
1118
|
-
if (inGamut(oklabToSrgb([l, mixedA * mid, mixedB * mid]))) lo = mid;
|
|
1119
|
-
else hi = mid;
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
const rgb = oklabToSrgb([l, mixedA * lo, mixedB * lo]).map(clamp012);
|
|
1123
|
-
const gain = Math.max(...base) / Math.max(...rgb, 1e-6);
|
|
1124
|
-
return rgb.map((v) => clamp012(v * gain));
|
|
1125
|
-
}
|
|
1126
|
-
var inGamut = (rgb) => rgb.every((v) => v >= -1e-4 && v <= 1 + 1e-4);
|
|
1127
|
-
function lightRigForCharacter(character, baseLights = MEDIUM_DEFAULT_LIGHTS) {
|
|
1128
|
-
const spotlightIndices = [];
|
|
1129
|
-
baseLights.forEach((light, i) => {
|
|
1130
|
-
if (light.coneAngle < EDGE_STRIP_CONE_ANGLE) spotlightIndices.push(i);
|
|
1131
|
-
});
|
|
1132
|
-
const spotlightCount = spotlightIndices.length;
|
|
1133
|
-
return baseLights.map((light, i) => {
|
|
1134
|
-
if (light.coneAngle >= EDGE_STRIP_CONE_ANGLE) {
|
|
1135
|
-
return { ...light, color: retint(light.color, character.hue, character.chroma, EDGE_STRIP_TINT_MIX) };
|
|
1136
|
-
}
|
|
1137
|
-
const slot = spotlightIndices.indexOf(i);
|
|
1138
|
-
const hueOffset = spotlightCount > 1 ? LIGHT_HUE_SPREAD * (2 * slot / (spotlightCount - 1) - 1) : 0;
|
|
1139
|
-
return { ...light, color: retint(light.color, character.hue + hueOffset, character.chroma, 1) };
|
|
1140
|
-
});
|
|
1141
|
-
}
|
|
1142
|
-
function lightRigForCover(cover, baseLights = MEDIUM_DEFAULT_LIGHTS) {
|
|
1143
|
-
return lightRigForCharacter(characterOf(cover), baseLights);
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
export { LINEAR_TO_LMS, LMS_TO_LINEAR, LMS_TO_OKLAB, MEDIUM_ALPHA_BURST_RAYS, MEDIUM_ALPHA_RAY_LENGTH_SCALE, MEDIUM_COMPOSITE_SHADER, MEDIUM_CONDENSATE_CORRECT_SHADER, MEDIUM_CONDENSATE_FORWARD_SHADER, MEDIUM_CONDENSATE_REACT_SHADER, MEDIUM_DEFAULTS, MEDIUM_DEFAULT_CELL_PX, MEDIUM_DEFAULT_LIGHTS, MEDIUM_DRIFT_TURBULENCE, MEDIUM_EMISSION_BEATS, MEDIUM_EMISSION_PROBABILITY, MEDIUM_EMIT_SHADER, MEDIUM_MAX_LIGHTS, MEDIUM_MIN_EMISSION_INTERVAL, MEDIUM_NATURAL_INTERVAL, MEDIUM_NATURAL_JITTER, MEDIUM_PLAYING_TURBULENCE_RANGE, MEDIUM_PROBE_FLOOR_PX, MEDIUM_RESAMPLE_SHADER, MEDIUM_SEED_SHADER, MEDIUM_SENSITIVE_BOTTOM, MEDIUM_SENSITIVE_TOP, MEDIUM_SHADOW_SHADER, MEDIUM_SPECIES_HUE_SPREAD, MEDIUM_SPECIES_LIGHTNESS, MEDIUM_TIME_PERIOD, MEDIUM_TRACK_ADVECT_SHADER, MEDIUM_TRACK_DEPTH_INTENSITY_RANGE, MEDIUM_TRACK_DEPTH_WIDTH_RANGE, MEDIUM_TRACK_LAYER_BURST_ACCENT, MEDIUM_TRACK_LAYER_BURST_SPREAD, MEDIUM_TRACK_LAYER_CURL_PUSH, MEDIUM_TRACK_LAYER_FADE_GAMMA, MEDIUM_TRACK_LAYER_GRAVITY_SAG, MEDIUM_TRACK_LAYER_LIFE_SECONDS, MEDIUM_TRACK_LAYER_LOOK, MEDIUM_TRACK_LAYER_MAX_TRACKS, MEDIUM_TRACK_PRESETS, MEDIUM_TURBULENCE_TAU, MEDIUM_VAPOR_CORRECT_SHADER, MEDIUM_VAPOR_FORWARD_SHADER, MEDIUM_VAPOR_REACT_SHADER, OKLAB_TO_LMS, VG_CURL_NOISE, VG_OKLAB_TO_SRGB, VG_VALUE_NOISE, applyTrackDepth, characterOf, computeMediumSpatialPeriods, createMediumDynamics, depthFarOffsetPx, lightRigForCharacter, lightRigForCover, neutralSpecies, oklabToSrgb, speciesFamily, srgbToOklab, vgPotentialJS, wrappedDistanceFromZero };
|
|
1147
|
-
//# sourceMappingURL=chunk-VY22O2II.js.map
|
|
1148
|
-
//# sourceMappingURL=chunk-VY22O2II.js.map
|