Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

350
Views
Three.js shadows acting weirdly

I am trying to create a little solar system but found a bug... or a feature. I'd like for all of my planets to be able to cast and receive shadows from all other planets. However, it seems as if it depends on instancing order if shadows are cast or not. Code for the light and shadows:

const sunLight = new THREE.PointLight(0xffffff, 3, 100);
sunLight.position.set(0, 0, 0);
sunLight.castShadow = true
scene.add(sunLight);

//Set up shadow properties for the light
sunLight.shadow.mapSize.width = 512; // default
sunLight.shadow.mapSize.height = 512; // default
sunLight.shadow.camera.near = 0.5; // default
sunLight.shadow.camera.far = 500; // default

const sphereSize = 1;
const pointLightHelper = new THREE.PointLightHelper(sunLight, sphereSize);
scene.add(pointLightHelper);
const shadowHelper = new THREE.CameraHelper( sunLight.shadow.camera );
scene.add( shadowHelper );

Basic code for the code objects:

var earth = new THREE.Mesh(
  new THREE.SphereGeometry(1, 32, 16),
  new THREE.MeshStandardMaterial({
    map: tLoader.load("/textures/nasa-world.jpg"),
    bumpMap: tLoader.load("/textures/nasa-jpl-world-bump.png"),
    bumpScale: 0.01,
  }));
  earth.castShadow = true
  earth.receiveShadow = true
  // position goes here
  scene.add(earth);

var mars = new THREE.Mesh(
  new THREE.SphereGeometry(0.53, 32, 16),
  new THREE.MeshStandardMaterial({
    map: tLoader.load("/textures/nasa-mars.jpg"),
    bumpMap: tLoader.load("/textures/nasa-mars-bump.png"),
    bumpScale: 0.01,
  }))
  mars.castShadow = true
  mars.receiveShadow = true
  //position goes here
  scene.add(mars);

Case 1 (working shadow):

earth.position.x = 18
mars.position.x = 15

(https://ibb.co/gS26Sfz)

Case 2 (not working):

earth.position.x = 15
mars.position.x = 18

(https://ibb.co/PZrh2wS)

Case 3 (not sure why, but it works): When I switch around the instancing (I first instance mars, then earth, Case 2 DOES work). (https://ibb.co/pRz06b1)

It does seem to me that only objects that are instanced BEFORE the objects that drop shadows can actually receive shadows. I cannot imagine, though, that this is truly a limitation, I am probably doing something wrong. Please help me, how can I make both objects cast and receive shadows from one another?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After playing around and reading some more documentation, it seems as if this problem is hard coded. The instancing order does seem to determine what can cast and receive shadows. In other words: the meshes that are to receive the shadow must be instanced before the objects casting the shadows. This is quite a limitation, in some ways.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!