Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

355
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda