ThreeJS 之 DirectionalLight

19 阅读1分钟

向特定方向发射的光。DirectionalLight 的行为就好像它是无限远的,从它产生的光线都是平行的。这种情况的常见用例是模拟日光;太阳足够远,可以认为它的位置是无限的,并且来自它的所有光线都是平行的。

该灯光可以投射阴影,-有关详细信息,请参阅DirectionalLightShadow页面。

Three.js

const directionalLight = new window.THREE.DirectionalLight(0xffffff, 3);
directionalLight.castShadow = true;
directionalLight.position.set(80, 80, -8);

  // 添加阴影相机设置
directionalLight.shadow.mapSize.set(1024 * 5, 1024 * 5);
directionalLight.shadow.bias = -0.00001;
// directionalLight.shadow.color = new window.THREE.Color(0x000000);
directionalLight.shadow.camera.near = 0.1;
directionalLight.shadow.camera.far = 5000;
directionalLight.shadow.camera.top = 300;
directionalLight.shadow.camera.right = 300;
directionalLight.shadow.camera.left = -300;
directionalLight.shadow.camera.bottom = -300;

R3F

<directionalLight
  castShadow
  position={[80, 80, -8]}
  color={0xffffff}
  intensity={3}
  shadow-mapSize={[1024 * 5, 1024 * 5]}
  shadow-bias={-0.00001}
  shadow-camera-near={0.1}
  shadow-camera-far={5000}
  shadow-camera-top={300}
  shadow-camera-right={300}
  shadow-camera-left={-300}
  shadow-camera-bottom={-300}
/>