3D1 Light and Dark | 3D1 光与影

📚 3D1 Light and Dark | 3D1 光与影

In computer graphics and advanced geometry, simulating how light interacts with surfaces relies heavily on vector algebra and linear transformations. The module ‘3D1 Light and Dark’ delves into the mathematical frameworks behind realistic rendering – from the simple dot product that governs diffuse shading to the matrix projections that cast crisp shadows. By mastering these concepts, you will see how pure mathematics turns a blank 3D model into a vividly lit scene.

在计算机图形学与进阶几何中,模拟光线与表面的交互高度依赖向量代数与线性变换。“3D1 光与影”这一单元将深入探讨真实感渲染背后的数学框架——从控制漫反射着色的简单点积,到投射清晰阴影的矩阵投影。掌握这些概念后,你将看到纯粹的数学如何将空白的 3D 模型变成光照生动的场景。

1. Representing Objects and Lights in 3D Space | 三维空间中的物体与光源表示

Every point, light source, and surface normal in a 3D scene is defined by vectors in ℝ³. A point P is given by coordinates (x, y, z), while a directional light is described by a normalised vector L pointing towards the light source. For a point light, we also store its position Pₗ. Surface orientation is captured by an outward-pointing unit normal vector N. These vectors are the building blocks of all lighting calculations.

三维场景中的每一个点、光源以及表面法线都由 ℝ³ 中的向量定义。点 P 由坐标 (x, y, z) 给出,而方向光则用指向光源的归一化向量 L 描述。对于点光源,我们还需要存储它的位置 Pₗ。表面朝向则用一个向外的单位法向量 N 表示。这些向量是所有光照计算的基本构件。


2. The Dot Product: Foundation of Diffuse Shading | 点积:漫反射着色的基础

Lambert’s cosine law states that the brightness of a matte surface depends on the angle between the light direction L and the surface normal N. The diffuse intensity is proportional to the dot product N·L. If the dot product is negative, the surface faces away from the light and receives no illumination. Thus, the diffuse contribution is max(N·L, 0). Mathematically, the diffuse colour at a point is Id = kd × Clight × Csurface × max(N·L, 0), where kd is the diffuse reflectivity coefficient.

朗伯余弦定律指出,粗糙表面的亮度取决于光线方向 L 与表面法线 N 之间的夹角。漫反射强度与点积 N·L 成正比。若点积为负,则表面背向光源,不受光照。因此,漫反射贡献为 max(N·L, 0)。数学上,某点的漫反射颜色可写作 Id = kd × Clight × Csurface × max(N·L, 0),其中 kd 为漫反射系数。


3. Normal Vectors and Surface Orientation | 法向量与表面朝向

Normals are crucial for correct shading. For a triangular facet with vertices A, B, C in counter‑clockwise order, the unnormalised normal is obtained via the cross product: N = (BA) × (CA). Normalisation then yields the unit normal = N / |N|. In smooth shading, vertex normals are often averaged from adjacent face normals to give the illusion of curvature.

法向量对正确的着色至关重要。对于按逆时针顺序排列的三角形面片 A, B, C,未归一化的法向量可通过叉积得到:N = (BA) × (CA)。然后进行归一化得到单位法线 = N / |N|。在平滑着色中,顶点法线通常由相邻面法线平均求得,以呈现曲面的视觉效果。


4. Light Attenuation and Distance | 光线衰减与距离

Point lights and spotlights lose intensity over distance. A common attenuation model uses a quadratic fall‑off: intensity factor = 1 / (a + b d + c d²), where d is the distance from the surface point to the light, and a, b, c are constant, linear, and quadratic attenuation coefficients. Without attenuation, objects would appear equally bright regardless of their distance, ruining the sense of depth.

点光源和聚光灯光源会随距离衰减。常用的衰减模型采用二次下降:强度因子 = 1 / (a + b d + c d²),其中 d 为表面上一点到光源的距离,a、b、c 分别为常数、线性和二次衰减系数。若没有衰减,无论距离远近物体看上去都会同样亮,从而破坏深度感。


5. Specular Reflection and the Reflection Vector | 镜面反射与反射向量

Specular highlights are produced by mirror‑like reflections. Given an incident light direction L and normal N, the perfect specular reflection direction R is given by the vector formula R = 2 (N·L) NL. The specular intensity for a viewer direction V depends on ( R·V )n, where the exponent n (shininess) controls the highlight size. Higher n gives a tighter, sharper highlight.

镜面高光由类镜面反射产生。已知入射光方向 L 和法线 N,理想的镜面反射方向 R 由向量公式 R = 2 (N·L) NL 给出。对于视线方向 V,镜面反射强度取决于 ( R·V )n,其中指数 n(光泽度)控制高光尺寸。n 值越大,高光越集中、越锐利。


6. The Phong Illumination Model | Phong 光照模型

Phong’s model combines ambient, diffuse, and specular components. For multiple light sources, the total colour at a point is the sum of each light’s contribution. The per‑light contribution is:

I = kₐCₐ + kdCd max(N·L, 0) + ksCs max(R·V, 0)α

where kₐ, kd, ks are ambient, diffuse, and specular coefficients, C are colors, and α is the shininess. This model is simple, fast, and forms the basis of many real‑time shaders.

Phong 模型结合了环境光、漫反射和镜面反射分量。对于多个光源,某一点的总颜色是每个光源贡献的总和。每个光源的贡献为:

I = kₐCₐ + kdCd max(N·L, 0) + ksCs max(R·V, 0)α

其中 kₐ、kd、ks 分别为环境光、漫反射和镜面反射系数,C 表示颜色,α 为光泽度。该模型简单、快速,构成了许多实时着色器的基础。


7. Ambient Light and Global Illumination Approximations | 环境光与全局光照近似

Ambient light crudely simulates indirect illumination bouncing from all directions. It is a constant term kₐCₐ added uniformly to all surfaces, preventing unlit areas from becoming pitch black. More realistic ambient occlusion techniques darken crevices using the fraction of the hemisphere above a point that is blocked by nearby geometry, often computed by integrating a visibility function over the hemisphere.

环境光粗略地模拟了来自各个方向的间接照明。它是一个常数项 kₐCₐ,均匀地添加到所有表面上,以防未受光区域变得漆黑一片。更真实的环境光遮蔽技术通过计算某点上半球面被邻近几何体遮挡的比例来压暗缝隙,这一比例通常通过半球面上的可见性函数积分得到。


8. Casting Shadows: Ray‑Triangle Intersection | 投射阴影:光线与三角形求交

Determining if a point is in shadow involves casting a ray from the point towards the light and testing for intersection with scene geometry. A robust method uses barycentric coordinates for triangles. Given a ray P + t D and a triangle with vertices V₀, V₁, V₂, solve P + t D = (1 – u – v) V₀ + u V₁ + v V₂. Using Cramer’s rule yields t, u, v. The point is occluded if t > 0 and u ≥ 0, v ≥ 0, u + v ≤ 1.

判断一个点是否处于阴影中,需要从该点向光源投射光线,并检测与场景几何体是否相交。一种稳健的方法是利用三角形的重心坐标。给定光线 P + t D 和顶点为 V₀, V₁, V₂ 的三角形,解方程 P + t D = (1 – u – v) V₀ + u V₁ + v V₂。使用克莱姆法则可求出 t, u, v。当 t > 0 且 u ≥ 0, v ≥ 0, u + v ≤ 1 时,该点被遮挡。


9. Shadow Mapping: Depth Buffers and Projection | 阴影贴图:深度缓冲与投影

Shadow mapping is a two‑pass technique. First, the scene is rendered from the light’s viewpoint into a depth texture. Then, during the main render, each visible point’s position is transformed into the light’s clip space using a projection matrix. If the point’s depth in light space is greater than the depth stored in the shadow map, it lies in shadow. The projection from world to light clip space is a composition of view and projection matrices: M = Pₗ × Vₗ.

阴影贴图是一种两趟技术。首先,从光源的视角将场景渲染到一张深度纹理中。然后,在主渲染过程中,将每个可见点的位置利用投影矩阵变换到光源的裁剪空间。若该点在光源空间中的深度大于阴影贴图中存储的深度,则该点处于阴影中。由世界空间到光源裁剪空间的投影是视图矩阵与投影矩阵的复合:M = Pₗ × Vₗ


10. Putting It All Together: A Simple Shader | 综合示例:一个简单的着色器

A typical pixel shader loop sums the lighting contributions. For each light, it first tests if the pixel is in shadow using a shadow map lookup; if not, it computes the diffuse and specular terms. The ambient term is added once. The fragment colour is the sum. This mathematical pipeline transforms abstract vectors into visually rich images, demonstrating the power of linear algebra and analytic geometry in computer graphics.

典型的像素着色器循环会累加各个光源的贡献。对于每一光源,它首先通过查寻阴影贴图来检测该像素是否处于阴影中;若不处于阴影中,则计算漫反射和镜面反射项。环境光项只添加一次。片元颜色即为这些项的总和。这条数学管线将抽象的向量转化为视觉丰富的图像,充分展示了线性代数与解析几何在计算机图形学中的威力。


11. Advanced Topics and Real‑World Applications | 进阶主题与实际应用

Beyond Phong, physically based rendering (PBR) employs microfacet models with the bidirectional reflectance distribution function (BRDF), adhering to energy conservation. These models often involve the half‑vector H = (L + V) / |L + V| and the Fresnel equations. The mathematics you learn here – vectors, matrices, calculus – directly underpins the rendering engines used in films, games, and virtual reality.

在 Phong 模型之外,基于物理的渲染(PBR)采用微表面模型和双向反射分布函数(BRDF),并遵守能量守恒。这些模型常涉及半向量 H = (L + V) / |L + V| 以及菲涅耳方程。你在此所学的向量、矩阵和微积分知识,直接支撑着电影、游戏和虚拟现实中所使用的渲染引擎。


Published by TutorHao | Further Mathematics Revision Series | aleveler.com

更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading