Lighting has three layers. Use the ones the scene needs.
| Layer | Set with | What it gives |
|---|---|---|
| Look | <Scene look> |
Ready-made lights and a background. Most scenes need nothing else. |
| Environment | <Scene environment> or <Environment> |
What metals and glossy materials reflect, plus soft ambient light. |
| Your own lights | Light components, or <Daylight> |
Lights you place, or a sun that follows the time of day. |
Looks#
look |
Background | Lights | Good for |
|---|---|---|---|
"soft" (default) |
warm cream #f6efe6 |
warm sky light, warm key from the top right, cool fill | Toys, emoji-style objects, friendly UI |
"studio" |
cool grey #eceff3 |
neutral sky light, key and rim light | Product viewers |
"flat" |
white #ffffff |
even ambient light, no shading or tone mapping | Cartoon or UI-like flat colour |
"none" |
none | none | Lighting it yourself: an environment, <Daylight> or light components |
import { Box, Scene } from "@apricotjs/react-native";
export const Soft = () => (
<Scene style={{ flex: 1 }}>
<Box radius={0.15} color="#ff9f59" />
</Scene>
);
export const Studio = () => (
<Scene style={{ flex: 1 }} look="studio">
<Box radius={0.15} material="paint" />
</Scene>
);look is read once, when the scene mounts.
Environments: reflections#
An environment is a virtual photo studio, with a gradient from ceiling to floor and soft boxes of light. Metals and glossy paint reflect it, and it lights everything softly. It needs no image file and is ready at once.
environment |
Mood |
|---|---|
"none" (default) |
No reflections |
"studio" |
Dark studio with bright soft boxes: metals and cars |
"soft" |
Light and even: pale products, white phones, soft paint |
"sunset" |
A low warm sun, an orange horizon, a cool sky |
"night" |
Dark, with blue and pink neon strips and a thin light above |
For shiny objects, let the environment be the only light:
import { StudioFloor } from "@apricotjs/assets";
import { Scene, Sphere } from "@apricotjs/react-native";
export function Chrome() {
return (
<Scene style={{ flex: 1 }} look="none" environment="studio" background="#0e0f12">
<StudioFloor radius={6} colors={["#2a2d33", "#0e0f12"]} />
<Sphere radius={0.8} position={[0, 0.8, 0]} material="chrome" />
</Scene>
);
}Changing the environment at runtime#
<Scene environment> is fixed at mount. To switch, fade, dim or turn the studio, use <Environment> inside the scene. A new name fades in over transition seconds. rotation and intensity take shared values.
import { Environment, Scene, Sphere } from "@apricotjs/react-native";
import { Gesture, GestureDetector } from "react-native-gesture-handler";
import { useSharedValue } from "react-native-reanimated";
export function TurnTheLights({ night }: { night: boolean }) {
const turn = useSharedValue(0);
const start = useSharedValue(0);
const drag = Gesture.Pan()
.onBegin(() => {
start.value = turn.value;
})
.onUpdate((e) => {
turn.value = start.value + e.translationX / 120; // radians
});
return (
<GestureDetector gesture={drag}>
<Scene style={{ flex: 1 }} look="none" background="#0e0f12">
<Environment name={night ? "night" : "studio"} rotation={turn} transition={0.8} />
<Sphere radius={0.8} material="car-paint" />
</Scene>
</GestureDetector>
);
}Your own studio#
Describe one with sky, the ceiling, horizon and floor colours, and boxes. Each box is { direction, size, intensity, color }.
| Field | Meaning |
|---|---|
direction |
Points from the object towards the light. |
size |
Half width and half height, in radians. |
intensity |
Brightness. Above 1 makes highlights. |
color |
The light's colour. |
import { Environment, Scene, Sphere } from "@apricotjs/react-native";
export function CustomStudio() {
return (
<Scene style={{ flex: 1 }} look="none">
<Environment
sky={["#3b2f5c", "#1c1630", "#07060b"]}
boxes={[
{ direction: [0.4, 0.6, 0.7], size: [0.25, 0.12], intensity: 6, color: "#ffd9b0" },
{ direction: [-0.8, 0.1, 0.5], size: [0.06, 0.6], intensity: 4, color: "#9ab8ff" },
]}
/>
<Sphere radius={0.8} material="chrome" />
</Scene>
);
}To reuse a studio by name, register it once with defineEnvironment("brand", { sky, boxes, intensity }), then use environment="brand" or <Environment name="brand" />.
Light components#
Add lights on top of a look, or with look="none" as the only lights. intensity, position and target accept shared values, so lights can move and dim every frame.
| Component | Light | Key props (defaults) |
|---|---|---|
<AmbientLight> |
Even light from everywhere | color (white), intensity (1) |
<HemisphereLight> |
Sky colour from above, ground colour from below | sky (white), ground (warm grey), intensity |
<DirectionalLight> |
Sunlight: parallel rays | position ([3, 5, 4]), target ([0, 0, 0]), intensity, color, castShadow |
<PointLight> |
A bulb | position ([0, 2, 0]), distance (0: no limit), intensity, color |
<SpotLight> |
A cone of light | position, target, angle (0.5 rad half-angle), penumbra (0.3), distance |
import { DirectionalLight, HemisphereLight, Scene, Sphere } from "@apricotjs/react-native";
export function Lamp() {
return (
<Scene style={{ flex: 1 }} look="none" background="#ffffff">
<HemisphereLight sky="#ffe6cc" ground="#c83020" intensity={2} />
<DirectionalLight position={[-2, 4, 5]} intensity={2.1} color="#ffe8cc" />
<DirectionalLight position={[4, 1.5, 5]} intensity={0.9} color="#ffdcc0" />
<Sphere radius={0.8} color="#ff9f59" />
</Scene>
);
}Daylight: a sun that follows the clock#
<Daylight time> sets the sun, sky light and background for an hour of the day, from 0 to 24. Use it with look="none". A plain value animates over transition (1.5 s). A shared value is followed exactly, so a slider can scrub through the day. With an environment, reflections dim at night too.
import { Ground, Trees } from "@apricotjs/assets";
import { Daylight, Scene } from "@apricotjs/react-native";
export function DayNight({ hour }: { hour: number }) {
return (
<Scene style={{ flex: 1 }} look="none" environment="soft" fog shadows camera={{ position: [0, 12, 30] }}>
<Daylight time={hour} />
<Ground />
<Trees count={80} />
</Scene>
);
}| Option | Default | What it does |
|---|---|---|
sunrise, sunset |
6, 19 | The hours of sunrise and sunset. |
north |
0 (the sun rises at +x) | Turns the compass: where the sun rises, in radians. |
background |
true |
The sky colour becomes the background and fog colour. Never on a transparent scene. |
keys |
DAY |
Replaces the day's colours. |
Nights with DAY are nearly black, for rooms with their own lamps. For an outdoor place without lamps, use keys={MOONLIT}, imported from @apricotjs/react-native. It gives a bright moon and a deep blue sky.
Shadows#
Turn shadows on with the shadows prop. The main directional light casts them. That is the look's key light, <Daylight>'s sun, or the light marked <DirectionalLight castShadow>.
import { Box, Plane, Scene } from "@apricotjs/react-native";
export function Shadows() {
return (
<Scene style={{ flex: 1 }} shadows camera={{ position: [3, 3, 5] }}>
<Plane size={10} rotation={[-Math.PI / 2, 0, 0]} material="matte" color="#e8e1d7" />
<Box size={1} radius={0.1} position={[0, 0.5, 0]} />
</Scene>
);
}Who casts and receives#
Everything casts and receives shadows by default, with two exceptions. Flat things (floors, planes, decals) only receive. See-through things do neither. Override this per object with castShadow and receiveShadow on shapes, Mesh, Merged, Model and Instances.
shadowOnly hides an object but keeps its shadow. Use it for a roof over a cut-away room, so the sun comes in only through the window.
Options#
Pass an object instead of true: shadows={{ size, softness, darkness, radius, blur }}.
| Option | Default | What it does |
|---|---|---|
size |
1024 | Map resolution. 2048 is sharper and uses four times the memory. |
softness |
2 | Edge softness, in texels. |
darkness |
0.85 | From 0 to 1. |
radius |
For big scenes: the area in metres around what the camera looks at, for example { radius: 120 } for a city. |
|
blur |
true for wide, blurred edges, as under a room's soft light. softness then sets how far they blur (for example 8). |
When shadows redraw#
The shadow map is redrawn only when something that casts moves. Turning the camera around a still scene does not redraw it, except with radius: the shadow area follows the camera, so turning it can redraw the map. Each casting mesh is drawn again during a redraw, so use <Instances> for repeated casters.
Ambient occlusion and tone#
| Prop | What it does |
|---|---|
occlusion |
Soft darkening where surfaces meet or come close, such as the corners of a room or under a sofa. true, or { radius, strength, resolution, samples }. It adds GPU time to every frame. |
toneMapping |
How light becomes screen colour. "agx" (the default) is soft. "neutral" keeps colours closer to as written, so pastels stay rich. "filmic" has more contrast. "none" is raw. |
exposure |
Brightens (above 1) or darkens (below 1) the whole picture. |
These props are read at mount, like the other scene options. For interiors (a window, lamps at dusk), see Lighting a room.
Fog and background#
fog:truefades objects between 30 and 90 units into the background colour.{ near, far, color }sets the range. It hides the edge of a large ground.background: any colour, shown exactly as given, so the scene can match your UI.transparent: no background at all (overlays).
Related#
- Lights reference: every prop,
Daylight,Environment, shadows. - Lighting a room: sun through a window, light beams, lamps that come on at dusk.
- Shapes and materials.
- Paths and labels: the Metro line scene uses daylight, fog and shadows together.