Error "scene.enableDepthRenderer is not a function" creating LensRenderingPipeline

Hello, I get “scene.enableDepthRenderer is not a function” when I create the LensRenderingPipeline, without importing the full Babylon namespace.
It look to me strange because I should have imported all the needed classes…
Here’s my code

import { Engine } from "@babylonjs/core/Engines/engine";
import { Scene } from "@babylonjs/core/scene";
import { Vector3 } from "@babylonjs/core/Maths/math";
import { ArcRotateCamera } from "@babylonjs/core/Cameras/arcRotateCamera";
import { SpotLight } from "@babylonjs/core/Lights/spotLight";
import { Mesh } from "@babylonjs/core/Meshes/mesh";
import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder";
import { ShadowGenerator } from "@babylonjs/core/Lights/Shadows/shadowGenerator";
// import * as BABYLON from "@babylonjs/core/Legacy/legacy";
import { LensRenderingPipeline } from "@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/lensRenderingPipeline";
import { Tools } from "@babylonjs/core/Misc/tools"

const createScene = function () {
  var scene = new Scene(engine);
  const camera = new ArcRotateCamera("arcamera", Tools.ToRadians(-90), Tools.ToRadians(45), 10, new Vector3.Zero(), scene);
  camera.attachControl(canvas, true);

  const lensEffect = new LensRenderingPipeline('lens', {
    edge_blur: 1.0,
    dof_focus_distance: 6,
    dof_aperture: 5.0,
  }, scene, 1.0, camera);

  const box = MeshBuilder.CreateBox("box", { width: 1, depth: 1, height: 4 }, scene);
  box.position = new Vector3(0, 2, 0);

  const plane = Mesh.CreateGround("Spotlight Hard Shadows", 24, 60, 1, scene, false);
  plane.receiveShadows = true;

  const light = new SpotLight("SpotLight", new Vector3(-5, 5.16, -5.1), new Vector3(1, -1, 1), 1.2, 24, scene);
  const shadowGenerator = new ShadowGenerator(1024, light);
  shadowGenerator.getShadowMap().renderList.push(box);

  return scene;
};

const canvas = document.getElementById("renderCanvas");
const engine = new Engine(canvas);
const scene = createScene();
engine.runRenderLoop(() => {
  scene.render();
});

I’ve found the solution, I need
import { DepthRendererSceneComponent } from “@babylonjs/core/Rendering/depthRendererSceneComponent”;

…but… why?

The lens rendering pipeline is using the depth renderer internally to do its job, so you need to import it.

Yes, but it’s not documented.
I think that at least a specific error message in the console would be nice…
My personal opinion is that actually using ES6 classes is a bit a pane, generally speaking

I ll add the missing dependency by default in the lens pipeline.

@RaananW is working on fixing the ES6 pain points.

2 Likes