@d5techs/3dgs-lib 1.4.57 → 1.4.59

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/3dgs-lib.cjs CHANGED
@@ -2238,40 +2238,37 @@ fn dirToUv(d: vec3<f32>) -> vec2<f32> {
2238
2238
 
2239
2239
  @fragment fn fs(i: V) -> @location(0) vec4<f32> {
2240
2240
  let d = normalize(i.dir);
2241
- let camY = u.extra.x;
2242
- let sphereR = u.extra.y;
2241
+ let camH = u.extra.x;
2242
+ let projR = u.extra.y;
2243
2243
 
2244
- // --- sky UV (always computed) ---
2244
+ // --- sky UV (always computed for uniform control flow) ---
2245
2245
  let skyUv = dirToUv(d);
2246
2246
 
2247
- // --- ground projection (always computed for uniform control flow) ---
2248
- // Ray from camera (0, camY, 0) in direction d hits plane y=0 at t
2247
+ // --- flat ground projection ---
2248
+ // Ray from camera at height camH above ground, direction d,
2249
+ // hits ground plane at t = -camH / d.y
2249
2250
  let dyClamped = min(d.y, -0.0001);
2250
- let t = -camY / dyClamped;
2251
+ let t = -camH / dyClamped;
2251
2252
  let hitX = t * d.x;
2252
2253
  let hitZ = t * d.z;
2253
2254
  let hitDist = sqrt(hitX * hitX + hitZ * hitZ);
2254
2255
 
2255
- // Project the ground hit point back onto a sphere of radius R
2256
- // centered at the camera projection on y=0 (i.e. center = origin).
2257
- // For points beyond R, fade to horizon sampling.
2258
- let ratio = min(hitDist, sphereR) / max(hitDist, 0.001);
2259
- let pX = hitX * ratio;
2260
- let pZ = hitZ * ratio;
2261
- let pY = -sqrt(max(sphereR * sphereR - pX * pX - pZ * pZ, 0.0));
2262
- let groundDir = normalize(vec3(pX, pY, pZ));
2256
+ // Re-map to a direction on the HDR sphere from a virtual capture
2257
+ // height above ground. Larger = more ground texture visible,
2258
+ // smaller = more horizon. 15 matches Three.js GroundProjectedEnv default.
2259
+ let captureH = 15.0;
2260
+ let groundDir = normalize(vec3(hitX, -captureH, hitZ));
2263
2261
  let groundUv = dirToUv(groundDir);
2264
2262
 
2265
- // --- sample both (unconditional = uniform control flow) ---
2263
+ // --- sample both unconditionally (uniform control flow) ---
2266
2264
  let skyColor = textureSample(envTexture, envSampler, skyUv).rgb;
2267
2265
  let groundColor = textureSample(envTexture, envSampler, groundUv).rgb;
2268
2266
 
2269
2267
  // Blend: smooth transition near horizon
2270
- // step(0.01, camY) disables ground projection when camera is at/below ground
2271
- let groundFactor = smoothstep(0.01, -0.15, d.y) * step(0.01, camY);
2272
- // Fade out ground color at the sphere edge to avoid hard seam
2273
- let edgeFade = 1.0 - smoothstep(sphereR * 0.7, sphereR * 0.99, hitDist);
2274
- let finalBlend = groundFactor * edgeFade;
2268
+ let horizonBlend = smoothstep(0.0, -0.12, d.y);
2269
+ let aboveGround = step(0.01, camH);
2270
+ let edgeFade = 1.0 - smoothstep(projR * 0.6, projR, hitDist);
2271
+ let finalBlend = horizonBlend * aboveGround * edgeFade;
2275
2272
  let c = mix(skyColor, groundColor, finalBlend);
2276
2273
 
2277
2274
  // Reinhard tone mapping + gamma
@@ -2295,7 +2292,7 @@ class SkyboxRenderer {
2295
2292
  __publicField(this, "frameReady", false);
2296
2293
  __publicField(this, "mode", "none");
2297
2294
  /** Ground projection sphere radius (world units). Larger = ground extends further, flatter. */
2298
- __publicField(this, "groundRadius", 500);
2295
+ __publicField(this, "groundRadius", 1e3);
2299
2296
  this.device = device;
2300
2297
  const depthStencil = {
2301
2298
  format: depthFormat,
@@ -2414,7 +2411,7 @@ class SkyboxRenderer {
2414
2411
  this.mode = "equirect";
2415
2412
  }
2416
2413
  // ---- common ----
2417
- prepareFrame(viewMatrix, projectionMatrix, cameraPosition, groundY) {
2414
+ prepareFrame(viewMatrix, projectionMatrix, cameraPosition) {
2418
2415
  if (!this.isActive) {
2419
2416
  this.frameReady = false;
2420
2417
  return;
@@ -2432,9 +2429,7 @@ class SkyboxRenderer {
2432
2429
  ud[9] = viewMatrix[9];
2433
2430
  ud[10] = viewMatrix[10];
2434
2431
  ud[11] = 0;
2435
- const camWorldY = cameraPosition ? cameraPosition[1] : 0;
2436
- const gndY = groundY ?? 0;
2437
- ud[12] = camWorldY - gndY;
2432
+ ud[12] = cameraPosition ? cameraPosition[1] : 0;
2438
2433
  ud[13] = this.groundRadius;
2439
2434
  ud[14] = 0;
2440
2435
  ud[15] = 0;
@@ -19075,22 +19070,10 @@ class App {
19075
19070
  this.hotspotManager.updateBillboards();
19076
19071
  if ((_a2 = this.skyboxRenderer) == null ? void 0 : _a2.isActive) {
19077
19072
  const cam = this.camera.position;
19078
- let groundY = 0;
19079
- const gsRenderer2 = this.sceneManager.getGSRenderer();
19080
- if (gsRenderer2) {
19081
- const bbox = gsRenderer2.getBoundingBox();
19082
- if (bbox) {
19083
- const m = gsRenderer2.getModelMatrix();
19084
- const minLocalY = bbox.center[1] - bbox.radius;
19085
- groundY = minLocalY * m[5] + bbox.center[1] * (m[5] - m[5]) + m[13];
19086
- groundY = (bbox.center[1] - bbox.radius) * m[5] + m[13];
19087
- }
19088
- }
19089
19073
  this.skyboxRenderer.prepareFrame(
19090
19074
  this.camera.viewMatrix,
19091
19075
  this.camera.projectionMatrix,
19092
- [cam[0], cam[1], cam[2]],
19093
- groundY
19076
+ [cam[0], cam[1], cam[2]]
19094
19077
  );
19095
19078
  }
19096
19079
  const pass = this.renderer.beginFrame();