Extensible 3D (X3D)
Part 1: Architecture and base components

17 Lighting component

--- X3D separator bar ---

cube 17.1 Introduction

17.1.1 Name

The name of this component is "Lighting". This name shall be used when referring to this component in the COMPONENT statement (see 7.2.5.4 Component statement).

17.1.2 Overview

This clause describes the Lighting component of this part of ISO/IEC 19775. This includes how light sources are defined and positioned as well as how lights effect the rendered image. Table 17.1 provides links to the major topics in this clause.

Table 17.1 — Topics

cube 17.2 概念

17.2.1 光源语义

17.2.1.1 概述

所有影响某个 Shape 节点的灯光的和将照亮这个 Shape 节点。这其中将包括光源发出的直射光和环境光的成分。环境照明是由光源直接发出的光在环境中经过散射和反射而的结果。环境光的亮和场景中的单个光相关。大体上这近似于自然中发生的环境反射。

任何作为光照源的节点将由 X3DLightNode 衍生。所有的光源包含 intensity(亮度)、color(颜色)、ambientIntensity(环境亮度)域。intensity 域指定了由灯光直接发射出的亮度,ambientIntensity 域指定了灯光向环境散射出的亮度。灯光亮度可以在范围 0.0(无光线发射)到 1.0(完全亮度)。color 域为直射光和环境光指定了 RGB 值的光谱色。on 域指定了灯光是否被激活。如果值为 FALSE,那么灯光将被禁止并不再影响场景中的节点。如果值为 TRUE,灯光将按 17.2.1.2 灯光的适用范围 影响场景图中的其它节点。

以下是作为光源节点的节点类型:

PointLight 和 SpotLight 照亮所有属于其光照影响容积的对象,而不管这些对象在变换层级中的位置。PointLight 定义此影响容积为一个中心位于灯光位置的球(由一个半径定义)。SpotLight 定义此影响容积为一个由半径和截止角定义的立体角。DirectionalLight 节点只照亮由此灯光父组节点继承的对象,这包括任何与此 DirectionalLight 处在同一层级的以及更低层级的子。

17.2.1.2 灯光的适用范围

某些灯光类型,例如 DirectionalLight,只照亮和其处于相同变换层级的对象。这允许被用来创建现实效果,比如一个只照亮一个房间的灯。

17.2.2 光照模型

17.2.2.1 介绍

X3D 光照模型提供了详细的方程以定义灯光的颜色将如何应用到几何物体上。每一个物体的当前应用的 Material 节点的值、Color 节点的值、纹理将和照明此物体的灯光以及当前绑定的 Fog 节点相结合。这些方程被设计用来模拟光线照射到表面上的物理特性。

17.2.2.2 光照 '关闭'

如果以下任何条件为 true,此 Shape 节点将不接受光照:

  1. 形的 appearance 域为 NULL(空 - 缺省值)
  2. Appearance 节点的 material 域为 NULL(空 - 缺省值)

注意特殊情况的几何节点也不支持光照(细节见 11.4.4 IndexedLineSet11.4.10 PointSet

如果此形不接受光照,此形几何体上的每个点的 colour (Irgb) 和 alpha (A, 1−transparency) 按 表 17.2 给定。

Table 17.2 — Unlit colour and alpha mapping

Texture type Colour per-vertex
or per-face
Colour NULL
No texture Irgb= ICrgb
A = 1
Irgb= (1, 1, 1)
A = 1
Intensity
(one-component)
Irgb= IT × ICrgb
A = 1
Irgb = (IT,IT,IT )
A = 1
Intensity+Alpha
(two-component)
Irgb= I T × ICrgb
A = AT
Irgb= (IT,IT,IT )
A = AT
RGB
(three-component)
Irgb= ITrgb
A = 1
Irgb= ITrgb
A = 1
RGBA
(four-component)
Irgb= ITrgb
A = AT
Irgb= ITrgb A = AT

其中:

AT = normalized [0, 1] alpha value from 2 or 4 component texture image
ICrgb = interpolated per-vertex colour, or per-face colour, from Color node
IT = normalized [0, 1] intensity from 1 or 2 component texture image
ITrgb= colour from 3-4 component texture image

17.2.2.3 光照 '打开'

If the shape is lit (i.e., a Material and an Appearance node are specified for the Shape), the Material and Texture nodes determine the diffuse colour for the lighting equation as specified in Table 17.3.

The Material's diffuseColor field modulates the color in the texture. Hence, a diffuseColor of white will result in the pure color of the texture, while a diffuseColor of black will result in a black diffuse factor regardless of the texture.

The Material's transparency field modulates the alpha in the texture. Hence, a transparency of 0 will result in an alpha equal to that of the texture. A transparency of 1 will result in an alpha of 0 regardless of the value in the texture.

Table 17.3 — Lit colour and alpha mapping

Texture type Colour per-vertex
     or per-face
Color node NULL
No texture ODrgb = ICrgb
A = 1-TM
ODrgb = IDrgb
A = 1-TM
Intensity texture
(one-component)
ODrgb = IT × ICrgb
A = 1-TM
ODrgb = IT × IDrgb
A = 1-TM
Intensity+Alpha texture
(two-component)
ODrgb = IT × ICrgb
A = AT
ODrgb = IT × IDrgb
A = AT
RGB texture
(three-component)
ODrgb = ITrgb
A = 1-TM
ODrgb = ITrgb
A = 1-TM
RGBA texture
(four-component)
ODrgb = ITrgb
A = AT
ODrgb = ITrgb
A = AT

where:

IDrgb = material diffuseColor
ODrgb = diffuse factor, used in lighting equations below
TM = material transparency

All other terms are as defined in 17.2.2.2 Lighting off.

17.2.2.4 光照方程

An ideal X3D implementation will evaluate the following lighting equation at each point on a lit surface. RGB intensities at each point on a geometry (Irgb) are given by:

Irgb = IFrgb × (1 -f0) + f0 × (OE rgb + SUM( oni × attenuationi × spoti × ILrgb
                                                 × (ambienti + diffusei + specular i)))

where:

attenuationi = 1 / max(c1 + c2 × dL + c3 × dL² , 1 )
ambienti = Iia × ODrgb × Oa

diffusei = Ii × ODrgb × ( N · L )
specular i = Ii × OSrgb × ( N · ((L + V) / |L + V|))shininess × 128

and:

· = modified vector dot product: if dot product < 0, then 0.0, otherwise, dot product
c1 , c2, c 3 = light i attenuation
dV = distance from point on geometry to viewer's position, in coordinate system of current fog node
dL = distance from light to point on geometry, in light's coordinate system
f0 = Fog interpolant, see Table 17.5 for calculation
IFrgb = currently bound fog's color
I Lrgb = light i color
Ii = light i intensity
Iia = light i ambientIntensity
L = (Point/SpotLight) normalized vector from point on geometry to light source i position
L = (DirectionalLight) -direction of light source i
N = normalized normal vector at this point on geometry (interpolated from vertex normals specified in Normal node or calculated by browser)
Oa = Material ambientIntensity
ODrgb = diffuse colour, from Material node, Color node, and/or texture node
OErgb = Material emissiveColor
OSrgb = Material specularColor
on i = 1, if light source i affects this point on the geometry,
0, if light source i does not affect this geometry (if farther away than radius for PointLight or SpotLight, outside of enclosing Group/Transform for DirectionalLights, or on field is FALSE)
shininess = Material shininess
spotAngle = acos( -L · spotDiri)
spot BW = SpotLight i beamWidth
spot CO = SpotLight i cutOffAngle
spot i = spotlight factor, see Table 17.4 for calculation
spotDiri = normalized SpotLight i direction
SUM: sum over all light sources i
V = normalized vector from point on geometry to viewer's position

Table 17.4 — Calculation of the spotlight factor

Condition (in order) spoti =
lighti is PointLight or DirectionalLight 1
spotAngle ≥ spotCO 0
spotAngle ≤ spotBW 1
spotBW  < spotAngle < spot CO (spotAngle - spotCO ) / (spotBW - spotCO)

Table 17.5 — Calculation of the fog interpolant

Condition f0 =
no fog 1
fogType "LINEAR", dV < fogVisibility (fogVisibility-dV) / fogVisibility
fogType "LINEAR", dV > fogVisibility 0
fogType "EXPONENTIAL", dV < fogVisibility exp(-dV / (fogVisibility-dV ) )
fogType "EXPONENTIAL", dV > fogVisibility 0

17.2.2.5 参考

X3D 光照方程基于简化的 [FOLEY][OPENGL] 中给定的光照方程.

17.3 抽象类型

17.3.1 X3DLightNode

X3DLightNode : X3DChildNode { 
  SFFloat [in,out] ambientIntensity 0     [0,1]
  SFColor [in,out] color            1 1 1 [0,1]
  SFFloat [in,out] intensity        1     [0,1]
  SFNode  [in,out] metadata         NULL  [X3DMetadataObject]
  SFBool  [in,out] on               TRUE
}

The X3DLightNode abstract node type is the base type from which all node types that serve as light sources are derived. A description of the ambientIntensity, color, intensity, and on fields is in 17.2.1 Light source semantics.

17.4 节点参考

17.4.1 DirectionalLight

DirectionalLight : X3DLightNode {
  SFFloat [in,out] ambientIntensity 0      [0,1]
  SFColor [in,out] color            1 1 1  [0,1]
  SFVec3f [in,out] direction        0 0 -1 (-∞,∞)
  SFFloat [in,out] intensity        1      [0,1]
  SFNode  [in,out] metadata         NULL   [X3DMetadataObject]
  SFBool  [in,out] on               TRUE
}

The DirectionalLight node defines a directional light source that illuminates along rays parallel to a given 3-dimensional vector. A description of the ambientIntensity, color, intensity, and on fields is in 17.2.1 Light source semantics.

The direction field specifies the direction vector of the illumination emanating from the light source in the local coordinate system. Light is emitted along parallel rays from an infinite distance away. A directional light source illuminates only the objects in its enclosing parent group. The light may illuminate everything within this coordinate system, including all children and descendants of its parent group. The accumulated transformations of the parent nodes affect the light.

DirectionalLight nodes do not attenuate with distance. A precise description of X3D's lighting equations is contained in 17.2.2 光照模型

17.4.2 PointLight

PointLight : X3DLightNode {
  SFFloat [in,out] ambientIntensity 0     [0,1]
  SFVec3f [in,out] attenuation      1 0 0 [0,∞)
  SFColor [in,out] color            1 1 1 [0,1]
  SFFloat [in,out] intensity        1     [0,1]
  SFVec3f [in,out] location         0 0 0 (-∞,∞)
  SFNode [in,out]  metadata         NULL  [X3DMetadataObject]
  SFBool  [in,out] on               TRUE
  SFFloat [in,out] radius           100   [0,∞)
}

The PointLight node specifies a point light source at a 3D location in the local coordinate system. A point light source emits light equally in all directions; that is, it is omnidirectional. PointLight nodes are specified in the local coordinate system and are affected by ancestor transformations.

Subclause 17.2.1 Light source semantics, contains a detailed description of the ambientIntensity, color, and intensity fields.

A PointLight node illuminates geometry within radius metres of its location. Both radius and location are affected by ancestors' transformations (scales affect radius and transformations affect location). The radius field shall be greater than or equal to zero.

PointLight node's illumination falls off with distance as specified by three attenuation coefficients. The attenuation factor is:

1/max(attenuation[0] + attenuation[1] × r + attenuation[2] × r2, 1)

where r is the distance from the light to the surface being illuminated. The default is no attenuation. An attenuation value of (0, 0, 0) is identical to (1, 0, 0). Attenuation values shall be greater than or equal to zero. A detailed description of X3D's lighting equations is contained in 17.2.2 Lighting model.

17.4.3 SpotLight

SpotLight : X3DLightNode {
  SFFloat [in,out] ambientIntensity 0        [0,1]
  SFVec3f [in,out] attenuation      1 0 0    [0,∞)
  SFFloat [in,out] beamWidth        π/2      (0,π/2]
  SFColor [in,out] color            1 1 1    [0,1]
  SFFloat [in,out] cutOffAngle      π/4      (0,π/2]
  SFVec3f [in,out] direction        0 0 -1   (-∞,∞)
  SFFloat [in,out] intensity        1        [0,1]
  SFVec3f [in,out] location         0 0 0    (-∞,∞)
  SFNode  [in,out] metadata         NULL     [X3DMetadataObject]
  SFBool  [in,out] on               TRUE
  SFFloat [in,out] radius           100      [0,∞)
}

The SpotLight node defines a light source that emits light from a specific point along a specific direction vector and constrained within a solid angle. Spotlights may illuminate geometry nodes that respond to light sources and intersect the solid angle defined by the SpotLight. Spotlight nodes are specified in the local coordinate system and are affected by ancestors' transformations.

A detailed description of ambientIntensity, color, intensity, and the lighting equations of X3D is provided in 17.2.1 Light source semantics. More information on lighting concepts can be found in 17.2.2 Lighting model, including a detailed description of the X3D lighting equations.

The location field specifies a translation offset of the centre point of the light source from the light's local coordinate system origin. This point is the apex of the solid angle which bounds light emission from the given light source. The direction field specifies the direction vector of the light's central axis defined in the local coordinate system.

The on field specifies whether the light source emits light. If on is TRUE, the light source is emitting light and may illuminate geometry in the scene. If on is FALSE, the light source does not emit light and does not illuminate any geometry.

The radius field specifies the radial extent of the solid angle and the maximum distance from location that may be illuminated by the light source. The light source does not emit light outside this radius. The radius shall be greater than or equal to zero.

Both radius and location are affected by ancestors' transformations (scales affect radius and transformations affect location).

The cutOffAngle field specifies the outer bound of the solid angle. The light source does not emit light outside of this solid angle. The beamWidth field specifies an inner solid angle in which the light source emits light at uniform full intensity. The light source's emission intensity drops off from the inner solid angle (beamWidth) to the outer solid angle (cutOffAngle) as described in the following equations:

    angle = the angle between the Spotlight's direction vector
            and the vector from the Spotlight location to the point
            to be illuminated

    if (angle ≥ cutOffAngle):
        multiplier = 0
    else if (angle ≤ beamWidth):
        multiplier = 1
    else:
        multiplier = (angle - cutOffAngle) / (beamWidth - cutOffAngle)
    intensity(angle) = SpotLight.intensity × multiplier

If the beamWidth is greater than the cutOffAngle, beamWidth is defined to be equal to the cutOffAngle and the light source emits full intensity within the entire solid angle defined by cutOffAngle. Both beamWidth and cutOffAngle shall be greater than 0.0 and less than or equal to π/2. Figure 17.1 depicts the beamWidth, cutOffAngle, direction, location, and radius fields of the SpotLight node.

SpotLight node

Figure 17.1 — SpotLight node

SpotLight illumination falls off with distance as specified by three attenuation coefficients. The attenuation factor is:

1/max(attenuation[0] + attenuation[1] × r + attenuation[2] × r2 , 1)

where r is the distance from the light to the surface being illuminated. The default is no attenuation. An attenuation value of (0, 0, 0) is identical to (1, 0, 0). Attenuation values shall be greater than or equal to zero. A detailed description of X3D's lighting equations is contained in 17.2.2 Lighting model.

cube 17.5 支持级别

The Lighting component provides three levels of support as specified in Table 17.6.

Table 17.6 — Lighting component support levels

Level Prerequisites Nodes/Features Support
1 Core 1
Shape 1
X3DLightNode (abstract) n/a
DirectionalLight Not scoped by parent Group or Transform.
2 Core 1
Shape 1
 
All Level 1 Lighting nodes All fields as supported in Level 1
PointLight radius optionally supported. Linear attenuation.
SpotLight beamWidth optionally supported. radius optionally supported. Linear attenuation.
3 Core 1
Shape 1
All Level 2 Lighting nodes All fields fully supported

--- X3D separator bar ---