@d5techs/3dgs-lib 1.4.59 → 1.4.60

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,41 +2237,41 @@ 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 camH = u.extra.x;
2240
- let projR = u.extra.y;
2240
+ let R = u.extra.y;
2241
2241
 
2242
- // --- sky UV (always computed for uniform control flow) ---
2242
+ // --- sky ---
2243
2243
  let skyUv = dirToUv(d);
2244
2244
 
2245
- // --- flat ground projection ---
2246
- // Ray from camera at height camH above ground, direction d,
2247
- // hits ground plane at t = -camH / d.y
2245
+ // --- ground: inverted bowl hemisphere at Y=0 ---
2248
2246
  let dyClamped = min(d.y, -0.0001);
2249
2247
  let t = -camH / dyClamped;
2250
2248
  let hitX = t * d.x;
2251
2249
  let hitZ = t * d.z;
2252
2250
  let hitDist = sqrt(hitX * hitX + hitZ * hitZ);
2253
2251
 
2254
- // Re-map to a direction on the HDR sphere from a virtual capture
2255
- // height above ground. Larger = more ground texture visible,
2256
- // smaller = more horizon. 15 matches Three.js GroundProjectedEnv default.
2257
- let captureH = 15.0;
2258
- let groundDir = normalize(vec3(hitX, -captureH, hitZ));
2252
+ // Clamp hit point inside the bowl radius
2253
+ let s = min(1.0, R * 0.999 / max(hitDist, 0.001));
2254
+ let bx = hitX * s;
2255
+ let bz = hitZ * s;
2256
+ // Project onto the lower hemisphere: y = -sqrt( - x² - z²)
2257
+ let bowlY = -sqrt(max(R * R - bx * bx - bz * bz, 0.0));
2258
+ let groundDir = normalize(vec3(bx, bowlY, bz));
2259
2259
  let groundUv = dirToUv(groundDir);
2260
2260
 
2261
- // --- sample both unconditionally (uniform control flow) ---
2262
- let skyColor = textureSample(envTexture, envSampler, skyUv).rgb;
2261
+ // --- sample both (uniform control flow) ---
2262
+ let skyColor = textureSample(envTexture, envSampler, skyUv).rgb;
2263
2263
  let groundColor = textureSample(envTexture, envSampler, groundUv).rgb;
2264
2264
 
2265
- // Blend: smooth transition near horizon
2266
- let horizonBlend = smoothstep(0.0, -0.12, d.y);
2267
- let aboveGround = step(0.01, camH);
2268
- let edgeFade = 1.0 - smoothstep(projR * 0.6, projR, hitDist);
2269
- let finalBlend = horizonBlend * aboveGround * edgeFade;
2265
+ // Blend near horizon + fade at bowl edge
2266
+ let horizonBlend = smoothstep(0.0, -0.08, d.y);
2267
+ let aboveGround = step(0.01, camH);
2268
+ let edgeFade = 1.0 - smoothstep(R * 0.7, R, hitDist);
2269
+ let finalBlend = horizonBlend * aboveGround * edgeFade;
2270
2270
  let c = mix(skyColor, groundColor, finalBlend);
2271
2271
 
2272
2272
  // Reinhard tone mapping + gamma
2273
2273
  let mapped = c / (c + vec3(1.));
2274
- let gamma = pow(mapped, vec3(1./2.2));
2274
+ let gamma = pow(mapped, vec3(1./2.2));
2275
2275
  return vec4(gamma, 1.);
2276
2276
  }`
2277
2277
  );