Threejs Add DirectionalLight to cast shadow to planets that are orbiting arround the sun

Im using DirectionalLight to cast shadow to 9 planets arround the sun. The light comes from sun at (0,0,0). and there are planets orbiting arround the sun. The problem is the shadow casted by the DirectionalLight are fixed and I need this shadow follows each planet to cast the shadow at right position. Any suggestions pls. thx in advance @prisoner849 You helped me a lot. if you had any tips. thxxx

If I understood correctly what you want to achieve.
In conception of a star system, when you’ve got several planest and a sun, as a light source, makes sense to use PointLight instead of DirectionalLight.

1 Like

You are totally right. Ive tried to use PointLight but Im scalling a lot the planets (mesh.scale.set(…)) and the light gets positioned at center (0,0,0) and does not cast the light to the whole scenario. Theres a way to scale the light because If I increase a lot the intensity, everything receives so much light and gets white.

Instantiate a point light with just two parameters (color and intensity), omitting the third one (distance), thus it means that the light woun’t have limit on distance.

Read the docs :slight_smile:
distance - Maximum range of the light. Default is 0 (no limit).

yep. I did it already but I had scaled a lot the planets and I need to set a huge intensity value to cast light to the whole scenario and this affects the planets that are near at the sun. they get too white.

I tried a lot of settings and this one worked like a charm to me :

var light2;
    light2 = new THREE.PointLight(color, intensity, distance, decay);
    //move light = "SUNLIGHT";
    light2.distance = distance;
    light2.decay = decay;
    // light2.position.set(lightPositionX, lightPositionY, lightPositionZ);
    light2.castShadow = castShadow; // default false
    light2.visible = true;
    light2.shadow.bias = 0.0001;
    light2.shadow.mapSize.width = 4096; // default
    light2.shadow.mapSize.height = 4096; // default
    light2.shadow.darkness = 0.1; = 1000000; = 3e9; // default
    // light2.color.setHSL(0.5, 0.7, 0.8);

    // and rotation shows the shadow.
    // = -270;
    light2.rotation.set(0, Math.PI, 0);

I disabled the Decay as well and insert shiness on mesh attribute.