BasicMultiChannelPerlin

Smooth, continuous camera shake.

Smooth, random shake on each position and rotation axis, relative to the camera: X is left/right, Y is up/down, Z is forward/back. Nothing shakes until you set an amplitude.

Settings

SettingDescriptionDefault
positionAmplitudeHow far the camera moves on each axis.[0, 0, 0]
positionFrequencyHow fast the position shakes on each axis.[1, 1, 1]
rotationAmplitudeHow far the camera turns on each axis, in degrees.[0, 0, 0]
rotationFrequencyHow fast the rotation shakes on each axis.[1, 1, 1]
amplitudeGainMultiplies all amplitudes. Set to 0 to turn the shake off.1
frequencyGainMultiplies all frequencies.1
amplitudeDampingSeconds to fade to a new amplitudeGain, instead of switching instantly.0
seedSame seed, same shake. Read once on creation.random

Fading in and out

Change amplitudeGain with amplitudeDamping set, and the shake fades smoothly instead of starting or stopping abruptly.

Layering

For a slow sway plus a fast jitter, add two of them with different settings.

Usage

import { BasicMultiChannelPerlinNoise } from '@pmndrs/klipp';

const shake = new BasicMultiChannelPerlinNoise({
  positionAmplitude: [0.05, 0.05, 0],
  rotationAmplitude: [0.3, 0.3, 0],
  frequencyGain: 2,
});
camera.addNoise(shake);

Fading in and out

shake.amplitudeDamping = 0.5;
shake.amplitudeGain = engineRunning ? 1 : 0;

Layering

camera.addNoise(new BasicMultiChannelPerlinNoise({ rotationAmplitude: [1, 1, 0], frequencyGain: 0.3 }));
camera.addNoise(new BasicMultiChannelPerlinNoise({ positionAmplitude: [0.02, 0.02, 0], frequencyGain: 8 }));