@d5techs/3dgs-lib 1.4.65 → 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.cjs CHANGED
@@ -2239,38 +2239,23 @@ fn dirToUv(d: vec3<f32>) -> vec2<f32> {
2239
2239
  @fragment fn fs(i: V) -> @location(0) vec4<f32> {
2240
2240
  let d = normalize(i.dir);
2241
2241
  let cx = u.cam.x;
2242
- let cy = u.cam.y;
2242
+ let cy = max(u.cam.y, 0.1);
2243
2243
  let cz = u.cam.z;
2244
2244
  let R = u.cam.w;
2245
2245
 
2246
- // --- sky: sample HDR with original direction ---
2247
- let skyUv = dirToUv(d);
2246
+ // Ray-sphere intersection: camera at (cx, cy, cz), sphere radius R at origin
2247
+ let origin = vec3(cx, cy, cz);
2248
+ let halfB = dot(origin, d);
2249
+ let cVal = dot(origin, origin) - R * R;
2250
+ let disc = halfB * halfB - cVal;
2248
2251
 
2249
- // --- ground: ray from camera hits ground plane ---
2250
- let dyClamped = min(d.y, -0.0001);
2251
- let t = -cy / dyClamped;
2252
- let wx = cx + t * d.x;
2253
- let wz = cz + t * d.z;
2254
- let wDist = sqrt(wx * wx + wz * wz);
2252
+ // Far intersection (camera is inside sphere)
2253
+ let t = -halfB + sqrt(max(disc, 0.0));
2254
+ let hitPoint = origin + t * d;
2255
+ let sampleDir = normalize(hitPoint);
2255
2256
 
2256
- // Bowl projection centered at world origin
2257
- let s = min(1.0, R * 0.999 / max(wDist, 0.001));
2258
- let bx = wx * s;
2259
- let bz = wz * s;
2260
- let bowlY = -sqrt(max(R * R - bx * bx - bz * bz, 0.0));
2261
- let groundDir = normalize(vec3(bx, bowlY, bz));
2262
- let groundUv = dirToUv(groundDir);
2263
-
2264
- // --- sample both (uniform control flow) ---
2265
- let skyColor = textureSample(envTexture, envSampler, skyUv).rgb;
2266
- let groundColor = textureSample(envTexture, envSampler, groundUv).rgb;
2267
-
2268
- // Sharp blend right at the horizon (d.y = 0)
2269
- let horizonBlend = smoothstep(0.002, -0.002, d.y);
2270
- let aboveGround = step(0.01, cy);
2271
- let edgeFade = 1.0 - smoothstep(R * 0.85, R, wDist);
2272
- let finalBlend = horizonBlend * aboveGround * edgeFade;
2273
- let c = mix(skyColor, groundColor, finalBlend);
2257
+ let uv = dirToUv(sampleDir);
2258
+ let c = textureSample(envTexture, envSampler, uv).rgb;
2274
2259
 
2275
2260
  // Reinhard tone mapping + gamma
2276
2261
  let mapped = c / (c + vec3(1.));
@@ -2292,7 +2277,7 @@ class SkyboxRenderer {
2292
2277
  __publicField(this, "bindGroup", null);
2293
2278
  __publicField(this, "frameReady", false);
2294
2279
  __publicField(this, "mode", "none");
2295
- /** Ground projection sphere radius (world units). Larger = ground extends further, flatter. */
2280
+ /** Virtual HDR capture height (world units). Controls ground texture spread. */
2296
2281
  __publicField(this, "groundRadius", 50);
2297
2282
  this.device = device;
2298
2283
  const depthStencil = {
@@ -19095,7 +19080,8 @@ class App {
19095
19080
  );
19096
19081
  }
19097
19082
  const camH = cam[1] - groundLevel;
19098
- this.skyboxRenderer.groundRadius = Math.max(200, camH * 3);
19083
+ const camDist = Math.sqrt(cam[0] * cam[0] + camH * camH + cam[2] * cam[2]);
19084
+ this.skyboxRenderer.groundRadius = Math.max(500, camDist + 200);
19099
19085
  this.skyboxRenderer.prepareFrame(
19100
19086
  this.camera.viewMatrix,
19101
19087
  this.camera.projectionMatrix,