Real-Time Lighting, Atmospheric Scattering, and Galaxy Rendering in Baidu Maps WebGL

This article explains how Baidu Maps' WebGL engine implements real‑time lighting based on solar position, simulates atmospheric scattering using Rayleigh and Mie models, and renders the Milky Way on a celestial sphere, detailing the calculations, textures, and visual results.

Baidu Maps Tech Team
Baidu Maps Tech Team
Baidu Maps Tech Team
Real-Time Lighting, Atmospheric Scattering, and Galaxy Rendering in Baidu Maps WebGL

Lighting Effects

Because Earth rotates and revolves, the sun’s direct position changes throughout the year. In the WebGL map engine, real‑time lighting is applied to 3D buildings, calculating shadows based on the current sun position. The engine computes the sun’s sub‑solar point, altitude, and azimuth from the current time and map view, then derives shadow direction and length. When viewing Beijing at night, shadows disappear. At low zoom levels the Earth mode shows the sun’s sub‑solar point, distinguishing day, night, dawn and dusk.

Related solar‑angle calculations can be found in public references on solar geometry.

Atmospheric Effects

The atmosphere forms a bright halo around Earth when seen from space, with colour gradients caused by Rayleigh and Mie scattering. Rayleigh scattering, driven by tiny particles, preferentially scatters short‑wavelength light (blue), while Mie scattering from larger particles (dust, droplets) is wavelength‑independent and produces clouds and haze. GPU Gems 2 provides a detailed implementation of atmospheric scattering.

Different parameters are set for the atmospheric layer and the ground to achieve realistic results.

Galaxy Implementation

To render the Milky Way, a celestial sphere is defined whose equator aligns with Earth’s equator and whose poles match Earth’s poles. Celestial coordinates (right ascension and declination) map stars onto this sphere. A texture from the European Southern Observatory is used, rotated so its equator matches the sphere’s equator, then replaced with a proper Milky Way texture.

The sphere is oriented so that the 0° right ascension aligns with the sun’s position at the spring equinox; the current time determines the sphere’s rotation relative to Earth’s orbit, producing an accurate placement of the galaxy.

The final rendering matches the real sky position.

Conclusion

This article concludes the WebGL map engine series, covering core techniques such as WebWorker usage, rendering architecture, performance optimization, and visual effects like lighting, atmospheric scattering, and galaxy rendering. The engine remains a complex system with room for further improvement.

WebGLatmospheric scatteringgalaxy renderingMap Enginereal-time lighting
Baidu Maps Tech Team
Written by

Baidu Maps Tech Team

Want to see the Baidu Maps team's technical insights, learn how top engineers tackle tough problems, or join the team? Follow the Baidu Maps Tech Team to get the answers you need.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.