Cycle colour grades
Updated
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.
Cycle colour grades
#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]);}How it works
Section titled “How it works”The script is explained step by step in Cycle colour grades.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
ColourGrades.xrproj