Motion
Get Motion
Valley Hours, a still

DocsExample scenesTime, sound and the world

Example scene · Time, sound and the world

Valley Hours

A valley of hills, ridge behind ridge, that keeps the hours with you: rose and lilac at dawn, green and blue by day, ember and plum at dusk, and deep blue at night with stars, the moon, the village's windows lit and fireflies over the near slopes.

Intermediate5 layersA scriptHeaviest layer: Shader, heavy

Main feature: The time of day. Also uses: Logic as code, Materials, Layers and folders, The inspector.

What you'll learn

  • How a scene changes with the hour on your clock, two ways at once: a shader that reads the time itself, and a script that moves the layers that don't know the time.
  • How one shader drawn twice, with a part setting, lets other layers sit between its sky and its hills.
  • How a Time of day setting can hold the scene at one hour.

How it's built

The layers, bottom to top: Sky, Clouds, Hills, Mist, Fireflies.

  1. Sky is a Shader that reads the time itself: its code is given the seconds since midnight (iDate.w). From the hour it weighs how near it is to night, dawn, day and dusk, and mixes each one's colours, so the light moves on a little every minute with nothing else to drive it. The stars, the sun and the moon are drawn in the sky's part. The sun rises at six and sets at six by this clock, not by the season: for a sky that follows the real sun where you are, use the Real sky layer instead.
  2. Clouds is a Fog and clouds layer, drifting between the sky and the hills.
  3. Hills is the same shader drawn twice: its part setting is 0 for the sky and 1 for the hills. The ridges are noise along their length, with five layers of finer and finer detail, each ridge wider and lower than the one behind; the nearest two rise at the sides to frame the valley. Each ridge fades towards the sky's colour lower down, which reads as haze, and its top catches a thin line of the low sun at dawn and dusk. The woods are two-dimensional noise on the nearer slopes, the river is a wavy band that carries the sky's colour, and the village is a scatter of cells that light up as night comes.
  4. Mist is more fog, lying in the valley's folds.
  5. Fireflies are Motes, which come out after dark.
Picture: Valley Hours up to step 1, showing Sky
Step 1
Picture: Valley Hours up to step 2, showing Sky and Clouds
Step 2
Picture: Valley Hours up to step 3, showing Sky, Clouds and Hills
Step 3
Picture: Valley Hours up to step 4, showing Sky, Clouds, Hills and Mist
Step 4
Step 5

A TypeScript script reads scene.clock once a minute and moves the layers that don't know the time: the Fog and clouds layers take the light's colour, rose in the morning and amber in the evening, and the Motes come out as fireflies after dark. The Time of day setting can hold it at one hour, which the script hands to the shader.

Look in Studio

Open it from Studio's start page, under Start from one of Motion's.

  • For the script, pick Scene at the top of the Outliner and click Open the editor on its Script card: it opens as the script.ts tab. It's short: hourNow() reads the setting or the clock, darkness() turns the hour into 0 by day and 1 at night, and followTheHour() animates the clouds, the mist and the fireflies towards it over twenty seconds, every minute (scene.every).
  • Pick Sky or Hills and click Open the editor in the inspector to see the shader's code. Its part setting is among the layer's settings.

Make it yours

  • Change the palettes: the colours for night, dawn, day and dusk are the vec3s at the start of the sky's part and of the hills' part of the Shader's code, each a sum of four colours. Sky and Hills each have a copy, so change both.
  • Make it a seaside: drop the nearest ridge to a flat line and widen the river into the sea.
  • Add your own layers that follow the hour: in the script, scene.clock's daylight is a ready-made 0 at night to 1 at midday for any setting.

Settings people can change

SettingWhat it does
Time of dayFollows the clock, or stays at dawn, morning, afternoon, dusk or night
CloudsHow much cloud drifts over the sky
Mist in the valleyHow thick the mist lies in the folds
Fireflies after darkFireflies at night, or none
BloomHow much the bright parts bloom over everything
Ask about this page on the forumAsk a question in Help