voxljs 0.1.0 → 0.1.1
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/dist/audio/SpatialAudioEngine.d.ts +10 -0
- package/dist/audio/SpatialAudioEngine.js +80 -0
- package/dist/audio/SpatialAudioEngine.js.map +1 -1
- package/dist/core/VoxelEngine.d.ts +99 -0
- package/dist/core/VoxelEngine.js +181 -0
- package/dist/core/VoxelEngine.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/input/InputManager.d.ts +45 -6
- package/dist/input/InputManager.js +178 -31
- package/dist/input/InputManager.js.map +1 -1
- package/dist/input/index.d.ts +1 -1
- package/dist/input/index.js +1 -1
- package/dist/input/index.js.map +1 -1
- package/dist/materials/Material.d.ts +6 -0
- package/dist/materials/Material.js +12 -0
- package/dist/materials/Material.js.map +1 -1
- package/dist/perf/EntityTickScheduler.d.ts +71 -0
- package/dist/perf/EntityTickScheduler.js +202 -0
- package/dist/perf/EntityTickScheduler.js.map +1 -0
- package/dist/perf/SpatialEntityGrid.d.ts +47 -0
- package/dist/perf/SpatialEntityGrid.js +200 -0
- package/dist/perf/SpatialEntityGrid.js.map +1 -0
- package/dist/perf/index.d.ts +2 -0
- package/dist/perf/index.js +2 -0
- package/dist/perf/index.js.map +1 -1
- package/dist/physics/VoxelPhysicsWorld.d.ts +308 -0
- package/dist/physics/VoxelPhysicsWorld.js +1020 -0
- package/dist/physics/VoxelPhysicsWorld.js.map +1 -0
- package/dist/physics/index.d.ts +1 -0
- package/dist/physics/index.js +1 -0
- package/dist/physics/index.js.map +1 -1
- package/dist/renderers/WebGLRenderer.js +1 -0
- package/dist/renderers/WebGLRenderer.js.map +1 -1
- package/dist/renderers/webgl/WebGLProgram.js +18 -19
- package/dist/renderers/webgl/WebGLProgram.js.map +1 -1
- package/dist/renderers/webgl/WebGLState.d.ts +17 -0
- package/dist/renderers/webgl/WebGLState.js +115 -1
- package/dist/renderers/webgl/WebGLState.js.map +1 -1
- package/dist/voxel/GrassFieldSystem.d.ts +186 -0
- package/dist/voxel/GrassFieldSystem.js +723 -0
- package/dist/voxel/GrassFieldSystem.js.map +1 -0
- package/dist/voxel/SilhouetteLightVolumes.d.ts +13 -2
- package/dist/voxel/SilhouetteLightVolumes.js +384 -78
- package/dist/voxel/SilhouetteLightVolumes.js.map +1 -1
- package/dist/voxel/VoxImporter.d.ts +32 -0
- package/dist/voxel/VoxImporter.js +228 -0
- package/dist/voxel/VoxImporter.js.map +1 -1
- package/dist/voxel/VoxelBrushes.d.ts +110 -0
- package/dist/voxel/VoxelBrushes.js +248 -0
- package/dist/voxel/VoxelBrushes.js.map +1 -0
- package/dist/voxel/VoxelPotatoShader.d.ts +8 -2
- package/dist/voxel/VoxelPotatoShader.js +68 -4
- package/dist/voxel/VoxelPotatoShader.js.map +1 -1
- package/dist/voxel/VoxelSilhouetteShadows.d.ts +69 -11
- package/dist/voxel/VoxelSilhouetteShadows.js +653 -32
- package/dist/voxel/VoxelSilhouetteShadows.js.map +1 -1
- package/dist/voxel/index.d.ts +4 -2
- package/dist/voxel/index.js +4 -2
- package/dist/voxel/index.js.map +1 -1
- package/dist/world/VoxelMobAISystem.d.ts +183 -0
- package/dist/world/VoxelMobAISystem.js +492 -0
- package/dist/world/VoxelMobAISystem.js.map +1 -0
- package/dist/world/index.d.ts +1 -0
- package/dist/world/index.js +1 -0
- package/dist/world/index.js.map +1 -1
- package/llms.txt +301 -0
- package/package.json +2 -1
|
@@ -41,6 +41,7 @@ uniform float uDustIntensity;
|
|
|
41
41
|
uniform float uFogEnabled;
|
|
42
42
|
uniform float uFogNear;
|
|
43
43
|
uniform float uFogFar;
|
|
44
|
+
uniform vec3 uSunDir;
|
|
44
45
|
|
|
45
46
|
varying vec3 vNormal;
|
|
46
47
|
varying vec3 vViewDir;
|
|
@@ -53,36 +54,46 @@ varying float vFogDepth;
|
|
|
53
54
|
void main() {
|
|
54
55
|
vec3 N = normalize(vNormal);
|
|
55
56
|
vec3 V = normalize(vViewDir);
|
|
57
|
+
vec3 S = normalize(uSunDir);
|
|
56
58
|
|
|
57
|
-
//
|
|
59
|
+
// Quartic branchless Fresnel fade so grazing planes dissolve invisibly (zero hard quad lines)
|
|
58
60
|
float viewDot = abs(dot(N, V));
|
|
59
|
-
float
|
|
61
|
+
float fSmooth = viewDot * viewDot * (3.0 - 2.0 * viewDot);
|
|
62
|
+
float fresnelFade = mix(fSmooth * viewDot, fSmooth, clamp(1.0 - uFresnelPower * 0.45, 0.0, 0.45));
|
|
60
63
|
|
|
61
|
-
//
|
|
62
|
-
float
|
|
63
|
-
edgeSoftness =
|
|
64
|
+
// Silky lateral edge falloff reaching 0.0 cleanly at both borders (zero box seams)
|
|
65
|
+
float sEdge = sin(clamp(vUv.x, 0.0, 1.0) * 3.14159265);
|
|
66
|
+
float edgeSoftness = sEdge * sEdge * sqrt(max(0.0001, sEdge));
|
|
64
67
|
|
|
65
|
-
//
|
|
68
|
+
// Gentle misty entry at the skylight/window and long, airy fade toward floor impact
|
|
69
|
+
float endFade = smoothstep(0.0, 0.14, vUv.y) * (1.0 - smoothstep(0.58, 1.0, vUv.y));
|
|
70
|
+
|
|
71
|
+
// Smooth atmospheric attenuation along ray distance so shafts stay localized and airy
|
|
66
72
|
float normDist = clamp(vExtrudeDist / max(0.001, uMaxShaftDistance), 0.0, 1.0);
|
|
67
|
-
float
|
|
73
|
+
float rem = 1.0 - normDist;
|
|
74
|
+
float distAtten = rem * sqrt(max(0.0001, rem));
|
|
75
|
+
|
|
76
|
+
// Subtle forward Mie scattering when gazing toward the sun
|
|
77
|
+
float sunAlign = clamp(dot(-V, S), 0.0, 1.0);
|
|
78
|
+
float mieScatter = 0.82 + 0.34 * sunAlign * sunAlign;
|
|
68
79
|
|
|
69
|
-
//
|
|
70
|
-
float
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
float dustMotes = 1.0 + uDustIntensity * (0.65 * dustPhaseA + 0.35 * dustPhaseB);
|
|
80
|
+
// Delicate beam-aligned filaments and drifting dust motes along -sunDir
|
|
81
|
+
float alongBeam = dot(vWorldPos, -S);
|
|
82
|
+
float filaments = 0.88 + 0.12 * sin(vUv.x * 15.70796 + alongBeam * 0.32);
|
|
83
|
+
float dustPhase = sin(alongBeam * 2.1 - uTime * 0.75 + vUv.x * 6.28318) *
|
|
84
|
+
cos(alongBeam * 4.2 - uTime * 1.1 + (vWorldPos.x - vWorldPos.z) * 1.3);
|
|
85
|
+
float dustMotes = 1.0 + uDustIntensity * 0.38 * dustPhase;
|
|
76
86
|
|
|
77
|
-
float alpha = uShaftIntensity * fresnelFade * edgeSoftness * distAtten * max(0.
|
|
87
|
+
float alpha = uShaftIntensity * fresnelFade * edgeSoftness * endFade * distAtten * mieScatter * filaments * max(0.45, dustMotes);
|
|
78
88
|
|
|
79
89
|
if (uFogEnabled > 0.5) {
|
|
80
90
|
float fogFactor = clamp((vFogDepth - uFogNear) / max(1.0, uFogFar - uFogNear), 0.0, 1.0);
|
|
81
91
|
alpha *= (1.0 - fogFactor);
|
|
82
92
|
}
|
|
83
93
|
|
|
84
|
-
if (alpha < 0.
|
|
85
|
-
|
|
94
|
+
if (alpha < 0.002) discard;
|
|
95
|
+
vec3 airyColor = mix(vColor, vec3(1.0, 0.98, 0.93), 0.22);
|
|
96
|
+
gl_FragColor = vec4(airyColor * (1.0 + 0.08 * max(0.0, dustPhase)), clamp(alpha, 0.0, 0.45));
|
|
86
97
|
}
|
|
87
98
|
`;
|
|
88
99
|
export const GI_BOUNCE_PATCH_VERTEX_SHADER = `
|
|
@@ -123,15 +134,16 @@ void main() {
|
|
|
123
134
|
|
|
124
135
|
float alpha;
|
|
125
136
|
if (vBounceRole < 0.5) {
|
|
126
|
-
// Role 0:
|
|
127
|
-
float borderFade = (1.0 - smoothstep(0.
|
|
128
|
-
(1.0 - smoothstep(0.
|
|
129
|
-
|
|
137
|
+
// Role 0: Delicate surface-hugging sunlit floor/wall tint with soft feathered edge
|
|
138
|
+
float borderFade = (1.0 - smoothstep(0.42, 1.0, abs(centered.x))) *
|
|
139
|
+
(1.0 - smoothstep(0.42, 1.0, abs(centered.y)));
|
|
140
|
+
float softSpot = borderFade * (1.0 - 0.25 * clamp(radial, 0.0, 1.0));
|
|
141
|
+
alpha = uPatchIntensity * softSpot;
|
|
130
142
|
} else {
|
|
131
|
-
// Role 1:
|
|
143
|
+
// Role 1: Whisper-soft radial 1-bounce GI glow fading smoothly to 0 before the quad edge
|
|
132
144
|
float giFalloff = 1.0 - smoothstep(0.0, 1.0, radial);
|
|
133
|
-
float subtlePulse = 1.0 + 0.
|
|
134
|
-
alpha = uBounceIntensity * giFalloff * giFalloff * subtlePulse;
|
|
145
|
+
float subtlePulse = 1.0 + 0.025 * sin(uTime * 1.3);
|
|
146
|
+
alpha = uBounceIntensity * giFalloff * giFalloff * giFalloff * subtlePulse;
|
|
135
147
|
}
|
|
136
148
|
|
|
137
149
|
if (uFogEnabled > 0.5) {
|
|
@@ -139,11 +151,12 @@ void main() {
|
|
|
139
151
|
alpha *= (1.0 - fogFactor);
|
|
140
152
|
}
|
|
141
153
|
|
|
142
|
-
if (alpha < 0.
|
|
143
|
-
gl_FragColor = vec4(vColor, clamp(alpha, 0.0,
|
|
154
|
+
if (alpha < 0.002) discard;
|
|
155
|
+
gl_FragColor = vec4(vColor, clamp(alpha, 0.0, 0.35));
|
|
144
156
|
}
|
|
145
157
|
`;
|
|
146
158
|
export function createGodRayShaftMaterial(options = {}) {
|
|
159
|
+
const initSun = options.sunDirection ?? { x: 0.45, y: 0.82, z: 0.35 };
|
|
147
160
|
return new ShaderMaterial({
|
|
148
161
|
name: 'GodRayShaftMaterial',
|
|
149
162
|
vertexColors: true,
|
|
@@ -154,10 +167,11 @@ export function createGodRayShaftMaterial(options = {}) {
|
|
|
154
167
|
side: DoubleSide,
|
|
155
168
|
uniforms: {
|
|
156
169
|
uTime: { value: 0.0 },
|
|
157
|
-
uShaftIntensity: { value: options.shaftIntensity ?? 0.
|
|
170
|
+
uShaftIntensity: { value: options.shaftIntensity ?? 0.10 },
|
|
158
171
|
uMaxShaftDistance: { value: Math.max(0.01, options.maxShaftDistance ?? 24.0) },
|
|
159
|
-
uFresnelPower: { value: options.fresnelPower ?? 1.
|
|
160
|
-
uDustIntensity: { value: options.dustIntensity ?? 0.
|
|
172
|
+
uFresnelPower: { value: options.fresnelPower ?? 1.6 },
|
|
173
|
+
uDustIntensity: { value: options.dustIntensity ?? 0.22 },
|
|
174
|
+
uSunDir: { value: new Vector3(initSun.x, initSun.y, initSun.z).normalize() },
|
|
161
175
|
uFogEnabled: { value: options.fogEnabled ? 1.0 : 0.0 },
|
|
162
176
|
uFogNear: { value: options.fogNear ?? 60.0 },
|
|
163
177
|
uFogFar: { value: options.fogFar ?? 320.0 },
|
|
@@ -180,8 +194,8 @@ export function createBouncePatchMaterial(options = {}) {
|
|
|
180
194
|
side: DoubleSide,
|
|
181
195
|
uniforms: {
|
|
182
196
|
uTime: { value: 0.0 },
|
|
183
|
-
uPatchIntensity: { value: options.patchIntensity ?? 0.
|
|
184
|
-
uBounceIntensity: { value: options.bounceIntensity ?? 0.
|
|
197
|
+
uPatchIntensity: { value: options.patchIntensity ?? 0.14 },
|
|
198
|
+
uBounceIntensity: { value: options.bounceIntensity ?? 0.055 },
|
|
185
199
|
uFogEnabled: { value: options.fogEnabled ? 1.0 : 0.0 },
|
|
186
200
|
uFogNear: { value: options.fogNear ?? 60.0 },
|
|
187
201
|
uFogFar: { value: options.fogFar ?? 320.0 },
|
|
@@ -225,13 +239,59 @@ function hasExteriorWallJambInDirection(vx, vy, vz, tx, tz, nx, nz, maxSpan, get
|
|
|
225
239
|
const jx = vx + tx * k;
|
|
226
240
|
const jz = vz + tz * k;
|
|
227
241
|
if (isOpaque(getVoxel(jx, vy, jz))) {
|
|
228
|
-
// Wall jamb must have open exterior air on +N side
|
|
229
|
-
|
|
230
|
-
|
|
242
|
+
// Wall jamb must have open exterior air on +N side, hollow interior air on -N side,
|
|
243
|
+
// AND actually belong to a wall (either continuing along +T or turning inward along -N),
|
|
244
|
+
// preventing open 4-pillar gazebos/pergolas from emitting huge wall-to-wall doorway beams.
|
|
245
|
+
const hasOpenFront = !isOpaque(getVoxel(jx + nx, vy, jz + nz));
|
|
246
|
+
const hasWallContinuation = isOpaque(getVoxel(jx + tx, vy, jz + tz));
|
|
247
|
+
const hasCornerTurnWall = isOpaque(getVoxel(jx - nx, vy, jz - nz));
|
|
248
|
+
return hasOpenFront && (hasWallContinuation || hasCornerTurnWall);
|
|
231
249
|
}
|
|
232
250
|
}
|
|
233
251
|
return false;
|
|
234
252
|
}
|
|
253
|
+
const _sunCheckOrigin = new Vector3();
|
|
254
|
+
const _sunCheckDir = new Vector3();
|
|
255
|
+
/**
|
|
256
|
+
* Verifies that an opening cell actually receives direct incoming sunlight along `+sunDirection`
|
|
257
|
+
* (stepping past stacked translucent skylight layers to the exterior sun-entry face).
|
|
258
|
+
*/
|
|
259
|
+
function isOpeningSunlit(vx, vy, vz, nx, ny, nz, sx, sy, sz, maxCheckDist, getVoxel, isOpaque, isTranslucent) {
|
|
260
|
+
let ox = vx + 0.5;
|
|
261
|
+
let oy = vy + 0.5;
|
|
262
|
+
let oz = vz + 0.5;
|
|
263
|
+
if (ny > 0.5) {
|
|
264
|
+
let topY = vy;
|
|
265
|
+
for (let step = 0; step < 6; step++) {
|
|
266
|
+
if (isTranslucent(getVoxel(vx, topY + 1, vz))) {
|
|
267
|
+
topY++;
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
oy = topY + 1.02;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
let extX = vx;
|
|
277
|
+
let extZ = vz;
|
|
278
|
+
for (let step = 0; step < 4; step++) {
|
|
279
|
+
if (isTranslucent(getVoxel(extX + nx, vy, extZ + nz))) {
|
|
280
|
+
extX += nx;
|
|
281
|
+
extZ += nz;
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
ox = extX + 0.5 + nx * 0.52;
|
|
288
|
+
oz = extZ + 0.5 + nz * 0.52;
|
|
289
|
+
}
|
|
290
|
+
_sunCheckOrigin.set(ox, oy, oz);
|
|
291
|
+
_sunCheckDir.set(sx, sy, sz);
|
|
292
|
+
const hit = raycastVoxels(_sunCheckOrigin, _sunCheckDir, maxCheckDist, getVoxel, isOpaque);
|
|
293
|
+
return hit === null;
|
|
294
|
+
}
|
|
235
295
|
/**
|
|
236
296
|
* Step 1: Detects enclosed/semi-enclosed roof breaches, doorways/windows, and translucent/stained-glass
|
|
237
297
|
* openings facing `sunDirection`, and extracts their collinear-merged perimeter silhouette edges.
|
|
@@ -257,6 +317,7 @@ export function detectOpeningSilhouettes(options) {
|
|
|
257
317
|
const maxX = originX + sizeX;
|
|
258
318
|
const maxY = originY + sizeY;
|
|
259
319
|
const maxZ = originZ + sizeZ;
|
|
320
|
+
const sunCheckDist = Math.max(8, maxSpan * 2);
|
|
260
321
|
for (let vy = originY; vy < maxY; vy++) {
|
|
261
322
|
for (let vz = originZ; vz < maxZ; vz++) {
|
|
262
323
|
for (let vx = originX; vx < maxX; vx++) {
|
|
@@ -266,10 +327,15 @@ export function detectOpeningSilhouettes(options) {
|
|
|
266
327
|
const translucent = isTranslucent(id);
|
|
267
328
|
if (translucent) {
|
|
268
329
|
const tint = new Color(getTranslucentColor(id, vx, vy, vz));
|
|
269
|
-
// Check top face (+Y) if sun is above horizon
|
|
330
|
+
// Check top/bottom skylight face (+Y) if sun is above horizon:
|
|
331
|
+
// Must have sky/translucent above (!isOpaque), open interior air below, and incoming sun access
|
|
332
|
+
const aboveId = getVoxel(vx, vy + 1, vz);
|
|
333
|
+
const belowId = getVoxel(vx, vy - 1, vz);
|
|
270
334
|
if (sy > 0.05 &&
|
|
271
|
-
!isOpaque(
|
|
272
|
-
!isOpaque(
|
|
335
|
+
!isOpaque(aboveId) &&
|
|
336
|
+
!isOpaque(belowId) &&
|
|
337
|
+
!isTranslucent(belowId) &&
|
|
338
|
+
isOpeningSunlit(vx, vy, vz, 0, 1, 0, sx, sy, sz, sunCheckDist, getVoxel, isOpaque, isTranslucent)) {
|
|
273
339
|
const cell = {
|
|
274
340
|
vx,
|
|
275
341
|
vy,
|
|
@@ -283,7 +349,21 @@ export function detectOpeningSilhouettes(options) {
|
|
|
283
349
|
cellMap.set(`0,1,0:${vx},${vy},${vz}`, cell);
|
|
284
350
|
continue;
|
|
285
351
|
}
|
|
286
|
-
//
|
|
352
|
+
// If stacked above another translucent skylight voxel that exits into open air below,
|
|
353
|
+
// let only the bottom-most skylight layer emit the aperture.
|
|
354
|
+
// Vertical stained-glass windows resting on an opaque sill are NOT skipped!
|
|
355
|
+
if (isTranslucent(belowId)) {
|
|
356
|
+
let scanY = vy - 1;
|
|
357
|
+
while (scanY > originY - 4 && isTranslucent(getVoxel(vx, scanY, vz))) {
|
|
358
|
+
scanY--;
|
|
359
|
+
}
|
|
360
|
+
if (!isOpaque(getVoxel(vx, scanY, vz))) {
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
// Check sun-facing vertical wall faces (±X, ±Z):
|
|
365
|
+
// Must have non-opaque on the sunward side (+N), open interior air on the inward side (-N),
|
|
366
|
+
// framing above, and direct incoming sunlight along +sunDirection
|
|
287
367
|
const wallDirs = [
|
|
288
368
|
[1, 0, 0],
|
|
289
369
|
[-1, 0, 0],
|
|
@@ -294,8 +374,13 @@ export function detectOpeningSilhouettes(options) {
|
|
|
294
374
|
const [nx, ny, nz] = wallDirs[d];
|
|
295
375
|
if (nx * sx + nz * sz <= 0.05)
|
|
296
376
|
continue;
|
|
297
|
-
|
|
298
|
-
|
|
377
|
+
const outId = getVoxel(vx + nx, vy, vz + nz);
|
|
378
|
+
const inId = getVoxel(vx - nx, vy, vz - nz);
|
|
379
|
+
if (!isOpaque(outId) &&
|
|
380
|
+
!isOpaque(inId) &&
|
|
381
|
+
!isTranslucent(inId) &&
|
|
382
|
+
hasOpaqueInDirection(vx, vy, vz, 0, 1, 0, maxSpan, getVoxel, isOpaque) &&
|
|
383
|
+
isOpeningSunlit(vx, vy, vz, nx, ny, nz, sx, sy, sz, sunCheckDist, getVoxel, isOpaque, isTranslucent)) {
|
|
299
384
|
const cell = {
|
|
300
385
|
vx,
|
|
301
386
|
vy,
|
|
@@ -314,7 +399,7 @@ export function detectOpeningSilhouettes(options) {
|
|
|
314
399
|
}
|
|
315
400
|
// Open air voxel: check if it is a roof breach (hole in ceiling/roof) or wall doorway/window
|
|
316
401
|
// 1. Horizontal roof breach check (when sun is above horizon):
|
|
317
|
-
// Must be open to sky above
|
|
402
|
+
// Must be open to sky above, have interior air below, and receive direct sunlight
|
|
318
403
|
if (sy > 0.1 &&
|
|
319
404
|
!isOpaque(getVoxel(vx, vy - 1, vz)) &&
|
|
320
405
|
!hasOpaqueInDirection(vx, vy, vz, 0, 1, 0, maxSpan, getVoxel, isOpaque)) {
|
|
@@ -322,7 +407,8 @@ export function detectOpeningSilhouettes(options) {
|
|
|
322
407
|
const west = isRoofRimInDirection(vx, vy, vz, -1, 0, maxSpan, getVoxel, isOpaque);
|
|
323
408
|
const south = isRoofRimInDirection(vx, vy, vz, 0, 1, maxSpan, getVoxel, isOpaque);
|
|
324
409
|
const north = isRoofRimInDirection(vx, vy, vz, 0, -1, maxSpan, getVoxel, isOpaque);
|
|
325
|
-
if ((east && west) || (south && north))
|
|
410
|
+
if (((east && west) || (south && north)) &&
|
|
411
|
+
isOpeningSunlit(vx, vy, vz, 0, 1, 0, sx, sy, sz, sunCheckDist, getVoxel, isOpaque, isTranslucent)) {
|
|
326
412
|
const cell = {
|
|
327
413
|
vx,
|
|
328
414
|
vy,
|
|
@@ -373,6 +459,9 @@ export function detectOpeningSilhouettes(options) {
|
|
|
373
459
|
const hasInteriorCeiling = hasOpaqueInDirection(vx - nx, vy, vz - nz, 0, 1, 0, maxSpan, getVoxel, isOpaque);
|
|
374
460
|
if (!hasInteriorCeiling)
|
|
375
461
|
continue;
|
|
462
|
+
if (!isOpeningSunlit(vx, vy, vz, nx, 0, nz, sx, sy, sz, sunCheckDist, getVoxel, isOpaque, isTranslucent)) {
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
376
465
|
const cell = {
|
|
377
466
|
vx,
|
|
378
467
|
vy,
|
|
@@ -776,14 +865,15 @@ export function projectOpeningLightVolumes(options) {
|
|
|
776
865
|
const offX = options.worldOffset?.x ?? 0;
|
|
777
866
|
const offY = options.worldOffset?.y ?? 0;
|
|
778
867
|
const offZ = options.worldOffset?.z ?? 0;
|
|
779
|
-
const bounceElev = (options.bounceCardElevationVoxels ?? 0.
|
|
780
|
-
const bounceRadMult = Math.max(1.0, options.bounceCardRadiusMultiplier ?? 1.
|
|
868
|
+
const bounceElev = (options.bounceCardElevationVoxels ?? 0.028) * scale;
|
|
869
|
+
const bounceRadMult = Math.max(1.0, options.bounceCardRadiusMultiplier ?? 1.65);
|
|
781
870
|
const sLen = Math.hypot(options.sunDirection.x, options.sunDirection.y, options.sunDirection.z);
|
|
782
871
|
if (sLen < 1e-6) {
|
|
783
|
-
return { shaftQuads: [], lightPatches: [], bounceCards: [] };
|
|
872
|
+
return { shaftQuads: [], coreQuads: [], lightPatches: [], bounceCards: [] };
|
|
784
873
|
}
|
|
785
874
|
_pNegSun.set(-options.sunDirection.x / sLen, -options.sunDirection.y / sLen, -options.sunDirection.z / sLen);
|
|
786
875
|
const shaftQuads = [];
|
|
876
|
+
const coreQuads = [];
|
|
787
877
|
const lightPatches = [];
|
|
788
878
|
const bounceCards = [];
|
|
789
879
|
// 1. Project merged perimeter silhouette edges along -sunDirection to extrude volumetric sunbeam side walls
|
|
@@ -804,7 +894,7 @@ export function projectOpeningLightVolumes(options) {
|
|
|
804
894
|
continue;
|
|
805
895
|
const d0Grid = hit0 ? hit0.distance : hit1.distance;
|
|
806
896
|
const d1Grid = hit1 ? hit1.distance : hit0.distance;
|
|
807
|
-
if (d0Grid <
|
|
897
|
+
if (d0Grid < 0.75 && d1Grid < 0.75)
|
|
808
898
|
continue;
|
|
809
899
|
let gx0 = edge.start.x + _pNegSun.x * d0Grid;
|
|
810
900
|
let gy0 = edge.start.y + _pNegSun.y * d0Grid;
|
|
@@ -840,25 +930,44 @@ export function projectOpeningLightVolumes(options) {
|
|
|
840
930
|
else if (hit1.normalZ < 0)
|
|
841
931
|
gz1 = hit1.wz;
|
|
842
932
|
}
|
|
933
|
+
// For horizontal skylights/roof breaches, keep both bottom corners of the shaft wall on the same
|
|
934
|
+
// primary interior receiving plane so a grazing ray doesn't twist a shaft wall down a hillside
|
|
935
|
+
let finalD0 = d0Grid;
|
|
936
|
+
let finalD1 = d1Grid;
|
|
937
|
+
if (edge.openingNormal.y > 0.5 && _pNegSun.y < -0.05 && Math.abs(gy0 - gy1) > 0.25) {
|
|
938
|
+
const targetGy = Math.max(gy0, gy1);
|
|
939
|
+
if (edge.start.y > targetGy + 0.5) {
|
|
940
|
+
const dPlane = (targetGy - edge.start.y) / _pNegSun.y;
|
|
941
|
+
gy0 = targetGy;
|
|
942
|
+
gy1 = targetGy;
|
|
943
|
+
gx0 = edge.start.x + _pNegSun.x * dPlane;
|
|
944
|
+
gz0 = edge.start.z + _pNegSun.z * dPlane;
|
|
945
|
+
gx1 = edge.end.x + _pNegSun.x * dPlane;
|
|
946
|
+
gz1 = edge.end.z + _pNegSun.z * dPlane;
|
|
947
|
+
finalD0 = dPlane;
|
|
948
|
+
finalD1 = dPlane;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
843
951
|
shaftQuads.push({
|
|
844
952
|
openingStart: new Vector3(offX + edge.start.x * scale, offY + edge.start.y * scale, offZ + edge.start.z * scale),
|
|
845
953
|
openingEnd: new Vector3(offX + edge.end.x * scale, offY + edge.end.y * scale, offZ + edge.end.z * scale),
|
|
846
954
|
floorStart: new Vector3(offX + gx0 * scale, offY + gy0 * scale, offZ + gz0 * scale),
|
|
847
955
|
floorEnd: new Vector3(offX + gx1 * scale, offY + gy1 * scale, offZ + gz1 * scale),
|
|
848
|
-
extrudeDistStart:
|
|
849
|
-
extrudeDistEnd:
|
|
956
|
+
extrudeDistStart: finalD0 * scale,
|
|
957
|
+
extrudeDistEnd: finalD1 * scale,
|
|
850
958
|
color: edge.color.clone(),
|
|
851
959
|
kind: edge.kind,
|
|
852
960
|
});
|
|
853
961
|
}
|
|
854
|
-
// 2. Group contiguous coplanar opening cells of the same plane & color into merged
|
|
855
|
-
//
|
|
962
|
+
// 2. Group contiguous coplanar opening cells of the same plane & color into merged apertures,
|
|
963
|
+
// emitting crossed inner volumetric core planes + surface-clamped light patches + flush GI glow
|
|
856
964
|
const visited = new Set();
|
|
857
965
|
for (let i = 0; i < cells.length; i++) {
|
|
858
966
|
if (visited.has(i))
|
|
859
967
|
continue;
|
|
860
968
|
const seed = cells[i];
|
|
861
969
|
visited.add(i);
|
|
970
|
+
const clusterCells = [seed];
|
|
862
971
|
let minVx = seed.vx;
|
|
863
972
|
let maxVx = seed.vx + 1;
|
|
864
973
|
let minVy = seed.vy;
|
|
@@ -887,6 +996,7 @@ export function projectOpeningLightVolumes(options) {
|
|
|
887
996
|
cand.vz >= minVz - 1 &&
|
|
888
997
|
cand.vz <= maxVz) {
|
|
889
998
|
visited.add(j);
|
|
999
|
+
clusterCells.push(cand);
|
|
890
1000
|
minVx = Math.min(minVx, cand.vx);
|
|
891
1001
|
maxVx = Math.max(maxVx, cand.vx + 1);
|
|
892
1002
|
minVy = Math.min(minVy, cand.vy);
|
|
@@ -897,14 +1007,56 @@ export function projectOpeningLightVolumes(options) {
|
|
|
897
1007
|
}
|
|
898
1008
|
}
|
|
899
1009
|
}
|
|
900
|
-
// Cast a ray from the interior aperture center along -sunDirection to find
|
|
1010
|
+
// Cast a ray from the interior aperture center along -sunDirection to find primary floor/wall hit
|
|
901
1011
|
const cx = (minVx + maxVx) * 0.5 - seed.normal.x * 0.501;
|
|
902
1012
|
const cy = (minVy + maxVy) * 0.5 - seed.normal.y * 0.501;
|
|
903
1013
|
const cz = (minVz + maxVz) * 0.5 - seed.normal.z * 0.501;
|
|
904
1014
|
_pCenterOrigin.set(cx, cy, cz);
|
|
905
1015
|
const centerHit = raycastVoxels(_pCenterOrigin, _pNegSun, maxRayDist, getVoxel, isOpaque);
|
|
906
|
-
if (!centerHit || centerHit.distance <
|
|
1016
|
+
if (!centerHit || centerHit.distance < 0.75)
|
|
907
1017
|
continue;
|
|
1018
|
+
// Emit 2 crossed soft inner volumetric core quads along the aperture diagonals (zero extra draw calls!)
|
|
1019
|
+
const coreColor = seed.color.clone().multiplyScalar(0.46);
|
|
1020
|
+
const diagPairs = [];
|
|
1021
|
+
if (seed.normal.y > 0.5) {
|
|
1022
|
+
const py = minVy;
|
|
1023
|
+
const inX = (maxVx - minVx) * 0.14;
|
|
1024
|
+
const inZ = (maxVz - minVz) * 0.14;
|
|
1025
|
+
diagPairs.push([[minVx + inX, py, minVz + inZ], [maxVx - inX, py, maxVz - inZ]], [[maxVx - inX, py, minVz + inZ], [minVx + inX, py, maxVz - inZ]]);
|
|
1026
|
+
}
|
|
1027
|
+
else if (Math.abs(seed.normal.x) > 0.5) {
|
|
1028
|
+
const px = seed.normal.x > 0 ? minVx : maxVx;
|
|
1029
|
+
const inY = (maxVy - minVy) * 0.14;
|
|
1030
|
+
const inZ = (maxVz - minVz) * 0.14;
|
|
1031
|
+
diagPairs.push([[px, minVy + inY, minVz + inZ], [px, maxVy - inY, maxVz - inZ]], [[px, maxVy - inY, minVz + inZ], [px, minVy + inY, maxVz - inZ]]);
|
|
1032
|
+
}
|
|
1033
|
+
else {
|
|
1034
|
+
const pz = seed.normal.z > 0 ? minVz : maxVz;
|
|
1035
|
+
const inX = (maxVx - minVx) * 0.14;
|
|
1036
|
+
const inY = (maxVy - minVy) * 0.14;
|
|
1037
|
+
diagPairs.push([[minVx + inX, minVy + inY, pz], [maxVx - inX, maxVy - inY, pz]], [[maxVx - inX, minVy + inY, pz], [minVx + inX, maxVy - inY, pz]]);
|
|
1038
|
+
}
|
|
1039
|
+
for (let dp = 0; dp < diagPairs.length; dp++) {
|
|
1040
|
+
const [a, b] = diagPairs[dp];
|
|
1041
|
+
_pOrigin0.set(a[0] - seed.normal.x * 1e-3, a[1] - seed.normal.y * 1e-3, a[2] - seed.normal.z * 1e-3);
|
|
1042
|
+
_pOrigin1.set(b[0] - seed.normal.x * 1e-3, b[1] - seed.normal.y * 1e-3, b[2] - seed.normal.z * 1e-3);
|
|
1043
|
+
const hA = raycastVoxels(_pOrigin0, _pNegSun, maxRayDist, getVoxel, isOpaque);
|
|
1044
|
+
const hB = raycastVoxels(_pOrigin1, _pNegSun, maxRayDist, getVoxel, isOpaque);
|
|
1045
|
+
const dA = hA ? hA.distance : centerHit.distance;
|
|
1046
|
+
const dB = hB ? hB.distance : centerHit.distance;
|
|
1047
|
+
if (dA < 0.75 && dB < 0.75)
|
|
1048
|
+
continue;
|
|
1049
|
+
coreQuads.push({
|
|
1050
|
+
openingStart: new Vector3(offX + a[0] * scale, offY + a[1] * scale, offZ + a[2] * scale),
|
|
1051
|
+
openingEnd: new Vector3(offX + b[0] * scale, offY + b[1] * scale, offZ + b[2] * scale),
|
|
1052
|
+
floorStart: new Vector3(offX + (a[0] + _pNegSun.x * dA) * scale, offY + (a[1] + _pNegSun.y * dA) * scale, offZ + (a[2] + _pNegSun.z * dA) * scale),
|
|
1053
|
+
floorEnd: new Vector3(offX + (b[0] + _pNegSun.x * dB) * scale, offY + (b[1] + _pNegSun.y * dB) * scale, offZ + (b[2] + _pNegSun.z * dB) * scale),
|
|
1054
|
+
extrudeDistStart: dA * scale,
|
|
1055
|
+
extrudeDistEnd: dB * scale,
|
|
1056
|
+
color: coreColor.clone(),
|
|
1057
|
+
kind: seed.kind,
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
908
1060
|
const hitDist = centerHit.distance;
|
|
909
1061
|
const surfNx = centerHit.normalX || 0;
|
|
910
1062
|
const surfNy = centerHit.normalY || (centerHit.normalX === 0 && centerHit.normalZ === 0 ? 1 : 0);
|
|
@@ -929,13 +1081,12 @@ export function projectOpeningLightVolumes(options) {
|
|
|
929
1081
|
const halfSpanZ = Math.max(0.5, (maxVz - minVz) * 0.5) * scale;
|
|
930
1082
|
const halfSpanY = Math.max(0.5, (maxVy - minVy) * 0.5) * scale;
|
|
931
1083
|
const worldCenter = new Vector3(offX + hitCenterX * scale, offY + hitCenterY * scale, offZ + hitCenterZ * scale);
|
|
932
|
-
const decalBias = 0.
|
|
1084
|
+
const decalBias = 0.014 * scale;
|
|
933
1085
|
const px = worldCenter.x + surfNx * decalBias;
|
|
934
1086
|
const py = worldCenter.y + surfNy * decalBias;
|
|
935
1087
|
const pz = worldCenter.z + surfNz * decalBias;
|
|
936
1088
|
let patchCorners;
|
|
937
1089
|
if (Math.abs(surfNy) >= 0.5) {
|
|
938
|
-
// Horizontal floor/ceiling light patch
|
|
939
1090
|
patchCorners = [
|
|
940
1091
|
new Vector3(px - halfSpanX, py, pz - halfSpanZ),
|
|
941
1092
|
new Vector3(px + halfSpanX, py, pz - halfSpanZ),
|
|
@@ -944,7 +1095,6 @@ export function projectOpeningLightVolumes(options) {
|
|
|
944
1095
|
];
|
|
945
1096
|
}
|
|
946
1097
|
else if (Math.abs(surfNx) >= 0.5) {
|
|
947
|
-
// Vertical YZ wall light patch
|
|
948
1098
|
patchCorners = [
|
|
949
1099
|
new Vector3(px, py - halfSpanY, pz - halfSpanZ),
|
|
950
1100
|
new Vector3(px, py + halfSpanY, pz - halfSpanZ),
|
|
@@ -953,7 +1103,6 @@ export function projectOpeningLightVolumes(options) {
|
|
|
953
1103
|
];
|
|
954
1104
|
}
|
|
955
1105
|
else {
|
|
956
|
-
// Vertical XY wall light patch
|
|
957
1106
|
patchCorners = [
|
|
958
1107
|
new Vector3(px - halfSpanX, py - halfSpanY, pz),
|
|
959
1108
|
new Vector3(px + halfSpanX, py - halfSpanY, pz),
|
|
@@ -961,6 +1110,133 @@ export function projectOpeningLightVolumes(options) {
|
|
|
961
1110
|
new Vector3(px - halfSpanX, py + halfSpanY, pz),
|
|
962
1111
|
];
|
|
963
1112
|
}
|
|
1113
|
+
// Build deduplicated, non-overlapping per-voxel-face surface-clamped light patch quads
|
|
1114
|
+
// mapped into cluster-normalized UVs so light wraps cleanly onto floors/steps/walls with zero double-bright seams
|
|
1115
|
+
const surfaceQuads = [];
|
|
1116
|
+
const seenHitFaces = new Set();
|
|
1117
|
+
const rawCells = [];
|
|
1118
|
+
for (let c = 0; c < clusterCells.length; c++) {
|
|
1119
|
+
const cell = clusterCells[c];
|
|
1120
|
+
const origX = cell.vx + 0.5 - cell.normal.x * 0.501;
|
|
1121
|
+
const origY = cell.vy + 0.5 - cell.normal.y * 0.501;
|
|
1122
|
+
const origZ = cell.vz + 0.5 - cell.normal.z * 0.501;
|
|
1123
|
+
_pOrigin0.set(origX, origY, origZ);
|
|
1124
|
+
const cellHit = raycastVoxels(_pOrigin0, _pNegSun, maxRayDist, getVoxel, isOpaque);
|
|
1125
|
+
if (!cellHit || cellHit.distance < 0.75)
|
|
1126
|
+
continue;
|
|
1127
|
+
const cNx = cellHit.normalX || 0;
|
|
1128
|
+
const cNy = cellHit.normalY || (cellHit.normalX === 0 && cellHit.normalZ === 0 ? 1 : 0);
|
|
1129
|
+
const cNz = cellHit.normalZ || 0;
|
|
1130
|
+
const wx = cellHit.wx;
|
|
1131
|
+
const wy = cellHit.wy;
|
|
1132
|
+
const wz = cellHit.wz;
|
|
1133
|
+
const faceKey = `${wx},${wy},${wz}:${cNx},${cNy},${cNz}`;
|
|
1134
|
+
if (seenHitFaces.has(faceKey))
|
|
1135
|
+
continue;
|
|
1136
|
+
seenHitFaces.add(faceKey);
|
|
1137
|
+
let hx = origX + _pNegSun.x * cellHit.distance;
|
|
1138
|
+
let hy = origY + _pNegSun.y * cellHit.distance;
|
|
1139
|
+
let hz = origZ + _pNegSun.z * cellHit.distance;
|
|
1140
|
+
if (cNy > 0)
|
|
1141
|
+
hy = wy + 1;
|
|
1142
|
+
else if (cNy < 0)
|
|
1143
|
+
hy = wy;
|
|
1144
|
+
else if (cNx > 0)
|
|
1145
|
+
hx = wx + 1;
|
|
1146
|
+
else if (cNx < 0)
|
|
1147
|
+
hx = wx;
|
|
1148
|
+
else if (cNz > 0)
|
|
1149
|
+
hz = wz + 1;
|
|
1150
|
+
else if (cNz < 0)
|
|
1151
|
+
hz = wz;
|
|
1152
|
+
// Clamp strictly inside this exposed voxel face (zero additive overlap with neighbors, zero cliff overhang)
|
|
1153
|
+
if (Math.abs(cNy) >= 0.5) {
|
|
1154
|
+
const ySurf = offY + hy * scale + cNy * decalBias;
|
|
1155
|
+
rawCells.push({
|
|
1156
|
+
wx, wy, wz, cNx, cNy, cNz,
|
|
1157
|
+
a0: wx + 0.005, a1: wx + 0.995,
|
|
1158
|
+
b0: wz + 0.005, b1: wz + 0.995,
|
|
1159
|
+
surfCoord: ySurf,
|
|
1160
|
+
planeAxis: 'y',
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
else if (Math.abs(cNx) >= 0.5) {
|
|
1164
|
+
const xSurf = offX + hx * scale + cNx * decalBias;
|
|
1165
|
+
rawCells.push({
|
|
1166
|
+
wx, wy, wz, cNx, cNy, cNz,
|
|
1167
|
+
a0: wy + 0.005, a1: wy + 0.995,
|
|
1168
|
+
b0: wz + 0.005, b1: wz + 0.995,
|
|
1169
|
+
surfCoord: xSurf,
|
|
1170
|
+
planeAxis: 'x',
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
else {
|
|
1174
|
+
const zSurf = offZ + hz * scale + cNz * decalBias;
|
|
1175
|
+
rawCells.push({
|
|
1176
|
+
wx, wy, wz, cNx, cNy, cNz,
|
|
1177
|
+
a0: wx + 0.005, a1: wx + 0.995,
|
|
1178
|
+
b0: wy + 0.005, b1: wy + 0.995,
|
|
1179
|
+
surfCoord: zSurf,
|
|
1180
|
+
planeAxis: 'z',
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
if (rawCells.length > 0) {
|
|
1185
|
+
let minA = Infinity;
|
|
1186
|
+
let maxA = -Infinity;
|
|
1187
|
+
let minB = Infinity;
|
|
1188
|
+
let maxB = -Infinity;
|
|
1189
|
+
for (let i = 0; i < rawCells.length; i++) {
|
|
1190
|
+
const rc = rawCells[i];
|
|
1191
|
+
if (rc.a0 < minA)
|
|
1192
|
+
minA = rc.a0;
|
|
1193
|
+
if (rc.a1 > maxA)
|
|
1194
|
+
maxA = rc.a1;
|
|
1195
|
+
if (rc.b0 < minB)
|
|
1196
|
+
minB = rc.b0;
|
|
1197
|
+
if (rc.b1 > maxB)
|
|
1198
|
+
maxB = rc.b1;
|
|
1199
|
+
}
|
|
1200
|
+
const spanA = Math.max(0.01, maxA - minA);
|
|
1201
|
+
const spanB = Math.max(0.01, maxB - minB);
|
|
1202
|
+
for (let i = 0; i < rawCells.length; i++) {
|
|
1203
|
+
const rc = rawCells[i];
|
|
1204
|
+
const u0 = (rc.a0 - minA) / spanA;
|
|
1205
|
+
const u1 = (rc.a1 - minA) / spanA;
|
|
1206
|
+
const v0 = (rc.b0 - minB) / spanB;
|
|
1207
|
+
const v1 = (rc.b1 - minB) / spanB;
|
|
1208
|
+
let qCorners;
|
|
1209
|
+
if (rc.planeAxis === 'y') {
|
|
1210
|
+
qCorners = [
|
|
1211
|
+
new Vector3(offX + rc.a0 * scale, rc.surfCoord, offZ + rc.b0 * scale),
|
|
1212
|
+
new Vector3(offX + rc.a1 * scale, rc.surfCoord, offZ + rc.b0 * scale),
|
|
1213
|
+
new Vector3(offX + rc.a1 * scale, rc.surfCoord, offZ + rc.b1 * scale),
|
|
1214
|
+
new Vector3(offX + rc.a0 * scale, rc.surfCoord, offZ + rc.b1 * scale),
|
|
1215
|
+
];
|
|
1216
|
+
}
|
|
1217
|
+
else if (rc.planeAxis === 'x') {
|
|
1218
|
+
qCorners = [
|
|
1219
|
+
new Vector3(rc.surfCoord, offY + rc.a0 * scale, offZ + rc.b0 * scale),
|
|
1220
|
+
new Vector3(rc.surfCoord, offY + rc.a1 * scale, offZ + rc.b0 * scale),
|
|
1221
|
+
new Vector3(rc.surfCoord, offY + rc.a1 * scale, offZ + rc.b1 * scale),
|
|
1222
|
+
new Vector3(rc.surfCoord, offY + rc.a0 * scale, offZ + rc.b1 * scale),
|
|
1223
|
+
];
|
|
1224
|
+
}
|
|
1225
|
+
else {
|
|
1226
|
+
qCorners = [
|
|
1227
|
+
new Vector3(offX + rc.a0 * scale, offY + rc.b0 * scale, rc.surfCoord),
|
|
1228
|
+
new Vector3(offX + rc.a1 * scale, offY + rc.b0 * scale, rc.surfCoord),
|
|
1229
|
+
new Vector3(offX + rc.a1 * scale, offY + rc.b1 * scale, rc.surfCoord),
|
|
1230
|
+
new Vector3(offX + rc.a0 * scale, offY + rc.b1 * scale, rc.surfCoord),
|
|
1231
|
+
];
|
|
1232
|
+
}
|
|
1233
|
+
surfaceQuads.push({
|
|
1234
|
+
corners: qCorners,
|
|
1235
|
+
surfaceNormal: new Vector3(rc.cNx, rc.cNy, rc.cNz),
|
|
1236
|
+
uvRect: [u0, v0, u1, v1],
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
964
1240
|
lightPatches.push({
|
|
965
1241
|
corners: patchCorners,
|
|
966
1242
|
center: worldCenter.clone(),
|
|
@@ -968,8 +1244,9 @@ export function projectOpeningLightVolumes(options) {
|
|
|
968
1244
|
color: seed.color.clone(),
|
|
969
1245
|
travelDistance: hitDist * scale,
|
|
970
1246
|
kind: seed.kind,
|
|
1247
|
+
surfaceQuads: surfaceQuads.length > 0 ? surfaceQuads : undefined,
|
|
971
1248
|
});
|
|
972
|
-
// 3. Spawn
|
|
1249
|
+
// 3. Spawn a flush, surface-hugging 1-bounce fake GI halo on horizontal floors
|
|
973
1250
|
const giRadius = Math.max(halfSpanX, halfSpanZ) * bounceRadMult;
|
|
974
1251
|
const giY = worldCenter.y + bounceElev;
|
|
975
1252
|
const giCenter = new Vector3(worldCenter.x, giY, worldCenter.z);
|
|
@@ -987,7 +1264,7 @@ export function projectOpeningLightVolumes(options) {
|
|
|
987
1264
|
radius: giRadius,
|
|
988
1265
|
});
|
|
989
1266
|
}
|
|
990
|
-
return { shaftQuads, lightPatches, bounceCards };
|
|
1267
|
+
return { shaftQuads, coreQuads, lightPatches, bounceCards };
|
|
991
1268
|
}
|
|
992
1269
|
/**
|
|
993
1270
|
* SilhouetteLightVolumes — Zero-raymarch volumetric sunbeam (`GodRayShaftMesh`),
|
|
@@ -1044,6 +1321,7 @@ export class SilhouetteLightVolumes {
|
|
|
1044
1321
|
this.maxSlicesPerUpdate = Math.max(1, Math.floor(options.maxSlicesPerUpdate ?? 64));
|
|
1045
1322
|
this.shaftMaterial = createGodRayShaftMaterial({
|
|
1046
1323
|
...options.shaftMaterialOptions,
|
|
1324
|
+
sunDirection: options.shaftMaterialOptions?.sunDirection ?? this.sunDirection,
|
|
1047
1325
|
maxShaftDistance: options.shaftMaterialOptions?.maxShaftDistance ??
|
|
1048
1326
|
this.maxRayDistance * this.voxelScale,
|
|
1049
1327
|
});
|
|
@@ -1065,10 +1343,12 @@ export class SilhouetteLightVolumes {
|
|
|
1065
1343
|
this.bounceGeometry.setAttribute('bounceRole', new BufferAttribute(new Float32Array(0), 1));
|
|
1066
1344
|
this.bounceGeometry.setIndex(new BufferAttribute(new Uint16Array(0), 1));
|
|
1067
1345
|
this.shaftMesh = new GodRayShaftMesh(this.shaftGeometry, this.shaftMaterial);
|
|
1346
|
+
this.shaftMesh.renderOrder = 50;
|
|
1068
1347
|
this.godRayShaftMesh = this.shaftMesh;
|
|
1069
1348
|
this.bouncePatchMesh = new Mesh(this.bounceGeometry, this.bounceMaterial);
|
|
1070
1349
|
this.bouncePatchMesh.name = 'SilhouetteBouncePatchMesh';
|
|
1071
1350
|
this.bouncePatchMesh.frustumCulled = false;
|
|
1351
|
+
this.bouncePatchMesh.renderOrder = 49;
|
|
1072
1352
|
this.group = new Group();
|
|
1073
1353
|
this.group.name = 'SilhouetteLightVolumes';
|
|
1074
1354
|
this.group.add(this.shaftMesh);
|
|
@@ -1127,11 +1407,11 @@ export class SilhouetteLightVolumes {
|
|
|
1127
1407
|
this.maxRayDistance = preset.maxRayDistance;
|
|
1128
1408
|
this.sunAngleThreshold = preset.sunAngleThreshold;
|
|
1129
1409
|
const intensityScale = preset.id === 'high' ? 1.18 : 1.0;
|
|
1130
|
-
this.shaftMaterial.uniforms.uShaftIntensity.value = 0.
|
|
1410
|
+
this.shaftMaterial.uniforms.uShaftIntensity.value = 0.10 * intensityScale;
|
|
1131
1411
|
this.shaftMaterial.uniforms.uMaxShaftDistance.value = Math.max(0.01, this.maxRayDistance * this.voxelScale);
|
|
1132
1412
|
this.shaftMaterial.uniformsNeedUpdate = true;
|
|
1133
|
-
this.bounceMaterial.uniforms.uPatchIntensity.value = 0.
|
|
1134
|
-
this.bounceMaterial.uniforms.uBounceIntensity.value = 0.
|
|
1413
|
+
this.bounceMaterial.uniforms.uPatchIntensity.value = 0.14 * intensityScale;
|
|
1414
|
+
this.bounceMaterial.uniforms.uBounceIntensity.value = 0.055 * intensityScale;
|
|
1135
1415
|
this.bounceMaterial.uniformsNeedUpdate = true;
|
|
1136
1416
|
if (!this._enabled) {
|
|
1137
1417
|
this.group.visible = false;
|
|
@@ -1254,6 +1534,11 @@ export class SilhouetteLightVolumes {
|
|
|
1254
1534
|
const len = Math.hypot(nextSunDirection.x, nextSunDirection.y, nextSunDirection.z);
|
|
1255
1535
|
if (len > 1e-6) {
|
|
1256
1536
|
this.sunDirection.set(nextSunDirection.x / len, nextSunDirection.y / len, nextSunDirection.z / len);
|
|
1537
|
+
const uSunDir = this.shaftMaterial.uniforms.uSunDir?.value;
|
|
1538
|
+
if (uSunDir) {
|
|
1539
|
+
uSunDir.copy(this.sunDirection);
|
|
1540
|
+
this.shaftMaterial.uniformsNeedUpdate = true;
|
|
1541
|
+
}
|
|
1257
1542
|
}
|
|
1258
1543
|
}
|
|
1259
1544
|
if (!this._hasBuiltOnce) {
|
|
@@ -1394,9 +1679,10 @@ export class SilhouetteLightVolumes {
|
|
|
1394
1679
|
slice.shaftQuads = projected.shaftQuads;
|
|
1395
1680
|
slice.lightPatches = projected.lightPatches;
|
|
1396
1681
|
slice.bounceCards = projected.bounceCards;
|
|
1397
|
-
// 1. Pack volumetric sunbeam shaft quads
|
|
1682
|
+
// 1. Pack volumetric sunbeam shaft quads + crossed inner core planes into Draw Call #1
|
|
1398
1683
|
const sQuads = projected.shaftQuads;
|
|
1399
|
-
const
|
|
1684
|
+
const cQuads = projected.coreQuads ?? [];
|
|
1685
|
+
const sQCount = sQuads.length + cQuads.length;
|
|
1400
1686
|
const sVCount = sQCount * 4;
|
|
1401
1687
|
const sICount = sQCount * 6;
|
|
1402
1688
|
if (slice.shaftPositions.length < sVCount * 3) {
|
|
@@ -1413,12 +1699,11 @@ export class SilhouetteLightVolumes {
|
|
|
1413
1699
|
const sUv = slice.shaftUvs;
|
|
1414
1700
|
const sExt = slice.shaftExtrudeDists;
|
|
1415
1701
|
const sIdx = slice.shaftIndices;
|
|
1416
|
-
|
|
1417
|
-
const
|
|
1418
|
-
const vBase = q * 4;
|
|
1702
|
+
const writeShaftQuad = (qIndex, quad, colorScale) => {
|
|
1703
|
+
const vBase = qIndex * 4;
|
|
1419
1704
|
const pBase = vBase * 3;
|
|
1420
1705
|
const uBase = vBase * 2;
|
|
1421
|
-
const iBase =
|
|
1706
|
+
const iBase = qIndex * 6;
|
|
1422
1707
|
// V0: openingStart (u=0, v=0, extrudeDist=0)
|
|
1423
1708
|
sPos[pBase] = quad.openingStart.x;
|
|
1424
1709
|
sPos[pBase + 1] = quad.openingStart.y;
|
|
@@ -1467,9 +1752,9 @@ export class SilhouetteLightVolumes {
|
|
|
1467
1752
|
ny = 0;
|
|
1468
1753
|
nz = 0;
|
|
1469
1754
|
}
|
|
1470
|
-
const r = quad.color.r;
|
|
1471
|
-
const g = quad.color.g;
|
|
1472
|
-
const b = quad.color.b;
|
|
1755
|
+
const r = quad.color.r * colorScale;
|
|
1756
|
+
const g = quad.color.g * colorScale;
|
|
1757
|
+
const b = quad.color.b * colorScale;
|
|
1473
1758
|
for (let k = 0; k < 4; k++) {
|
|
1474
1759
|
const nk = pBase + k * 3;
|
|
1475
1760
|
sNorm[nk] = nx;
|
|
@@ -1485,13 +1770,24 @@ export class SilhouetteLightVolumes {
|
|
|
1485
1770
|
sIdx[iBase + 3] = vBase;
|
|
1486
1771
|
sIdx[iBase + 4] = vBase + 2;
|
|
1487
1772
|
sIdx[iBase + 5] = vBase + 3;
|
|
1773
|
+
};
|
|
1774
|
+
let sCursor = 0;
|
|
1775
|
+
for (let q = 0; q < sQuads.length; q++) {
|
|
1776
|
+
writeShaftQuad(sCursor++, sQuads[q], 1.0);
|
|
1777
|
+
}
|
|
1778
|
+
for (let q = 0; q < cQuads.length; q++) {
|
|
1779
|
+
writeShaftQuad(sCursor++, cQuads[q], 0.70);
|
|
1488
1780
|
}
|
|
1489
1781
|
slice.shaftVertexCount = sVCount;
|
|
1490
1782
|
slice.shaftIndexCount = sICount;
|
|
1491
|
-
// 2. Pack
|
|
1783
|
+
// 2. Pack surface-clamped floor light patches (role = 0) + flush 1-bounce GI halos (role = 1)
|
|
1492
1784
|
const patches = projected.lightPatches;
|
|
1493
1785
|
const cards = projected.bounceCards;
|
|
1494
|
-
|
|
1786
|
+
let patchQuadCount = 0;
|
|
1787
|
+
for (let i = 0; i < patches.length; i++) {
|
|
1788
|
+
patchQuadCount += patches[i].surfaceQuads?.length ?? 1;
|
|
1789
|
+
}
|
|
1790
|
+
const bQCount = patchQuadCount + cards.length;
|
|
1495
1791
|
const bVCount = bQCount * 4;
|
|
1496
1792
|
const bICount = bQCount * 6;
|
|
1497
1793
|
if (slice.bouncePositions.length < bVCount * 3) {
|
|
@@ -1508,16 +1804,17 @@ export class SilhouetteLightVolumes {
|
|
|
1508
1804
|
const bUv = slice.bounceUvs;
|
|
1509
1805
|
const bRole = slice.bounceRoles;
|
|
1510
1806
|
const bIdx = slice.bounceIndices;
|
|
1511
|
-
const writeQuad = (qIndex, corners, normal, color, role) => {
|
|
1807
|
+
const writeQuad = (qIndex, corners, normal, color, role, uvRect = [0, 0, 1, 1]) => {
|
|
1512
1808
|
const vBase = qIndex * 4;
|
|
1513
1809
|
const pBase = vBase * 3;
|
|
1514
1810
|
const uBase = vBase * 2;
|
|
1515
1811
|
const iBase = qIndex * 6;
|
|
1812
|
+
const [u0, v0, u1, v1] = uvRect;
|
|
1516
1813
|
const uvs = [
|
|
1517
|
-
[
|
|
1518
|
-
[
|
|
1519
|
-
[
|
|
1520
|
-
[
|
|
1814
|
+
[u0, v0],
|
|
1815
|
+
[u1, v0],
|
|
1816
|
+
[u1, v1],
|
|
1817
|
+
[u0, v1],
|
|
1521
1818
|
];
|
|
1522
1819
|
for (let k = 0; k < 4; k++) {
|
|
1523
1820
|
const pk = pBase + k * 3;
|
|
@@ -1546,7 +1843,16 @@ export class SilhouetteLightVolumes {
|
|
|
1546
1843
|
let qCursor = 0;
|
|
1547
1844
|
for (let i = 0; i < patches.length; i++) {
|
|
1548
1845
|
const p = patches[i];
|
|
1549
|
-
|
|
1846
|
+
const clampedQuads = p.surfaceQuads;
|
|
1847
|
+
if (clampedQuads && clampedQuads.length > 0) {
|
|
1848
|
+
for (let sq = 0; sq < clampedQuads.length; sq++) {
|
|
1849
|
+
const sub = clampedQuads[sq];
|
|
1850
|
+
writeQuad(qCursor++, sub.corners, sub.surfaceNormal, p.color, 0.0, sub.uvRect);
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
else {
|
|
1854
|
+
writeQuad(qCursor++, p.corners, p.surfaceNormal, p.color, 0.0);
|
|
1855
|
+
}
|
|
1550
1856
|
}
|
|
1551
1857
|
for (let i = 0; i < cards.length; i++) {
|
|
1552
1858
|
const c = cards[i];
|