Error trying to apply motion blur

I’m trying to use motion blur in my project, and am just initializing it like so:

const motionBlur = new MotionBlurPostProcess('mb', window.scene, 1.0, this.camera);
motionBlur.isObjectBased = false;

However, I get the following error:

ocess.ts:308  Uncaught TypeError: Cannot read properties of undefined (reading '-1')
    at MotionBlurPostProcess._onApplyScreenBased (motionBlurPostProcess.ts:308:87)
    at Observer.onApply [as callback] (motionBlurPostProcess.ts:259:53)
    at Observable.notifyObservers (observable.ts:332:49)
    at MotionBlurPostProcess.apply (postProcess.ts:854:32)
    at PostProcessManager._finalizeFrame (postProcessManager.ts:203:31)
    at Scene._renderForCamera (scene.ts:3634:37)
    at Scene._processSubCameras (scene.ts:3649:18)
    at Scene.render (scene.ts:3911:18)
    at renderLoop (appStart.ts:105:13)
    at Engine._renderFrame (engine.ts:1279:13)
_onApplyScreenBased @ motionBlu

Any ideas how to resolve this?

I believe you are using tree shaking. How do you import MotionBlurPostProcess?

It’s part of a lot of imports here:

import {
  Nullable,
  Scene,
  Vector3,
  MeshBuilder,
  ArcRotateCamera,
  UniversalCamera,
  InstancedMesh,
  Mesh,
  AbstractMesh,
  Camera,
  Matrix,
  Frustum,
  Plane,
  TransformNode,
  Animation,
  Animatable,
  Observer,
  BezierCurveEase,
  ArcRotateCameraPointersInput,
  DeepImmutable,
  Quaternion,
  MotionBlurPostProcess,
} from '@babylonjs/core';

This configuration works fine for me.
Could you also check if the variable window.scene is valid? Probably it should be this.scene?

Motion blur is using the prepass renderer by default, try adding import "@babylonjs/core/Rendering/prePassRendererSceneComponent" to your imports.

2 Likes