Colour effects
Updated
Colour effects change the tones of the whole image: an old-photo Sepia, a black-and-white Grayscale, a shift in Hue/Saturation, and a Vignette that darkens the edges. Each is one component on a camera.
| Component | Type | What it does |
|---|---|---|
| Hue Saturation Effect | comp-hue-saturation-effect | Shifts the colours around the colour wheel and makes them duller or more vivid. |
| Sepia Effect | comp-sepia-effect | Tints the image brown, like an old photograph. |
| Grayscale Effect | comp-grayscale-effect | Renders the image in black and white. |
| Vignette Effect | comp-vignette-effect | Darkens the edges of the image. |
The effects
Section titled “The effects”Hue/Saturation
Section titled “Hue/Saturation”HueSaturationEffectComponent turns colours around the colour wheel and changes how vivid they are.
| Prop | Type | Default | Description |
|---|---|---|---|
hue |
number |
0 |
Turn of every colour around the wheel, in degrees, -180 to 180. |
saturation |
number |
0 |
Colourfulness: -1 grey, 0 unchanged, 1 vivid. |
SepiaEffectComponent tints the image brown, like an old photograph.
| Prop | Type | Default | Description |
|---|---|---|---|
intensity |
number |
1 |
How strongly the brown tone replaces the colours, 0 to 1. |
Grayscale
Section titled “Grayscale”GrayscaleEffectComponent renders the image in black and white.
| Prop | Type | Default | Description |
|---|---|---|---|
intensity |
number |
1 |
How far the colours fade to grey, 0 to 1. |
Vignette
Section titled “Vignette”VignetteEffectComponent darkens the edges of the image.
| Prop | Type | Default | Description |
|---|---|---|---|
darkness |
number |
0.5 |
How dark the edges get, 0 to 1. |
offset |
number |
0.5 |
How far from the centre the darkening starts, 0 to 1. |
Examples
Section titled “Examples”1. Flash the screen when the player is hurt
Section titled “1. Flash the screen when the player is hurt”Damage feedback: the vignette darkens sharply and recovers, and the image glitches for a moment. Another script emits player/hurt with the damage amount. The Glitch effect is saved on the camera with active set to false.
#pragma lifecycle(startup)
let vignette;let glitch;let pulse = null;let quiet = null;
function startup() { const eye = findEntity('Main Camera'); vignette = eye.getComponent(VignetteEffectComponent); glitch = eye.getComponent(GlitchEffectComponent); glitch.setProps({ active: false });
on('player/hurt', (data) => { const amount = Math.min(1, (data?.damage ?? 10) / 50); const peak = 0.5 + 0.45 * amount;
if (pulse) pulse.stop(); pulse = Tween.value(peak, 0.5, (value) => vignette.setProps({ darkness: value }), { duration: 0.6, ease: Ease.OutQuad, });
glitch.setProps({ active: true, strength: [0.2, 0.4 + 0.6 * amount] }); if (quiet) quiet(); quiet = delay(() => glitch.setProps({ active: false }), 400); });}On player/hurt, the camera's Vignette darkens sharply and eases back with a tween, while its Glitch effect tears the image for 400 ms.
Press Hurt to flash the screen. Drag to orbit the camera, scroll to zoom.
- Bigger hits darken the edges more:
amountmaps the damage to 0..1, andpeaksits between the resting0.5and0.95. - The vignette jumps to
peakand eases back to0.5. A new hit stops the previous pulse first, so two tweens never fight overdarkness. - Glitch is switched with its
activeprop instead ofsetEnabled. The effect stays in the chain, so turning it on costs no rebuild. delay(..., 400)quiets the glitch after 400 ms. The previous delay is cancelled when a new hit arrives, so rapid hits keep it going.
2. A black-and-white flashback with slow motion
Section titled “2. A black-and-white flashback with slow motion”A flashback cuts to another camera whose look is Sepia, Noise and Vignette, and slows the game down. After eight seconds of real time it cuts back.
#pragma lifecycle(startup)
let busy = false;
function startup() { on('story/flashback', async () => { if (busy) return; busy = true;
CameraDirector.switchTo('Flashback Cam'); Time.scale = 0.5;
const start = Time.now(); while (Time.since(start) < 8000) { await new Promise((done) => delay(done, 100)); }
Time.scale = 1; CameraDirector.switchToMain(); busy = false; });}A flashback cuts to a camera with Sepia, Noise and Vignette effects and halves the game speed; after eight seconds of real time it cuts back to the main camera.
Press Flashback: for eight seconds the scene turns sepia and the orbiting ball slows down. Drag to orbit the camera, scroll to zoom.
- The
Flashback Camcamera entity carries its own effects, set up in the editor.CameraDirector.switchTocuts to it, and its effects show from the same frame. Time.scale = 0.5runs the game at half speed.delaycounts game time, so the loop measures real time withTime.now()andTime.since()to keep the flashback eight real seconds long.CameraDirector.switchToMain()cuts back to the main camera and its own look.- The
busyflag ignores a second flashback while one is playing.
3. Cycle colour grades
Section titled “3. Cycle colour grades”Four colour effects on one camera make five looks. Each press of Space changes their props to the next look.
#pragma lifecycle(startup, update)
const LOOKS = [ { name: 'Natural', hue: 0, saturation: 0, sepia: 0, grey: 0, darkness: 0.3 }, { name: 'Vivid', hue: 0, saturation: 0.6, sepia: 0, grey: 0, darkness: 0.4 }, { name: 'Old photo', hue: 0, saturation: -0.3, sepia: 0.9, grey: 0, darkness: 0.7 }, { name: 'Noir', hue: 0, saturation: 0, sepia: 0, grey: 1, darkness: 0.85 }, { name: 'Alien', hue: 120, saturation: 0.3, sepia: 0, grey: 0, darkness: 0.5 },];let index = 0;let hueSaturation;let sepia;let grayscale;let vignette;
function apply(look) { hueSaturation.setProps({ hue: look.hue, saturation: look.saturation }); sepia.setProps({ intensity: look.sepia }); grayscale.setProps({ intensity: look.grey }); vignette.setProps({ darkness: look.darkness }); log('Look:', look.name);}
function startup() { const eye = findEntity('Main Camera'); hueSaturation = eye.getComponent(HueSaturationEffectComponent); sepia = eye.getComponent(SepiaEffectComponent); grayscale = eye.getComponent(GrayscaleEffectComponent); vignette = eye.getComponent(VignetteEffectComponent); apply(LOOKS[index]);}
function update() { if (!Input.keyboard.isKeyReleased(Key.Space)) return; index = (index + 1) % LOOKS.length; apply(LOOKS[index]);}Pressing Space steps the camera through five looks, from natural to old photo and noir, by changing the props of its Hue/Saturation, Sepia, Grayscale and Vignette effects.
Click the scene, then press Space to switch to the next look. Drag to orbit the camera, scroll to zoom.
- All four effects stay on the camera; a look only changes their props, so switching costs no rebuild.
- An
intensityof0leaves Sepia and Grayscale with no visible effect, and asaturationof0leaves colours unchanged. - Each look is plain data, so adding one is a single line in
LOOKS.