Agent Harness · VibeGit
Agent Harness Публичная копия обвязки агентной разработки: гейты, journeys, скиллы и шаблоны. Без ключей и личных данных.
agent-harness / tools / spells-assets / ue / vfx / Lens.js 336 строк · изменён 6 нояб., 03:45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
import * as THREE from 'three' ;
import { FullscreenQuad , rawPass } from '../engine/fullscreen.js' ;
import { U } from './common.js' ;
_v
active
warming
renderer
s renderer
s s
i worldPos einsteinRadius horizonRadius strength
l i
l worldPos
l einsteinRadius
l horizonRadius
l strength
l
w width h height
w h
u
u w h
u h
srcTex
u aspect u
k camera
n
l
l
_v l camera
z _v
l dk
z camera dk
_v camera
zz z camera te l k zz
u n _v aspect _v z camera te te l l k zz
u n z l dk l l
u n l l l dk
u n dk
dk
u n
u n
u n u zz k
u n
n
sh
u sh sh sh sh
u sh sh
n sh srcTex
u n
u srcTex
u depthTex
u camera camera
e camera pe camera
u e e e
u camera
u pe pe
r prev r clear r
r
r
r prev
r clear
const
MAX
=
2
,
STEPS
=
72
;
const
FRAG
=
`
precision highp float;
precision highp int;
precision highp sampler2D;
precision highp sampler3D;
uniform sampler2D tSrc;
uniform sampler2D tDepth;
uniform sampler3D uNoise3D;
uniform sampler2D uBlackbody;
uniform vec4 uA[ ${ MAX } ]; // centre (x * aspect, y), thetaE^2 * strength for a source at infinity, shadow radius
uniform vec4 uB[ ${ MAX } ]; // lens view depth, horizon world radius, ring gain, 1 / depth ramp (m)
uniform vec4 uC[ ${ MAX } ]; // disk: hole centre (world), r_s (world; 0 = no disk)
uniform vec4 uD[ ${ MAX } ]; // disk normal, emission scale
uniform vec4 uE[ ${ MAX } ]; // inner, outer radius (r_s), inner temperature (K), orbital speed (fraction of Kepler)
uniform vec4 uF[ ${ MAX } ]; // bending 0..1, shadow 0..1, rotation phase (s), one pixel in r_s at the hole
uniform vec4 uG[ ${ MAX } ]; // tint rgb, spin (rad/s at the inner edge)
uniform vec4 uH[ ${ MAX } ]; // frame-dragging twist of the background (rad at the Einstein ring), -, -, -
uniform vec4 uShell; // centre (world), radius (m)
uniform vec4 uShell2; // thickness (m), amount, -, -
uniform int uCount;
uniform vec2 uNearFar;
uniform float uAspect;
uniform float uPx; // one pixel in screen-height units
uniform vec3 uCamPos;
uniform mat3 uCamRot;
uniform vec2 uInvP; // 1 / projection[0][0], 1 / projection[1][1]
in vec2 vUv;
out vec4 fragColor;
vec3 blackbody(float k) { return textureLod(uBlackbody, vec2(clamp(log(k / 500.0) / log(40.0), 0.0, 1.0), 0.5), 0.0).rgb; }
// critical impact parameter for bending k (k = 1: Schwarzschild, 3 sqrt(3) / 2)
float critB(float k) { return k >= 0.6667 ? 2.598076 * k : inversesqrt(max(1.0 - k, 1e-3)); }
// banded turbulence in the disk frame: a circle through the noise for the angle (no seam), radius
// stretched so the structure runs in long arcs
float bands(float a, float rho, float seed, float as) { // rho: 3 * r / r_in (r_s at the usual ISCO)
vec2 cs = vec2(cos(a), sin(a)) * as;
float n0 = textureLod(uNoise3D, vec3(cs * 0.05 + 0.5, rho * 0.06 + seed * 0.3), 0.0).r;
float n1 = textureLod(uNoise3D, vec3(cs * 0.16, rho * 0.15 + seed), 0.0).r;
float n2 = textureLod(uNoise3D, vec3(cs * 0.4 + 0.31, rho * 0.45 + seed * 1.7 + 0.17), 0.0).r;
float n3 = textureLod(uNoise3D, vec3(cs * 1.1 + 0.63, rho * 1.4 + seed * 2.3 + 0.41), 0.0).r;
return (n1 * 0.55 + n2 * 0.3 + n3 * 0.15) * (0.55 + 0.9 * n0);
}
// one pass of the ray (direction v, photon going -v) through the disk plane at xc (r_s units)
void diskHit(int i, vec3 xc, vec3 v, vec3 n, vec3 e1, vec3 e2, inout vec3 em, inout float tr) {
float rho = length(xc), rin = uE[i].x, rout = uE[i].y;
if (rho < rin * 0.8 || rho > rout) return;
vec3 eR = xc / rho, eT = cross(n, eR), vd = normalize(v);
float x = rho / rin;
// Kepler speed (static frame) -> Doppler, times gravitational redshift
float beta = min(uE[i].w * sqrt(0.5 / max(rho - 1.0, 0.6)), 0.95);
float dop = sqrt(1.0 - beta * beta) / (1.0 - beta * dot(eT, -vd));
float g = dop * sqrt(max(1.0 - uF[i].x / rho, 0.04));
// differential rotation; two half-period-shifted layers hide each layer's shear reset
float a0 = atan(dot(eR, e2), dot(eR, e1));
float om = uG[i].w * pow(x, -1.5), P = 3.0;
float f0 = fract(uF[i].z / P), f1 = fract(uF[i].z / P + 0.5), w0 = 1.0 - abs(2.0 * f0 - 1.0);
// no bending = the blast ring after the collapse: torn into clumps rather than lanes
float as = uF[i].x < 1e-3 ? 5.0 : 1.0;
float dn = mix(bands(a0 - om * f1 * P, 3.0 * x, 0.53, as), bands(a0 - om * f0 * P, 3.0 * x, 0.0, as), w0);
dn = smoothstep(0.3, 0.75, dn);
if (as > 1.0) dn *= dn;
float edge = smoothstep(rin * 0.8, rin * 1.25, rho) * (1.0 - smoothstep(mix(rin, rout, 0.3), rout, rho));
float dens = edge * (0.35 + 1.8 * dn * dn);
float cosI = abs(dot(vd, n));
float a = 1.0 - exp(-2.2 * dens / max(cosI, 0.05));
// thin disk: T ~ r^-3/4 (Shakura-Sunyaev, inner zero softened), hot lanes a little hotter
float T = uE[i].z * pow(x, -0.75) * pow(max(1.0 - 0.9 * inversesqrt(max(x, 1.0)), 0.02), 0.25) * 1.6 * (0.85 + 0.3 * dn) * g;
float I = uD[i].w * pow(x, -1.8) * g * g * g * (0.15 + 1.4 * dn);
em += tr * a * blackbody(T) * uG[i].rgb * I;
tr *= 1.0 - a;
}
void main() {
vec2 asp = vec2(uAspect, 1.0), p = vUv * asp;
float d = texture(tDepth, vUv).r;
float zp = uNearFar.x * uNearFar.y / (uNearFar.y - d * (uNearFar.y - uNearFar.x));
vec3 rd = normalize(uCamRot * vec3((vUv * 2.0 - 1.0) * uInvP, -1.0));
vec3 fwd = uCamRot * vec3(0.0, 0.0, -1.0);
float cosV = dot(rd, fwd);
vec2 q = p;
float shadow = 1.0, ring = 0.0, tr = 1.0;
vec3 em = vec3(0.0);
for (int i = 0; i < ${ MAX } ; i++) {
if (i >= uCount) break;
vec2 t = p - uA[i].xy;
float r2 = max(dot(t, t), 1e-10), r = sqrt(r2);
float w = clamp((zp - uB[i].x) * uB[i].w, 0.0, 1.0);
w *= w * (3.0 - 2.0 * w);
q -= t * (uA[i].z * w / r2);
float rs = uC[i].w;
if (uH[i].x != 0.0) {
// frame dragging: the background swirls round a spinning hole, ~1 / r^2
float ang = uH[i].x * w * uA[i].z / (r2 + 0.3 * uA[i].z), cs = cos(ang), sn = sin(ang);
vec2 tq = q - uA[i].xy;
q = uA[i].xy + mat2(cs, sn, -sn, cs) * tq;
}
if (rs <= 0.0) {
if (zp < uB[i].x - uB[i].y * 1.05) continue; // something in front hides this hole
shadow *= smoothstep(uA[i].w - uPx, uA[i].w + uPx, r);
// Einstein ring brightening where the magnification 1 / (1 - (thetaE / theta)^4) peaks
float te = sqrt(uA[i].z * w), x = (r - te) / (0.1 * te + 2.0 * uPx);
ring += uB[i].z * exp(-x * x);
continue;
}
// --- disk: trace the camera ray through the hole's region (units of r_s)
float rout = uE[i].y, RB = rout * 1.08 + 3.0;
if (zp < uB[i].x - RB * rs) continue; // all of it is behind something in front
vec3 o = (uCamPos - uC[i].xyz) / rs;
float bo = dot(o, rd), disc = bo * bo - dot(o, o) + RB * RB;
vec3 Lm = cross(o, rd);
float h2 = dot(Lm, Lm), b = sqrt(h2), k = uF[i].x;
float bc = critB(k), aa = uF[i].w;
vec3 n = uD[i].xyz;
vec3 e1 = normalize(cross(n, abs(n.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0))), e2 = cross(n, e1);
if (disc > 0.0 && -bo + sqrt(disc) > 0.0) {
float t0 = max(-bo - sqrt(disc), 0.0);
vec3 x = o + rd * t0, v = rd;
float zs = zp / cosV / rs; // scene hit distance along the ray (r_s)
bool front = zp < uB[i].x - 2.0 * rs; // something between the camera and the hole
if (k < 1e-3) {
// no bending (after the collapse): one straight crossing
float den = dot(rd, n);
float tc = abs(den) > 1e-5 ? -dot(o, n) / den : -1.0;
if (tc > 0.0 && tc < zs + 0.3 / rs) diskHit(i, o + rd * tc, rd, n, e1, e2, em, tr);
} else {
float kb = 1.5 * k * h2, y0 = dot(x, n), travelled = 0.0;
float rr = dot(x, x);
vec3 acc = -kb * x / (rr * rr * sqrt(rr));
for (int s = 0; s < ${ STEPS } ; s++) {
float rx = sqrt(rr), dt = clamp(0.11 * rx, 0.03, 2.5);
// kick-drift-kick leapfrog
v += acc * (0.5 * dt);
vec3 xn = x + v * dt;
rr = dot(xn, xn);
acc = -kb * xn / (rr * rr * sqrt(rr));
v += acc * (0.5 * dt);
float y1 = dot(xn, n);
if (y0 * y1 < 0.0) {
vec3 xc = mix(x, xn, y0 / (y0 - y1));
// nearly straight rays meet the scene at its depth; bent ones are images of the far side,
// hidden only by what stands in front of the hole
bool straight = dot(normalize(v), rd) > 0.985;
if (straight ? t0 + travelled + length(xc - x) < zs + 0.3 / rs : !front) diskHit(i, xc, v, n, e1, e2, em, tr);
}
travelled += dt * length(v);
y0 = y1; x = xn;
if (rr < 1.0 || tr < 0.01 || (rr > RB * RB && dot(x, v) > 0.0)) break;
}
}
}
// shadow edge at the critical impact parameter, and the photon ring hugging it
float sh = uF[i].y;
if (sh > 0.0 && zp > uB[i].x - 1.5 * bc * rs - 0.35) {
shadow *= 1.0 - sh * (1.0 - smoothstep(bc - aa, bc + aa, b));
float rw = max(aa * 0.9, 0.006 * bc), xr = (b - bc - 1.6 * rw) / rw;
vec3 c = o - rd * bo, ce = c - n * dot(c, n);
float beta = 0.5 * min(uE[i].w, 1.9);
float dop = sqrt(1.0 - beta * beta) / (1.0 - beta * dot(cross(n, normalize(ce + 1e-5)), -rd));
em += tr * sh * exp(-xr * xr) * blackbody(uE[i].z * 1.3 * dop) * uG[i].rgb * (uD[i].w * 0.7 * dop * dop * dop);
}
}
for (int i = 0; i < ${ MAX } ; i++) { // keep lookups out of the hole's own image
if (i >= uCount) break;
if (uC[i].w > 0.0) continue; // a traced hole draws no opaque horizon into the source
if (zp < uB[i].x - uB[i].y * 1.05) continue; // in front of the hole: leave it be
vec2 t = q - uA[i].xy;
float r = length(t), rmin = uA[i].w * 1.08 + 2.0 * uPx;
if (r < rmin) q = uA[i].xy + (r > 1e-6 ? t / r : vec2(0.0, 1.0)) * rmin;
}
vec2 uv = q / asp, e = min(uv, 1.0 - uv);
float fade = smoothstep(0.0, 0.06, min(e.x, e.y));
uv = mix(vUv, uv, fade);
vec3 col = texture(tSrc, uv).rgb * ((1.0 + ring * fade) * shadow * tr) + em;
// photographic-negative spherical shell: path length through it, brightest at its limb
if (uShell2.y > 0.0) {
vec3 c = uShell.xyz - uCamPos;
float tc = dot(c, rd), d2 = dot(c, c) - tc * tc, R = uShell.w, Ri = max(R - uShell2.x, 0.0);
float chord = sqrt(max(R * R - d2, 0.0)) - sqrt(max(Ri * Ri - d2, 0.0));
float m = chord / max(sqrt(R * R - Ri * Ri), 1e-4);
m *= smoothstep(-0.2, 0.2, zp / cosV - (tc - sqrt(max(R * R - d2, 0.0))));
float l = dot(col, vec3(0.2126, 0.7152, 0.0722));
vec3 neg = vec3(0.55, 0.42, 1.0) * (2.2 / (1.0 + 3.0 * l)) + vec3(0.9, 0.95, 1.0) * 0.6 * exp(-24.0 * (1.0 - m) * (1.0 - m));
col = mix(col, neg, clamp(m * uShell2.y, 0.0, 1.0));
}
fragColor = vec4(col, 1.0);
} `
;
const
=
new
THREE. Vector3
(
)
;
export
class
Lens
{
=
false
;
=
false
;
constructor
(
renderer
)
{
this
.
renderer
=
;
this
.
lenses
=
Array
.
from
(
{
length
:
MAX
}
,
(
)
=>
(
{
pos
:
new
THREE. Vector3
(
)
,
einstein
:
1
,
horizon
:
0.4
,
strength
:
0
,
disk
:
{
on
:
false
,
axis
:
new
THREE. Vector3
(
0
,
1
,
0
)
,
rs
:
0.12
,
inner
:
3
,
outer
:
14
,
temperature
:
4800
,
beaming
:
0.6
,
intensity
:
6
,
tint
:
new
THREE. Color
(
1
,
1
,
1
)
,
phase
:
0
,
spin
:
2.2
,
bend
:
1
,
shadow
:
1
,
twist
:
0
,
}
,
}
)
)
;
this
.
shell
=
{
pos
:
new
THREE. Vector3
(
)
,
radius
:
1
,
thickness
:
0.3
,
amount
:
0
}
;
this
.
target
=
new
THREE. WebGLRenderTarget
(
1
,
1
,
{
type
:
THREE
.
HalfFloatType
,
minFilter
:
THREE
.
LinearFilter
,
magFilter
:
THREE
.
LinearFilter
,
depthBuffer
:
false
,
stencilBuffer
:
false
,
generateMipmaps
:
false
,
}
)
;
const
v4
=
(
)
=>
Array
.
from
(
{
length
:
MAX
}
,
(
)
=>
new
THREE. Vector4
(
)
)
;
this
.
quad
=
new
FullscreenQuad
(
rawPass
(
FRAG
,
{
tSrc
:
{
value
:
null
}
,
tDepth
:
{
value
:
null
}
,
uNoise3D
:
U
.
uNoise3D
,
uBlackbody
:
U
.
uBlackbody
,
uA
:
{
value
:
v4
(
)
}
,
uB
:
{
value
:
v4
(
)
}
,
uC
:
{
value
:
v4
(
)
}
,
uD
:
{
value
:
v4
(
)
}
,
uE
:
{
value
:
v4
(
)
}
,
uF
:
{
value
:
v4
(
)
}
,
uG
:
{
value
:
v4
(
)
}
,
uH
:
{
value
:
v4
(
)
}
,
uShell
:
{
value
:
new
THREE. Vector4
(
)
}
,
uShell2
:
{
value
:
new
THREE. Vector4
(
)
}
,
uCount
:
{
value
:
0
}
,
uNearFar
:
{
value
:
new
THREE. Vector2
(
)
}
,
uAspect
:
{
value
:
1
}
,
uPx
:
{
value
:
1
}
,
uCamPos
:
{
value
:
new
THREE. Vector3
(
)
}
,
uCamRot
:
{
value
:
new
THREE. Matrix3
(
)
}
,
uInvP
:
{
value
:
new
THREE. Vector2
(
)
}
,
}
)
)
;
const
=
.
getDrawingBufferSize
(
new
THREE. Vector2
(
)
)
;
this
.
setSize
(
.
x
,
.
y
)
;
}
set
(
,
,
,
,
=
1
)
{
const
=
this
.
lenses
[
]
;
.
pos
.
copy
(
)
;
.
einstein
=
;
.
horizon
=
;
.
strength
=
;
.
disk
.
on
=
false
;
}
setSize
(
width, height
)
{
const
=
Math
.
max
(
1
,
Math
.
floor
(
)
)
,
=
Math
.
max
(
1
,
Math
.
floor
(
)
)
;
this
.
target
.
setSize
(
,
)
;
const
=
this
.
quad
.
material
.
uniforms
;
.
uAspect
.
value
=
/
;
.
uPx
.
value
=
1
/
;
}
render
(
srcTex, depthTex, camera
)
{
if
(
!
this
.
active
)
return
;
const
=
this
.
quad
.
material
.
uniforms
,
=
.
uAspect
.
value
;
const
=
.
projectionMatrix
.
elements
[
5
]
*
0.5
;
let
=
0
;
for
(
const
of
this
.
lenses
)
{
if
(
!
(
.
strength
>
0
)
)
continue
;
.
copy
(
.
pos
)
.
applyMatrix4
(
.
matrixWorldInverse
)
;
const
=
-
.
z
;
const
D
=
.
disk
,
=
D
.
on
&&
D
.
rs
>
0
;
if
(
<=
.
near
&&
!
)
continue
;
.
applyMatrix4
(
.
projectionMatrix
)
;
const
=
Math
.
max
(
,
.
near
)
,
=
.
einstein
*
/
;
.
uA
.
value
[
]
.
set
(
(
.
x
*
0.5
+
0.5
)
*
,
.
y
*
0.5
+
0.5
,
>
.
near
?
*
*
.
strength
:
0
,
.
horizon
*
/
)
;
.
uB
.
value
[
]
.
set
(
,
.
horizon
,
?
0
:
1.5
*
Math
.
min
(
.
strength
,
2
)
,
1
/
Math
.
max
(
2
*
.
einstein
,
0.1
)
)
;
.
uC
.
value
[
]
.
set
(
.
pos
.
x
,
.
pos
.
y
,
.
pos
.
z
,
?
D
.
rs
:
0
)
;
.
uH
.
value
[
]
.
set
(
?
D
.
twist
:
0
,
0
,
0
,
0
)
;
if
(
)
{
.
uD
.
value
[
]
.
set
(
D
.
axis
.
x
,
D
.
axis
.
y
,
D
.
axis
.
z
,
D
.
intensity
)
;
.
uE
.
value
[
]
.
set
(
D
.
inner
,
D
.
outer
,
D
.
temperature
,
D
.
beaming
)
;
.
uF
.
value
[
]
.
set
(
D
.
bend
,
D
.
shadow
,
D
.
phase
,
.
uPx
.
value
*
/
(
*
D
.
rs
)
)
;
.
uG
.
value
[
]
.
set
(
D
.
tint
.
r
,
D
.
tint
.
g
,
D
.
tint
.
b
,
D
.
spin
)
;
}
++
;
}
const
=
this
.
shell
;
.
uShell
.
value
.
set
(
.
pos
.
x
,
.
pos
.
y
,
.
pos
.
z
,
.
radius
)
;
.
uShell2
.
value
.
set
(
.
thickness
,
Math
.
max
(
.
amount
,
0
)
,
0
,
0
)
;
if
(
!
&&
!
this
.
warming
&&
!
(
.
amount
>
0
)
)
return
;
.
uCount
.
value
=
;
.
tSrc
.
value
=
;
.
tDepth
.
value
=
;
.
uNearFar
.
value
.
set
(
.
near
,
.
far
)
;
const
=
.
matrixWorld
.
elements
,
=
.
projectionMatrix
.
elements
;
.
uCamPos
.
value
.
set
(
[
12
]
,
[
13
]
,
[
14
]
)
;
.
uCamRot
.
value
.
setFromMatrix4
(
.
matrixWorld
)
;
.
uInvP
.
value
.
set
(
1
/
[
0
]
,
1
/
[
5
]
)
;
const
=
this
.
renderer
,
=
.
getRenderTarget
(
)
,
=
.
autoClear
;
.
autoClear
=
false
;
this
.
quad
.
render
(
,
this
.
target
)
;
.
setRenderTarget
(
)
;
.
autoClear
=
;
return
this
.
target
.
texture
;
}
dispose
(
)
{
this
.
target
.
dispose
(
)
;
this
.
quad
.
material
.
dispose
(
)
;
}
}