Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emit light from an object

Tags:

three.js

I'm making a Three.js scene in which I have stars object and I would like to be able to make them "glow".

By glow I mean make them really emit light not just put a "halo" effect around them.

I tried to put a PointLight object at the same position as the star, this make light emit from the object but as you can see, it doesn't make the object "glow" which make a weird effect. enter image description here

My current code looks like this:

class Marker extends THREE.Object3D {
  constructor() {
    super();
    // load obj model
    const loader = new OBJLoader();
    loader.load(
      "https://supersecretdomain.com/star.obj",
      object => {
        object.traverse(child => {
          if (child instanceof THREE.Mesh) {
            // child.material.map = texture;
            child.material = new THREE.MeshLambertMaterial({
              color: 0xffff00
            });
            child.scale.set(0.01, 0.01, 0.01);
          }
        });
        this.add(object);
      }
    );
    const light = new THREE.PointLight(0xffff00, 0.5, 5);
    this.add(light);
  }
}

Any idea of how to do this ? ;)

like image 631
Théo Champion Avatar asked Sep 11 '25 23:09

Théo Champion


1 Answers

Adding a point light to the star is the correct way to make other objects be affected by its light. To make the star itself shine, you can set the emissive color of the material to something other than black (for best results, you probably want it to be the same color as the light).

like image 70
Jave Avatar answered Sep 14 '25 11:09

Jave