灯光

Starter pack

在3D图形中,灯光用于照亮场景中的物体。它们可以用来模拟太阳、灯或者任何其他光源发出的光。

运行起始代码:

没有灯光的场景

如你所见,场景是完全黑暗的。

这是因为我们还没有添加任何灯光,并且使用的材质是 <meshStandardMaterial />

让我们来了解一下 Three.js 中可用的不同类型的灯光

环境光

最简单的灯光类型是环境光。它均匀地照亮场景中的所有物体,无论它们的位置或方向。

intensity 属性定义了灯光的亮度。默认值是 1

<ambientLight intensity={0.5} />

环境光

color 属性定义了灯光的颜色。默认值是 #ffffff(白色):

<ambientLight intensity={0.5} color={"royalblue"} />

环境光

定向光

定向光 是一种距离无限远的光源。

它从特定方向照亮场景中的所有对象。

光的方向由其 positiontarget 属性定义。

由于 target 的默认值是 (0, 0, 0),我们可以仅使用 position 属性来定义光的方向。

<directionalLight position={[3, 3, 3]} intensity={0.5} />

与环境光类似,它具有 colorintensity 属性。

定向光

尝试将立方体切换为白色,并添加多个具有不同颜色的定向光,以查看它们如何与立方体交互:

Three.js logoReact logo

React Three Fiber: The Ultimate Guide to 3D Web Development

✨ You have reached the end of the preview ✨

Go to the next level with Three.js and React Three Fiber!

Get full access to this lesson and the complete course when you enroll:

  • 🔓 Full lesson videos with no limits
  • 💻 Access to the final source code
  • 🎓 Course progress tracking & completion
  • 💬 Invite to our private Discord community
Unlock the Full Course – Just $85

One-time payment. Lifetime updates included.