《Unity着色器圣经》8.0.1 | 阴影映射

目录索引

译文

阴影映射(Shadow Mapping)是一种允许我们在场景中生成阴影贴图的技术,它的概念非常简单:光影区域是由我们使用的光源产生的,也就是说,如果光源对应的是平行光,那么阴影的投影将是正交投影;如果光源对应的是点光源,那么阴影的投影将是透视投影。

计算方法是比较一个像素从光源处看是否可见,或者光源是否为投影点。

图片[1]-《Unity着色器圣经》8.0.1 | 阴影映射-软件开发学习笔记
Fig. 8.0.1a

当我们在场景中创建一个光源时,根据光源的视角(viewpoint),整个可见区域为照明区,而照明区以外的整个区域为阴影区。依照这个逻辑,我们可以认为这相当于一个比较操作,但这个过程是如何进行的呢?

在开始了解之前,我们需要先熟悉两个概念:阴影投射(shadow caster)阴影贴图(shadow map)

阴影投射代表阴影投影的区域,阴影贴图代表投射在物体上的阴影。

图片[2]-《Unity着色器圣经》8.0.1 | 阴影映射-软件开发学习笔记
Fig. 8.0.1b

阴影贴图是一种纹理,因此它具有 UV 坐标,并分两个阶段进行计算: 第一步,根据光源视角渲染场景。在这个过程中,深度信息会从 Z 缓冲区中提取出来,然后作为纹理保存在内存中。第二步,根据相机视角以常规方式在 GPU 上绘制场景。在这一阶段,我们必须计算内存中保存的纹理的 UV 坐标,以生成阴影贴图并应用到模型上。


原文对照

Shadow mapping is a technique that allows us to generate shadow maps in a scene. Its concept is quite simple: the area of light and shadow is generated concerning the frustum of illumination that we are using, that is, if the light source corresponds to a directional light, the projection of the shadow will be orthographic, while if the source corresponds to a point light, then the projection will be rendered in perspective.

This calculation is done by comparing whether a pixel is visible from the light source or as if the source were the projection point.

图片[1]-《Unity着色器圣经》8.0.1 | 阴影映射-软件开发学习笔记
Fig. 8.0.1a

When we create a light source in our scene, the entire visible area, according to the light source viewpoint, will be the illuminated area, and the entire area outside it will be the shadow zone. According to this logic, we can determine that this corresponds to a comparison operation, but how does this process work?

To do this, we must review two concepts: shadow caster and shadow map.

The shadow caster corresponds to the shadow projection area, while the shadow map corresponds to the shadow cast on an object.

图片[2]-《Unity着色器圣经》8.0.1 | 阴影映射-软件开发学习笔记
Fig. 8.0.1b

The shadow map is a texture; therefore it has UV coordinates and is calculated in two stages: First, the scene is rendered according to the light source viewpoint. During the process, the depth information is extracted from the Z-Buffer and then saved as a texture in the internal memory. In the second, the scene is drawn on the GPU in the usual way according to the camera viewpoint. In this stage, we must calculate the UV coordinates of the texture saved in memory to generate and apply the shadow map to the object.

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容