mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
101.91k stars 35.32k forks source link

What is happening to the light? #27910

Closed MMMMMoris closed 6 months ago

MMMMMoris commented 6 months ago

Description

I have the same set of code running with different versions of three.js. Here is the output running with r146 version: image

Here is the output running with r162, latest version: image

You can obviously find out that the color rendered by latest three.js is much more dimmer, why is that? Were there any reconstructions to the light usage or light effects during previous iterations?

Reproduction steps

  1. Just switch between r146 and latest version of three.js in npm and observe the differences

Code

Just the part of the code which refers to the light

// code goes here
import anime from "animejs";
import * as THREE from "three";
class Planet {
  protected light: THREE.Light;
  protected camera: THREE.Camera;

  protected createSphere() {
    const segments = 64;
    const planet = this.planetConfig;

    this.sphereInstance = new THREE.Mesh(
      new THREE.SphereGeometry(1, segments, segments),
    );

    this.rootScene.add(this.sphereInstance);
  }
  protected runAnimationFrame: () => void;
  public init() {
    const el = this.planetContainerEl.value;
    this.renderer = new THREE.WebGLRenderer({ alpha: true });

    const scene = (this.rootScene = new THREE.Scene());

    this.createSphere();

    const cameraPosition = Planet.position.center;
    const camera = (this.camera = new THREE.PerspectiveCamera( 50, width / height));
    camera.position.set(
      0,
      cameraPosition.cameraPositionY,
      cameraPosition.cameraPositionZ + 0.1
    );

    const light = (this.light = new THREE.DirectionalLight(0xffffff, 1));
    light.position.set(-1, 1, -2);
    scene.add(light);

    this.runAnimationFrame();

    const fadeInDuration = 800,
      fadeInEasing: anime.EasingOptions = "linear";
    this.fadeInPlanetAnime = anime({
      x: -1,
      y: 1,
      z: 3,
      easing: fadeInEasing,
      targets: light.position,
      duration: fadeInDuration,
    });
  }
}

Live example

Screenshots

Here is the output running with r146 version: image

Here is the output running with r162, latest version: image

Version

r146 and r162

Device

Desktop

Browser

Chrome

OS

Windows

Mugen87 commented 6 months ago

You can find information about the latest major changes in the engine in the following guides:

https://discourse.threejs.org/t/updates-to-color-management-in-three-js-r152/50791 https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733/42

If you need help during the upgrade, please ask for help at the forum.