Atmosphere: floating origin mode assumes the world origin is the planet centre (black sky in ground-level scenes)

Open
#19,212 1 comment 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript

Research direction

Read AtmospherePerCameraVariables.update and AtmospherePBRMaterialPlugin.bindForSubMesh in the atmosphere addon; the issue identifies both floating origin calculations that assume the origin is the planet centre. Trace how planet radius and origin offsets are used, then compare a ground level scene with floating origin enabled against the same scene without it. Done when the sky and PBR lighting match in both modes while existing globe behavior remains intact.

Written by the indexing model from the issue text.

Description

in progress
Summary

With useLargeWorldRendering: true (so scene.floatingOriginMode is on), Atmosphere from @babylonjs/addons assumes that the world origin is the planet centre. A ground-level scene, where the origin is on the surface (the usual case outside geospatial globes), then gets a black sky, and PBR materials that receive the atmosphere plugin are lit with a wrong offset. Without useLargeWorldRendering the same scene renders a correct sky.

Version: @babylonjs/core and @babylonjs/addons 9.37.1, Chrome 158, WebGL2 (ANGLE Vulkan) and WebGPU.

Where
  1. AtmospherePerCameraVariables.update: in floating origin mode it normalizes the camera's global position as the geocentric normal and adds originHeight along it. With the origin on the ground the camera is ~0 km from the "planet centre", so it is clamped onto the surface with an arbitrary "up". The non-floating branch (y += planetRadius + originHeight) is what a ground-level scene needs.
  2. AtmospherePBRMaterialPlugin.bindForSubMesh: in floating origin mode originOffsetKm is floatingOriginOffset * 0.001 only, without the planet radius that the non-floating branch adds, so world positions are treated as planet-centred too.
Repro

Any scene with a camera a few metres above y = 0 and a DirectionalLight pointing down:

const engine = new BABYLON.Engine(canvas, true, { useLargeWorldRendering: true });
// scene, camera at (0, 1.7, 0), sun = new DirectionalLight("sun", new Vector3(0.4, -1, 0.5), scene)
const atmosphere = new ADDONS.Atmosphere("sky", scene, [sun]);

Expected: the same blue sky as with useLargeWorldRendering: false. Actual: black sky (the sky compositor runs, but the camera is placed inside the planet).

Possible fix

An option telling the atmosphere where the planet centre is in floating origin mode (for example a boolean "origin on the surface" or an explicit planet-centre offset), used by both places above, keeping today's globe behaviour as the default. We work around it locally by running update as in the non-floating branch and by adding (0, planetRadius, 0) to originOffsetKm after bindForSubMesh; frames then match the non-floating scene.

Dominant language
TypeScript
Stars
26.6k
Forks
3.8k
Avg merge
1d 9h
Merged PRs (30d)
112

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from BabylonJS/Babylon.js

All issues in BabylonJS/Babylon.js

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.