@d5techs/3dgs-lib 1.4.60 → 1.4.62

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
@@ -2217,7 +2217,7 @@ struct V { @builtin(position) pos: vec4<f32>, @location(0) dir: vec3<f32> };
2217
2217
  const EQUIRECT_WGSL = (
2218
2218
  /* wgsl */
2219
2219
  `
2220
- struct Uniforms { col0: vec4<f32>, col1: vec4<f32>, col2: vec4<f32>, extra: vec4<f32> };
2220
+ struct Uniforms { col0: vec4<f32>, col1: vec4<f32>, col2: vec4<f32>, cam: vec4<f32> };
2221
2221
  @group(0) @binding(0) var<uniform> u: Uniforms;
2222
2222
  @group(0) @binding(1) var envSampler: sampler;
2223
2223
  @group(0) @binding(2) var envTexture: texture_2d<f32>;
@@ -2237,37 +2237,48 @@ fn dirToUv(d: vec3<f32>) -> vec2<f32> {
2237
2237
  }
2238
2238
 
2239
2239
  @fragment fn fs(i: V) -> @location(0) vec4<f32> {
2240
- let d = normalize(i.dir);
2241
- let camH = u.extra.x;
2242
- let R = u.extra.y;
2240
+ let d = normalize(i.dir);
2241
+ let cx = u.cam.x;
2242
+ let cy = u.cam.y;
2243
+ let cz = u.cam.z;
2244
+ let R = u.cam.w;
2243
2245
 
2244
- // --- sky ---
2246
+ // --- sky (always computed for uniform control flow) ---
2245
2247
  let skyUv = dirToUv(d);
2246
2248
 
2247
- // --- ground: inverted bowl hemisphere at Y=0 ---
2249
+ // --- ground: ray from camera hits Y=0 plane ---
2248
2250
  let dyClamped = min(d.y, -0.0001);
2249
- let t = -camH / dyClamped;
2250
- let hitX = t * d.x;
2251
- let hitZ = t * d.z;
2252
- let hitDist = sqrt(hitX * hitX + hitZ * hitZ);
2251
+ let t = -cy / dyClamped;
2252
+ // Hit point in WORLD space (not camera-relative)
2253
+ let wx = cx + t * d.x;
2254
+ let wz = cz + t * d.z;
2255
+ let wDist = sqrt(wx * wx + wz * wz);
2253
2256
 
2254
- // Clamp hit point inside the bowl radius
2255
- let s = min(1.0, R * 0.999 / max(hitDist, 0.001));
2256
- let bx = hitX * s;
2257
- let bz = hitZ * s;
2258
- // Project onto the lower hemisphere: y = -sqrt(R² - x² - z²)
2257
+ // Clamp inside the bowl radius (centered at world origin)
2258
+ let s = min(1.0, R * 0.999 / max(wDist, 0.001));
2259
+ let bx = wx * s;
2260
+ let bz = wz * s;
2261
+ // Inverted bowl: y = -sqrt(R² - x² - z²)
2259
2262
  let bowlY = -sqrt(max(R * R - bx * bx - bz * bz, 0.0));
2260
2263
  let groundDir = normalize(vec3(bx, bowlY, bz));
2261
- let groundUv = dirToUv(groundDir);
2264
+ let groundUv = dirToUv(groundDir);
2262
2265
 
2263
2266
  // --- sample both (uniform control flow) ---
2264
- let skyColor = textureSample(envTexture, envSampler, skyUv).rgb;
2265
- let groundColor = textureSample(envTexture, envSampler, groundUv).rgb;
2267
+ let skyColor = textureSample(envTexture, envSampler, skyUv).rgb;
2268
+ let hdrGround = textureSample(envTexture, envSampler, groundUv).rgb;
2269
+
2270
+ // Debug checkerboard to verify ground position
2271
+ let cx2 = floor(wx * 2.0);
2272
+ let cz2 = floor(wz * 2.0);
2273
+ let checker = ((cx2 + cz2) % 2.0 + 2.0) % 2.0;
2274
+ let checkerColor = mix(vec3(0.15, 0.15, 0.15), vec3(0.4, 0.4, 0.4), checker);
2275
+ // Mix HDR ground with subtle checker for position reference
2276
+ let groundColor = hdrGround * 0.8 + checkerColor * 0.2;
2266
2277
 
2267
- // Blend near horizon + fade at bowl edge
2268
- let horizonBlend = smoothstep(0.0, -0.08, d.y);
2269
- let aboveGround = step(0.01, camH);
2270
- let edgeFade = 1.0 - smoothstep(R * 0.7, R, hitDist);
2278
+ // Blend: horizon transition + fade at bowl edge
2279
+ let horizonBlend = smoothstep(0.0, -0.05, d.y);
2280
+ let aboveGround = step(0.01, cy);
2281
+ let edgeFade = 1.0 - smoothstep(R * 0.7, R, wDist);
2271
2282
  let finalBlend = horizonBlend * aboveGround * edgeFade;
2272
2283
  let c = mix(skyColor, groundColor, finalBlend);
2273
2284
 
@@ -2292,7 +2303,7 @@ class SkyboxRenderer {
2292
2303
  __publicField(this, "frameReady", false);
2293
2304
  __publicField(this, "mode", "none");
2294
2305
  /** Ground projection sphere radius (world units). Larger = ground extends further, flatter. */
2295
- __publicField(this, "groundRadius", 1e3);
2306
+ __publicField(this, "groundRadius", 50);
2296
2307
  this.device = device;
2297
2308
  const depthStencil = {
2298
2309
  format: depthFormat,
@@ -2429,10 +2440,10 @@ class SkyboxRenderer {
2429
2440
  ud[9] = viewMatrix[9];
2430
2441
  ud[10] = viewMatrix[10];
2431
2442
  ud[11] = 0;
2432
- ud[12] = cameraPosition ? cameraPosition[1] : 0;
2433
- ud[13] = this.groundRadius;
2434
- ud[14] = 0;
2435
- ud[15] = 0;
2443
+ ud[12] = cameraPosition ? cameraPosition[0] : 0;
2444
+ ud[13] = cameraPosition ? cameraPosition[1] : 0;
2445
+ ud[14] = cameraPosition ? cameraPosition[2] : 0;
2446
+ ud[15] = this.groundRadius;
2436
2447
  this.device.queue.writeBuffer(this.uniformBuffer, 0, ud);
2437
2448
  this.frameReady = true;
2438
2449
  }
@@ -19070,10 +19081,37 @@ class App {
19070
19081
  this.hotspotManager.updateBillboards();
19071
19082
  if ((_a2 = this.skyboxRenderer) == null ? void 0 : _a2.isActive) {
19072
19083
  const cam = this.camera.position;
19084
+ let groundLevel = 0;
19085
+ const gsRendererForGround = this.sceneManager.getGSRenderer();
19086
+ if (gsRendererForGround) {
19087
+ const bbox = gsRendererForGround.getBoundingBox();
19088
+ if (bbox) {
19089
+ const m = gsRendererForGround.getModelMatrix();
19090
+ groundLevel = m[5] * bbox.min[1] + m[13];
19091
+ if (!this._hdrDebugLogged) {
19092
+ this._hdrDebugLogged = true;
19093
+ console.log(
19094
+ "[HDR Ground Debug]",
19095
+ "bbox.min:",
19096
+ bbox.min,
19097
+ "bbox.max:",
19098
+ bbox.max,
19099
+ "bbox.center:",
19100
+ bbox.center,
19101
+ "groundLevel:",
19102
+ groundLevel,
19103
+ "cam:",
19104
+ [cam[0].toFixed(2), cam[1].toFixed(2), cam[2].toFixed(2)],
19105
+ "camH_effective:",
19106
+ (cam[1] - groundLevel).toFixed(2)
19107
+ );
19108
+ }
19109
+ }
19110
+ }
19073
19111
  this.skyboxRenderer.prepareFrame(
19074
19112
  this.camera.viewMatrix,
19075
19113
  this.camera.projectionMatrix,
19076
- [cam[0], cam[1], cam[2]]
19114
+ [cam[0], cam[1] - groundLevel, cam[2]]
19077
19115
  );
19078
19116
  }
19079
19117
  const pass = this.renderer.beginFrame();