logo

G

  • Tutorials
  • API
  • Examples
  • Plugins
  • Productsantv logo arrow
  • 6.1.26
  • Canvas
    • Introduction
    • Options
    • Built-in objects
    • Coordinate system
    • Scenegraph & Lifecycle
    • Event
    • OffscreenCanvas & Server-side Rendering
    • CustomElementRegistry
    • Frequently Asked Questions
  • Renderer
    • Introduction
    • Canvas Renderer
    • Canvaskit Renderer
    • SVG Renderer
    • WebGL Renderer
    • WebGPU Renderer
    • Custom Renderer
  • Camera
    • Introduction
    • Camera Parameters
    • Camera action
    • Camera animation
  • Event
    • Introduction
    • Event Object
    • Gesture & Drag'n'Drop
    • Frequently Asked Questions
  • Animation
    • Web Animations API
    • Lottie
  • Basic Shapes
    • Basic Concepts
    • DisplayObject
    • Group
    • Text
    • Circle
    • Ellipse
    • Rect
    • Image
    • Line
    • Polygon
    • Polyline
    • Path
    • HTML
  • Style System
    • Introduction
    • CSS Typed OM
    • Inheritance
    • CSS Properties & Values API
    • CSS Layout API
    • Pattern
    • Gradient
  • 3D
    • 材质
    • 几何
    • Mesh
    • 光源
    • 雾
    • 交互
  • Built-in Objects
    • EventTarget
    • Node
    • Element
    • Document
    • MutationObserver
    • Utils
  • GPGPU
    • Introduction
    • Programming Model
    • Kernel API
    • Principles of classical GPGPU implementation
    • webgpu-graph
  • Declarative programming
    • 使用 Web Components
  • Devtools
    • G 开发者工具
    • 内置的渲染统计信息
    • 第三方开发调试工具

光源

Previous
Mesh
Next
雾

Resource

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-Interactive solution
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

材质需要配合光源呈现出某种“立体感”。

日常生活中的光源有很多,太阳、台灯、手电筒。它们需要被抽象成可参数化描述的光源。

例如太阳可以看作是“平行光”,它通过颜色、强度、方向来描述。通常光源是作用于整个场景的,因此在具体使用渲染引擎时,会将它添加到场景 / 画布上,以 G 为例:

import { DirectionalLight } from '@antv/g-plugin-3d';
// 创建一个平行光
const light = new DirectionalLight({
style: {
fill: 'white',
direction: [-1, 0, 1],
},
});
// 加入画布
canvas.appendChild(light);

对于某些光源来说,在世界坐标系下的位置是有意义的,当我们想移动光源时,和其他 2D 图形完全一致:

light.translate();
light.setPosition();

通用属性

我们复用 G 中基础图形的部分样式属性,不同光源也有独有的属性。例如我们可以随时改变一个光源的颜色:

light.style.fill = 'red';

fill

光源颜色

intensity

光照强度,默认为 Math.PI

内置光源

平行光

direction

世界坐标系下的方向,类型为 [number, number, number]。示例

light.style.direction = [-1, 0, 1];

点光源

聚光灯

环境光

严格意义上讲这并不是一种光源,它是一种简单模拟全局光照的手段。当我们想提亮整个场景时,可以使用它。示例

import { AmbientLight } from '@antv/g-plugin-3d';
const ambientLight = new AmbientLight({
style: {
fill: 'white',
},
});
canvas.appendChild(ambientLight);

阴影