capnmidnight/Primrose

Shadow position is not stable.

Closed this issue · 1 comments

If you move around the scene, the shadows of the objects around you move as well, as the light that creates the shadow moves with the user. That light is create on line 45 of the Sky class. The light() function comes from the Live API and is just a short-hand for creating a point-source light.

Change the point light to a directional light.

  • change Line 5 from import light from "../../live-api/light"; to import { DirectionalLight } from "three/src/lights/DirectionalLight";
  • change Line 45 from this.sun = light(0xffffff, 1, 50) to this.sun = new DirectionalLight(0xffffff, 1). Notice that there is no semicolon at the end of the line, because the next line is a method call on the object.
  • change Line 47 from .at(0, 10, 10); to .at(0, 1, 1);.
  • add a line after Line 47 to call this.add(this.sun.target);. Without this line, the shadow will still be user-position-dependent because the light direction is calculated from the World coordinates of the light to the World coordinates of the target.

This was fixed in PR #141.