@d5techs/3dgs-lib 1.4.66 → 1.4.67

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
@@ -2237,31 +2237,23 @@ fn dirToUv(d: vec3<f32>) -> vec2<f32> {
2237
2237
  @fragment fn fs(i: V) -> @location(0) vec4<f32> {
2238
2238
  let d = normalize(i.dir);
2239
2239
  let cx = u.cam.x;
2240
- let cy = u.cam.y;
2240
+ let cy = max(u.cam.y, 0.1);
2241
2241
  let cz = u.cam.z;
2242
- let captureH = u.cam.w;
2242
+ let R = u.cam.w;
2243
2243
 
2244
- // --- sky: sample HDR with original direction ---
2245
- let skyUv = dirToUv(d);
2244
+ // Ray-sphere intersection: camera at (cx, cy, cz), sphere radius R at origin
2245
+ let origin = vec3(cx, cy, cz);
2246
+ let halfB = dot(origin, d);
2247
+ let cVal = dot(origin, origin) - R * R;
2248
+ let disc = halfB * halfB - cVal;
2246
2249
 
2247
- // --- ground: ray→plane at Y=0, then map hit point to HDR direction ---
2248
- let dyClamped = min(d.y, -0.0001);
2249
- let t = -cy / dyClamped;
2250
- let hitX = cx + t * d.x;
2251
- let hitZ = cz + t * d.z;
2250
+ // Far intersection (camera is inside sphere)
2251
+ let t = -halfB + sqrt(max(disc, 0.0));
2252
+ let hitPoint = origin + t * d;
2253
+ let sampleDir = normalize(hitPoint);
2252
2254
 
2253
- // Direction from virtual capture point (0, captureH, 0) to ground hit point
2254
- let groundDir = normalize(vec3(hitX, -captureH, hitZ));
2255
- let groundUv = dirToUv(groundDir);
2256
-
2257
- // --- sample both (uniform control flow) ---
2258
- let skyColor = textureSample(envTexture, envSampler, skyUv).rgb;
2259
- let groundColor = textureSample(envTexture, envSampler, groundUv).rgb;
2260
-
2261
- // Sharp blend at horizon, no edge fade needed
2262
- let horizonBlend = smoothstep(0.002, -0.002, d.y);
2263
- let aboveGround = step(0.01, cy);
2264
- let c = mix(skyColor, groundColor, horizonBlend * aboveGround);
2255
+ let uv = dirToUv(sampleDir);
2256
+ let c = textureSample(envTexture, envSampler, uv).rgb;
2265
2257
 
2266
2258
  // Reinhard tone mapping + gamma
2267
2259
  let mapped = c / (c + vec3(1.));
@@ -19086,7 +19078,8 @@ class App {
19086
19078
  );
19087
19079
  }
19088
19080
  const camH = cam[1] - groundLevel;
19089
- this.skyboxRenderer.groundRadius = 50;
19081
+ const camDist = Math.sqrt(cam[0] * cam[0] + camH * camH + cam[2] * cam[2]);
19082
+ this.skyboxRenderer.groundRadius = Math.max(500, camDist + 200);
19090
19083
  this.skyboxRenderer.prepareFrame(
19091
19084
  this.camera.viewMatrix,
19092
19085
  this.camera.projectionMatrix,