Skip to content

NgtsSky

NgtsSky is a port of Drei’s Sky which renders a procedural sky dome using atmospheric scattering simulation.

Based on the Three.js Sky shader which simulates realistic sky colors based on sun position.

Usage

Basic Sky

<ngts-sky />

Sunset Sky

<ngts-sky
[options]="{
turbidity: 8,
rayleigh: 2,
inclination: 0.49,
azimuth: 0.25
}"
/>

Midday Sky

<ngts-sky
[options]="{
turbidity: 10,
rayleigh: 0.5,
inclination: 0.6,
azimuth: 0.1
}"
/>

Night Sky (Low Sun)

<ngts-sky
[options]="{
turbidity: 20,
rayleigh: 0.1,
inclination: 0.05,
azimuth: 0.5
}"
/>

Dawn/Dusk

<ngts-sky
[options]="{
turbidity: 10,
rayleigh: 3,
mieCoefficient: 0.005,
mieDirectionalG: 0.7,
inclination: 0.52,
azimuth: 0.25
}"
/>

Hazy Atmosphere

<ngts-sky
[options]="{
turbidity: 20,
rayleigh: 0.5,
mieCoefficient: 0.03,
mieDirectionalG: 0.9,
inclination: 0.6
}"
/>

Direct Sun Position

Override inclination/azimuth with a direct position vector:

<ngts-sky
[options]="{
sunPosition: sunPosition,
turbidity: 10,
rayleigh: 2
}"
/>
// In component
sunPosition = new THREE.Vector3(100, 50, 100);

Animated Day/Night Cycle

@Component({
template: `
<ngts-sky [options]="{ inclination: inclination(), turbidity: 10, rayleigh: 2 }" />
`,
})
export class Scene {
inclination = signal(0.5);
constructor() {
// Animate sun position over time
injectBeforeRender(({ clock }) => {
const time = clock.getElapsedTime();
this.inclination.set(0.5 + Math.sin(time * 0.1) * 0.4);
});
}
}

With Directional Light

Sync a directional light with the sky’s sun position:

<ngts-sky [options]="{ inclination: 0.5, azimuth: 0.25 }" />
<ngt-directional-light
[position]="sunLightPosition"
[intensity]="1.5"
[castShadow]="true"
/>

Parameter Reference

ParameterEffectLow ValueHigh Value
turbidityAtmospheric hazinessClear skyFoggy/dusty
rayleighBlue color intensityLess blueDeeper blue
mieCoefficientSun halo/glow intensityNo haloStrong halo
mieDirectionalGSun disc sizeLarger sun discSmaller sun disc
inclinationSun height (0-1)Below horizonAbove head
azimuthSun rotation (0-1)EastFull circle

Notes

  • The sky shader simulates Rayleigh and Mie scattering for realistic atmospheric effects
  • inclination of 0.5 places the sun at the horizon; values above move it higher
  • azimuth controls horizontal rotation of the sun around the scene
  • Use sunPosition for precise control, overriding inclination/azimuth
  • Combine with a directional light positioned at the same sun location for accurate shadows
  • The distance parameter affects how large the sky sphere appears

Options

Properties

name type description
distance number Distance of the sky sphere from the camera. Default: 1000
inclination number Vertical angle of the sun (0-1, where 0.5 is horizon). Default: 0.6
azimuth number Horizontal angle of the sun (0-1, representing full rotation). Default: 0.1
mieCoefficient number Mie scattering coefficient. Controls haze and sun disc intensity. Default: 0.005
mieDirectionalG number Mie scattering directional parameter. Controls sun disc size. Default: 0.8
rayleigh number Rayleigh scattering coefficient. Higher values create bluer skies. Default: 0.5
turbidity number Atmospheric turbidity. Higher values create hazier atmospheres. Default: 10
sunPosition THREE.Vector3 Direct sun position vector. Overrides inclination/azimuth if set.