@d5techs/3dgs-lib 1.4.64 → 1.4.66

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.js CHANGED
@@ -2239,37 +2239,29 @@ fn dirToUv(d: vec3<f32>) -> vec2<f32> {
2239
2239
  let cx = u.cam.x;
2240
2240
  let cy = u.cam.y;
2241
2241
  let cz = u.cam.z;
2242
- let R = u.cam.w;
2242
+ let captureH = u.cam.w;
2243
2243
 
2244
- // --- sky: clamp to upper hemisphere so HDR's own ground doesn't show ---
2245
- let skyDir = normalize(vec3(d.x, max(d.y, 0.001), d.z));
2246
- let skyUv = dirToUv(skyDir);
2244
+ // --- sky: sample HDR with original direction ---
2245
+ let skyUv = dirToUv(d);
2247
2246
 
2248
- // --- ground: ray from camera hits ground plane ---
2247
+ // --- ground: ray→plane at Y=0, then map hit point to HDR direction ---
2249
2248
  let dyClamped = min(d.y, -0.0001);
2250
2249
  let t = -cy / dyClamped;
2251
- let wx = cx + t * d.x;
2252
- let wz = cz + t * d.z;
2253
- let wDist = sqrt(wx * wx + wz * wz);
2250
+ let hitX = cx + t * d.x;
2251
+ let hitZ = cz + t * d.z;
2254
2252
 
2255
- // Bowl projection centered at world origin
2256
- let s = min(1.0, R * 0.999 / max(wDist, 0.001));
2257
- let bx = wx * s;
2258
- let bz = wz * s;
2259
- let bowlY = -sqrt(max(R * R - bx * bx - bz * bz, 0.0));
2260
- let groundDir = normalize(vec3(bx, bowlY, bz));
2253
+ // Direction from virtual capture point (0, captureH, 0) to ground hit point
2254
+ let groundDir = normalize(vec3(hitX, -captureH, hitZ));
2261
2255
  let groundUv = dirToUv(groundDir);
2262
2256
 
2263
2257
  // --- sample both (uniform control flow) ---
2264
2258
  let skyColor = textureSample(envTexture, envSampler, skyUv).rgb;
2265
2259
  let groundColor = textureSample(envTexture, envSampler, groundUv).rgb;
2266
2260
 
2267
- // Blend: horizon transition + fade at bowl edge
2268
- let horizonBlend = smoothstep(0.0, -0.05, d.y);
2261
+ // Sharp blend at horizon, no edge fade needed
2262
+ let horizonBlend = smoothstep(0.002, -0.002, d.y);
2269
2263
  let aboveGround = step(0.01, cy);
2270
- let edgeFade = 1.0 - smoothstep(R * 0.7, R, wDist);
2271
- let finalBlend = horizonBlend * aboveGround * edgeFade;
2272
- let c = mix(skyColor, groundColor, finalBlend);
2264
+ let c = mix(skyColor, groundColor, horizonBlend * aboveGround);
2273
2265
 
2274
2266
  // Reinhard tone mapping + gamma
2275
2267
  let mapped = c / (c + vec3(1.));
@@ -2291,7 +2283,7 @@ class SkyboxRenderer {
2291
2283
  __publicField(this, "bindGroup", null);
2292
2284
  __publicField(this, "frameReady", false);
2293
2285
  __publicField(this, "mode", "none");
2294
- /** Ground projection sphere radius (world units). Larger = ground extends further, flatter. */
2286
+ /** Virtual HDR capture height (world units). Controls ground texture spread. */
2295
2287
  __publicField(this, "groundRadius", 50);
2296
2288
  this.device = device;
2297
2289
  const depthStencil = {
@@ -19093,10 +19085,12 @@ class App {
19093
19085
  [cam[0].toFixed(2), cam[1].toFixed(2), cam[2].toFixed(2)]
19094
19086
  );
19095
19087
  }
19088
+ const camH = cam[1] - groundLevel;
19089
+ this.skyboxRenderer.groundRadius = 50;
19096
19090
  this.skyboxRenderer.prepareFrame(
19097
19091
  this.camera.viewMatrix,
19098
19092
  this.camera.projectionMatrix,
19099
- [cam[0], cam[1] - groundLevel, cam[2]]
19093
+ [cam[0], camH, cam[2]]
19100
19094
  );
19101
19095
  }
19102
19096
  const pass = this.renderer.beginFrame();