Agent Harness · VibeGit
Agent Harness Публичная копия обвязки агентной разработки: гейты, journeys, скиллы и шаблоны. Без ключей и личных данных.
agent-harness / tools / spells-assets / ue / vfx / FxTarget.js 154 строк · изменён 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
import * as THREE from 'three' ;
import { FullscreenQuad , rawPass } from '../engine/fullscreen.js' ;
import { U , COMMON_GLSL , GROUND_GLSL } from './common.js' ;
export const DEBUG_VIEWS = { off : 0 ,
renderer
fw w scale fh h scale
fw fh
w h
w fw h fh
fw fh
r
timer
r
r
r
r
r fxScene camera
timer
u
u sceneTex
u partState
u
r
overdraw
:
1
,
emission
:
2
,
media
:
3
,
distortion
:
4
,
'ground A'
:
5
,
'ground B'
:
6
,
particles
:
7
}
;
const
PREPASS
=
`
precision highp float;
uniform highp sampler2D uSceneDepth;
uniform vec2 uRatio; // full / fx resolution
uniform vec2 uResolution;
void main() {
ivec2 b = ivec2(floor(floor(gl_FragCoord.xy) * uRatio)); // block origin, same as sceneViewZ
ivec2 m = ivec2(uResolution) - 1;
float d = texelFetch(uSceneDepth, min(b, m), 0).r;
d = max(d, texelFetch(uSceneDepth, min(b + ivec2(1, 0), m), 0).r);
d = max(d, texelFetch(uSceneDepth, min(b + ivec2(0, 1), m), 0).r);
d = max(d, texelFetch(uSceneDepth, min(b + ivec2(1, 1), m), 0).r);
gl_FragDepth = d;
} `
;
const
COMPOSITE
=
`
precision highp float;
precision highp sampler2D;
${ COMMON_GLSL }
${ GROUND_GLSL }
uniform sampler2D uScene;
uniform sampler2D uMedia;
uniform sampler2D uWeight;
uniform sampler2D uEmit;
uniform highp sampler2D uFxDepth;
uniform highp sampler2D uSceneDepth;
uniform highp sampler2D uPartState;
uniform vec4 uParams; // smoke occludes glow, distortion scale, CA, -
uniform vec4 uInvert; // centre uv, radius (uv, aspect-corrected), amount
in vec2 vUv;
out vec4 outColor;
void main() {
float zf = linearDepth(texture(uSceneDepth, vUv).r);
vec2 hp = vUv * uFxResolution - 0.5;
ivec2 b = ivec2(floor(hp));
ivec2 m = ivec2(uFxResolution) - 1;
ivec2 t0 = clamp(b, ivec2(0), m), t1 = clamp(b + ivec2(1, 0), ivec2(0), m);
ivec2 t2 = clamp(b + ivec2(0, 1), ivec2(0), m), t3 = clamp(b + ivec2(1, 1), ivec2(0), m);
float z0 = linearDepth(texelFetch(uFxDepth, t0, 0).r), z1 = linearDepth(texelFetch(uFxDepth, t1, 0).r);
float z2 = linearDepth(texelFetch(uFxDepth, t2, 0).r), z3 = linearDepth(texelFetch(uFxDepth, t3, 0).r);
float tol = 0.04 * zf + 0.05;
vec4 d4 = abs(vec4(z0, z1, z2, z3) - zf);
vec4 med, wt, em;
bool fx = true;
if (max(max(d4.x, d4.y), max(d4.z, d4.w)) < tol) {
med = texture(uMedia, vUv); wt = texture(uWeight, vUv); em = texture(uEmit, vUv);
} else {
// nearest-depth tap; if this pixel is in front of all of them, the FX there was drawn
// against something farther (a silhouette), so drop it
ivec2 t = t0; float best = d4.x;
if (d4.y < best) { best = d4.y; t = t1; }
if (d4.z < best) { best = d4.z; t = t2; }
if (d4.w < best) { best = d4.w; t = t3; }
if (zf < min(min(z0, z1), min(z2, z3)) - tol) fx = false;
med = texelFetch(uMedia, t, 0); wt = texelFetch(uWeight, t, 0); em = texelFetch(uEmit, t, 0);
}
if (!fx) { med = vec4(0.0, 0.0, 0.0, 1.0); wt = vec4(0.0); em = vec4(0.0); }
float rev = clamp(med.a, 0.0, 1.0);
vec3 accum = med.rgb / max(wt.r, 1e-4);
vec2 dist = wt.gb * uParams.y;
vec2 suv = vUv + dist;
vec3 scene;
if (uParams.z > 0.0 && dot(dist, dist) > 1e-8) {
vec2 ca = dist * uParams.z * 0.6;
scene = vec3(texture(uScene, suv + ca).r, texture(uScene, suv).g, texture(uScene, suv - ca).b);
} else scene = texture(uScene, suv).rgb;
vec3 col = scene * rev + accum * (1.0 - rev) + em.rgb * mix(1.0, rev, uParams.x);
// void collapse: a brief photographic-negative shell
if (uInvert.w > 0.0) {
vec2 q = (vUv - uInvert.xy) * vec2(uResolution.x / uResolution.y, 1.0);
float r = length(q);
float shell = smoothstep(uInvert.z, uInvert.z * 0.8, r) * uInvert.w;
float l = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = mix(col, vec3(0.6, 0.5, 1.0) * max(1.2 - l, 0.0) * 0.6, shell);
}
if (uDebug > 0.5) {
int v = int(uDebug + 0.5);
if (v == 1) col = scene * 0.15 + vec3(1.0, 0.25, 0.05) * em.r * 25.0; // overdraw: fxOut wrote a constant
else if (v == 2) col = em.rgb;
else if (v == 3) col = accum * (1.0 - rev);
else if (v == 4) col = vec3(0.5 + dist * 40.0, 0.5);
else if (v == 5) col = groundA(mix(uGroundRect.xy, uGroundRect.xy + uGroundRect.z, vUv)).rgb * vec3(1.0, 0.6, 1.0) + vec3(0.0, 0.0, groundA(mix(uGroundRect.xy, uGroundRect.xy + uGroundRect.z, vUv)).a);
else if (v == 6) col = groundB(mix(uGroundRect.xy, uGroundRect.xy + uGroundRect.z, vUv)).rgb + groundB(mix(uGroundRect.xy, uGroundRect.xy + uGroundRect.z, vUv)).a * 0.5;
else if (v == 7) { vec4 s = texture(uPartState, vUv); col = s.w < 1e8 ? fract(abs(s.xyz) * 0.1) : vec3(0.02); }
}
outColor = vec4(col, 1.0);
} `
;
export
class
FxTarget
{
constructor
(
renderer
)
{
this
.
renderer
=
;
this
.
rt
=
new
THREE. WebGLRenderTarget
(
1
,
1
,
{
count
:
3
,
type
:
THREE
.
HalfFloatType
,
minFilter
:
THREE
.
LinearFilter
,
magFilter
:
THREE
.
LinearFilter
,
generateMipmaps
:
false
,
depthTexture
:
new
THREE. DepthTexture
(
1
,
1
,
THREE
.
FloatType
)
,
}
)
;
this
.
comp
=
new
THREE. WebGLRenderTarget
(
1
,
1
,
{
type
:
THREE
.
HalfFloatType
,
depthBuffer
:
false
,
generateMipmaps
:
false
}
)
;
this
.
ratio
=
new
THREE. Vector2
(
2
,
2
)
;
this
.
prepass
=
new
FullscreenQuad
(
rawPass
(
PREPASS
,
{
uSceneDepth
:
U
.
uSceneDepth
,
uRatio
:
{
value
:
this
.
ratio
}
,
uResolution
:
U
.
uResolution
}
,
{
depthTest
:
true
,
depthWrite
:
true
,
depthFunc
:
THREE
.
AlwaysDepth
,
colorWrite
:
false
,
}
)
)
;
this
.
params
=
{
smokeOccludesGlow
:
0.5
,
distortion
:
1
,
ca
:
0.35
}
;
this
.
invert
=
new
THREE. Vector4
(
)
;
this
.
composite
=
new
FullscreenQuad
(
rawPass
(
COMPOSITE
,
{
...
U
,
uScene
:
{
value
:
null
}
,
uMedia
:
{
value
:
this
.
rt
.
textures
[
0
]
}
,
uWeight
:
{
value
:
this
.
rt
.
textures
[
1
]
}
,
uEmit
:
{
value
:
this
.
rt
.
textures
[
2
]
}
,
uFxDepth
:
{
value
:
this
.
rt
.
depthTexture
}
,
uPartState
:
{
value
:
null
}
,
uParams
:
{
value
:
new
THREE. Vector4
(
)
}
,
uInvert
:
{
value
:
this
.
invert
}
,
}
)
)
;
}
setSize
(
w, h, scale
)
{
const
=
Math
.
max
(
1
,
Math
.
ceil
(
*
)
)
,
=
Math
.
max
(
1
,
Math
.
ceil
(
*
)
)
;
this
.
rt
.
setSize
(
,
)
;
this
.
comp
.
setSize
(
,
)
;
this
.
ratio
.
set
(
/
,
/
)
;
U
.
uFxResolution
.
value
.
set
(
,
)
;
}
render
(
fxScene, camera, sceneTex, timer, partState = null
)
{
const
=
this
.
renderer
;
?.
begin
(
'fx'
)
;
.
setRenderTarget
(
this
.
rt
)
;
.
setClearColor
(
0x000000
,
1
)
;
.
clear
(
true
,
true
,
false
)
;
this
.
prepass
.
render
(
,
this
.
rt
)
;
.
render
(
,
)
;
?.
begin
(
'fxComp'
)
;
const
=
this
.
composite
.
material
.
uniforms
;
.
uScene
.
value
=
;
.
uPartState
.
value
=
;
.
uParams
.
value
.
set
(
this
.
params
.
smokeOccludesGlow
,
this
.
params
.
distortion
,
this
.
params
.
ca
,
0
)
;
this
.
composite
.
render
(
,
this
.
comp
)
;
return
this
.
comp
.
texture
;
}
}