Agent Harness · VibeGit
Agent Harness Публичная копия обвязки агентной разработки: гейты, journeys, скиллы и шаблоны. Без ключей и личных данных.
agent-harness / tools / water-assets / uw / scene / sky.js 189 строк · изменён 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
import * as THREE from 'three' ;
import { FullscreenQuad , rawPass } from '../engine/fullscreen.js' ;
import { Atmosphere , ATMOSPHERE_GLSL , OBSERVER_ALTITUDE , atmosphereCoefficients, transmittance } from './atmosphere.js' ;
const
renderer
p r
phi p
theta p
phi theta
c p
c
fade p
p fade
target r face r mip r
r c p
u
u p
f f f
u f
f
r f
r
r target face mip
CUBE_SIZE
=
1024
;
const
CLOUD_H
=
2.5
;
const
BG_VERT
=
`
out vec3 vDir;
void main() {
vDir = position;
vec4 p = projectionMatrix * mat4(mat3(viewMatrix)) * vec4(position, 1.0);
gl_Position = p.xyww; // far plane
} `
;
const
BG_FRAG
=
`
uniform samplerCube uCube;
uniform vec3 uSunDir;
uniform vec3 uSunColor;
in vec3 vDir;
out vec4 fragColor;
void main() {
vec3 d = normalize(vDir);
vec4 sky = textureLod(uCube, vec3(d.x, max(d.y, 0.0), d.z), 0.0);
float c = dot(d, uSunDir);
// 0.27 deg disc with limb darkening, plus a tight glow; hidden by clouds (cube alpha)
float disc = smoothstep(0.999985, 0.999992, c) * (0.6 + 0.4 * smoothstep(0.999985, 1.0, c));
vec3 col = sky.rgb + uSunColor * (disc * 900.0 + pow(max(c, 0.0), 2200.0) * 1.5) * step(0.0, d.y) * sky.a;
fragColor = vec4(col, 1.0);
} `
;
const
CUBE_FRAG
=
ATMOSPHERE_GLSL
+
`
const float CLOUD_H = ${ CLOUD_H . toFixed ( 2 ) } ;
const vec3 WATER = vec3(0.02, 0.035, 0.045); // deep-water body reflectance for the lower hemisphere
uniform int uFace;
uniform vec3 uSunDir;
uniform vec3 uSunColor;
uniform float uCloudCoverage;
in vec2 vUv;
out vec4 fragColor;
vec3 faceDir(vec2 uv) {
vec2 c = uv * 2.0 - 1.0;
if (uFace == 0) return vec3(1.0, -c.y, -c.x);
if (uFace == 1) return vec3(-1.0, -c.y, c.x);
if (uFace == 2) return vec3(c.x, 1.0, c.y);
if (uFace == 3) return vec3(c.x, -1.0, -c.y);
if (uFace == 4) return vec3(c.x, -c.y, 1.0);
return vec3(-c.x, -c.y, -1.0);
}
// cloud layer ported from three's Sky.js (static: time = 0, its cloudScale/elevation/density)
vec2 gradient(vec2 i) {
vec3 p = fract(i.xyx * vec3(0.1031, 0.1030, 0.0973));
p += dot(p, p.yzx + 33.33);
return fract((p.xx + p.yz) * p.zy) * 2.0 - 1.0;
}
float noise(vec2 p) {
vec2 i = floor(p), f = fract(p);
vec2 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);
float a = dot(gradient(i), f);
float b = dot(gradient(i + vec2(1.0, 0.0)), f - vec2(1.0, 0.0));
float c = dot(gradient(i + vec2(0.0, 1.0)), f - vec2(0.0, 1.0));
float d = dot(gradient(i + vec2(1.0, 1.0)), f - vec2(1.0, 1.0));
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y) * 1.6;
}
float fbm(vec2 p) {
float s = 0.0, a = 1.0;
for (int i = 0; i < 4; i++) { s += a * noise(p); a *= 0.5; p *= 2.0; }
return s;
}
void main() {
vec3 d = normalize(faceDir(vUv));
vec3 up = skyView(vec3(0.0, 1.0, 0.0), uSunDir);
if (d.y < 0.0) {
// below the horizon: sea, Fresnel between the mirrored sky and a dark water body
float F = 0.02 + 0.98 * pow(1.0 + d.y, 5.0);
vec3 body = WATER * (uSunColor * max(uSunDir.y, 0.0) + up);
fragColor = vec4(mix(body, skyView(vec3(d.x, -d.y, d.z), uSunDir), F), 1.0);
return;
}
vec3 col = skyView(d, uSunDir);
float vis = 1.0;
if (d.y > 1e-3 && uCloudCoverage > 0.0) {
vec2 p = d.xz / d.y * 0.396; // cloudScale 2e-4 * 1000 / mix(1, 0.1, cloudElevation 0.55)
float n = clamp(fbm(p) * 0.7 + 0.5, 0.0, 1.0);
float th = 1.0 - clamp(uCloudCoverage + noise(p * 0.3) * 0.222, 0.0, 1.0); // clear gaps / dense banks
float fade = smoothstep(0.0, 0.063, d.y);
float mask = smoothstep(th, th + 0.3, n) * fade;
float depth = max(0.0, n - th);
float beer = exp(-4.0 * depth);
float shade = mix(0.45, 1.0, clamp(beer * (1.0 - beer * beer) * 2.6, 0.0, 1.0)); // beer-powder
float c = dot(d, uSunDir);
float silver = clamp(0.51 / pow(1.49 - c * 1.4, 1.5), 0.0, 3.0); // HG g = 0.7 rim toward the sun
float edge = mask * (1.0 - mask) * 4.0;
float alpha = (1.0 - exp(-depth * 6.6)) * fade; // cloudDensity 0.55
// the deck point along d: sunlight through the atmosphere (and planet shadow) to it, and the
// eye-to-deck transmittance so distant clouds dissolve into the haze
float r0 = RB + OBS_H, rc = RB + CLOUD_H;
float t = -r0 * d.y + sqrt(r0 * r0 * d.y * d.y + (rc - r0) * (rc + r0));
float muV = (r0 * d.y + t) / rc;
float muS = clamp((r0 * uSunDir.y + t * c) / rc, -1.0, 1.0);
vec3 sun = uSunIllum * transmittance(CLOUD_H, muS) * sunVisible(CLOUD_H, rc, muS) * 0.22; // albedo/pi
vec3 cloud = up + sun * (shade + silver * edge * 0.6);
vec3 tv = clamp(transmittance(OBS_H, d.y) / max(transmittance(CLOUD_H, muV), vec3(1e-4)), 0.0, 1.0);
col = mix(col, mix(col, cloud, tv), alpha);
vis = 1.0 - alpha;
}
fragColor = vec4(col, vis);
} `
;
export
class
SkySystem
{
constructor
(
renderer
)
{
this
.
renderer
=
;
this
.
cubeSize
=
CUBE_SIZE
;
this
.
sunDir
=
new
THREE. Vector3
(
0
,
1
,
0
)
;
this
.
sunColor
=
new
THREE. Vector3
(
1
,
1
,
1
)
;
this
.
params
=
{
elevation
:
3.5
,
azimuth
:
205
,
turbidity
:
2
,
rayleigh
:
1
,
cloudCoverage
:
0.38
,
sunIntensity
:
9
}
;
this
.
atmosphere
=
new
Atmosphere
(
)
;
this
.
cubeRT
=
new
THREE. WebGLCubeRenderTarget
(
CUBE_SIZE
,
{
type
:
THREE
.
HalfFloatType
,
generateMipmaps
:
true
,
depthBuffer
:
false
,
minFilter
:
THREE
.
LinearMipmapLinearFilter
,
magFilter
:
THREE
.
LinearFilter
,
}
)
;
this
.
cube
=
this
.
cubeRT
.
texture
;
this
.
cubePass
=
new
FullscreenQuad
(
rawPass
(
CUBE_FRAG
,
{
...
this
.
atmosphere
.
uniforms
,
uFace
:
{
value
:
0
}
,
uSunDir
:
{
value
:
this
.
sunDir
}
,
uSunColor
:
{
value
:
this
.
sunColor
}
,
uCloudCoverage
:
{
value
:
0
}
,
}
)
)
;
this
.
camera
=
new
THREE. Camera
(
)
;
this
.
background
=
new
THREE. Mesh
(
new
THREE. BoxGeometry
(
1
,
1
,
1
)
,
new
THREE. ShaderMaterial
(
{
glslVersion
:
THREE
.
GLSL3
,
vertexShader
:
BG_VERT
,
fragmentShader
:
BG_FRAG
,
uniforms
:
{
uCube
:
{
value
:
this
.
cube
}
,
uSunDir
:
{
value
:
this
.
sunDir
}
,
uSunColor
:
{
value
:
this
.
sunColor
}
}
,
side
:
THREE
.
BackSide
,
depthWrite
:
false
,
}
)
,
)
;
this
.
background
.
frustumCulled
=
false
;
this
.
background
.
renderOrder
=
1000
;
}
update
(
)
{
const
=
this
.
params
,
=
this
.
renderer
;
const
=
THREE
.
MathUtils
.
degToRad
(
90
-
.
elevation
)
;
const
=
THREE
.
MathUtils
.
degToRad
(
.
azimuth
)
;
this
.
sunDir
.
setFromSphericalCoords
(
1
,
,
)
;
const
=
atmosphereCoefficients
(
)
;
const
T
=
transmittance
(
,
OBSERVER_ALTITUDE
,
Math
.
max
(
this
.
sunDir
.
y
,
0
)
)
;
const
=
THREE
.
MathUtils
.
smoothstep
(
.
elevation
,
-
2
,
2
)
;
this
.
sunColor
.
set
(
T
[
0
]
,
T
[
1
]
,
T
[
2
]
)
.
multiplyScalar
(
.
sunIntensity
*
)
;
const
=
.
getRenderTarget
(
)
,
=
.
getActiveCubeFace
(
)
,
=
.
getActiveMipmapLevel
(
)
;
this
.
atmosphere
.
update
(
,
,
this
.
sunDir
.
y
,
Math
.
PI
*
.
sunIntensity
)
;
const
=
this
.
cubePass
.
material
.
uniforms
;
.
uCloudCoverage
.
value
=
.
cloudCoverage
;
for
(
let
=
0
;
<
6
;
++
)
{
.
uFace
.
value
=
;
this
.
cube
.
generateMipmaps
=
===
5
;
.
setRenderTarget
(
this
.
cubeRT
,
)
;
.
render
(
this
.
cubePass
.
mesh
,
this
.
camera
)
;
}
.
setRenderTarget
(
,
,
)
;
this
.
cube
.
needsPMREMUpdate
=
true
;
}
}