Directional Shadow Details 平行光阴影细节

转载 2015年07月08日 11:19:55

This page explains shadows from Directional lights in detail.

此页面详细介绍了平行光阴影。

Directional lights are mostly used as a key light - sunlight or moonlight - in an outdoor game. Viewing distances can be huge, especially in first and third person games, and shadows often require some tuning to get the best quality vs. performance balance for your situation.

平行光大多数作为关键灯光 - 阳光或月光 - 在室外的游戏。观看距离可以是巨大的,尤其是在第一和第三人称游戏,阴影往往需要一些调整,以获得最佳的品质与性能,根据具体情况来权衡。

Let's start out with a good looking shadow setup for a 3rd person game:

对于第三人称游戏,我们首先设置看起来漂亮的阴影。


Shadows here look pretty good! 这里的阴影看起来还不错!

Here, visible distance is about 50 game units, so Shadow Distance was set to 50 in Quality Settings. Also, Shadow Cascades was set to 4, Shadow Resolution to High, and the light uses Soft Shadows.

在这里,可视距离大约是50游戏单位,阴影距离可以在质量设置中设置。阴影级联设置为4,阴影分辨率设置为高,并灯光使用软阴影。

Chapters below dissect each aspect of directional light shadows:

下面的章节仔细研究平行光阴影的各个方面:

Hard versus Soft shadows 硬阴影和软阴影

Using the same light setup, if we switch Shadow Type to Hard Shadows, then the transition from lit to shadowed regions is "hard" - either something is 100% in shadow, or 100% lit. Hard shadows are faster to render but often they look less realistic.

使用同样的灯光设置,我们切换阴影类型为硬阴影,这时阴影边缘很硬,没有过渡效果。硬阴影渲染很快,但通常看起来不真实。


Hard shadows with distance of 50 and four cascades.带有阴影距离为50和阴影级联为4的硬阴影

Shadow Cascade count 阴影级联数

For Directional lights Unity can use so called Cascaded Shadow Maps (alternatively called "Parallel Split Shadow Maps") which give very good shadow quality, especially for long viewing distances. Cascaded shadows work by dividing viewing area into progressively larger portions and using the same size shadow map on each. The result is that objects close to the viewer get more shadow map pixels than objects far away.

对于平行光,Unity可以使用级联阴影贴图(或成为平行分割阴影贴图)有很好的阴影质量,特别是远距离观看。级联阴影通过分割可视区域逐步部分变大,并使用相同的大小,在每个阴影贴图。结果是物体接近观看者将比更远的物体获得更多的阴影贴图像素。

In the images below we'll use Hard shadows because shadow pixels are better visible there.

在下面的图中,我们将使用硬阴影,因为阴影像素更好看见。

If no cascaded shadow maps were used, the entire shadow distance (still 50 units in our case) must be covered by the shadow texture uniformly. Hard shadows would look like this with no cascades:

如果不使用级联阴影,整个阴影距离(仍然是50单位)内,阴影纹理均匀的覆盖。没有级联,硬阴影看起来像这样:


Hard shadows with distance of 50 and no cascades.没有级联,带有50单位距离的硬阴影

The pixels of the shadow texture are the same size everywhere, and while they look good in distance, the quality is not stellar up close. The shadow texture covers the entire viewing area, and if visualized it would look like this:

阴影纹理的像素距离内各个地方都是同样大小,质量也不是越近物体就越高。阴影纹理覆盖整个可视区域,如果可视化阴影看起来像这个样子:


With no cascades, shadow texture covers viewing area uniformly.不带级联,阴影纹理覆盖均匀覆盖可视区域。

When two shadow cascades are used, the entire shadow distance is divided into a smaller chunk near the viewer and a larger chunk far away. Hard shadows would look like this with two cascades:

当使用2个阴影级联时,整个阴影距离内,被分为两块,靠近观察者较小的块和远处较大的块。有2个级联的硬阴影看起来像这样:

级联阴影
Hard shadows with distance of 50 and two cascades.带有50距离和2个级联的硬阴影

In exchange for some performance, we get better shadow resolution up close.

牺牲一点点性能,我们获得近处更好的阴影分辨率。

级联阴影
With two cascades, two shadow textures cover different sized portions of viewing area.

带有2个级联,2个阴影贴图覆盖可视区域的不同大小的部分。

And finally when four shadow cascades are used, the shadow distance is divided into four progressively larger portions. Hard shadows would look like this with four cascades:

最后我们使用4个阴影级联,在阴影距离内,被分割为4个逐步变大的部分。有4个级联的硬阴影看起来像这样:

级联阴影
Hard shadows with distance of 50 and four cascades. Hey, we've seen this already!

带有50距离和2个级联的硬阴影。

级联阴影
With four cascades, four shadow textures cover different sized portions of viewing area.

带有4个级联,4个阴影贴图覆盖可视区域的不同大小的部分。

Shadow Distance is Important! 阴影距离很重要!

Shadow Distance is extremely important for both quality and performance of directional light shadows. Just like shadow cascade count, shadow distance can be set in Quality Settings and allows an easy way to scale shadows down on less performant hardware.

对于平行光阴影的质量和性能,阴影的距离是非常重要的。就像阴影级联数,阴影距离可以在质量设置中设置,很容易降低阴影范围,以减少硬件性能消耗。

Shadows fade out at the end of shadow distance, and further than that objects are not shadowed. In most situations shadows further than some distance in the game would not be noticeable anyway!

在阴影距离结束处,阴影将淡出,更远的物体将没有阴影。大多数情况下在游戏中更远地方的阴影不会引人注目!

With no shadow cascades, hard shadows and shadow distance set to 20 units our shadows look like picture below. Note that shadows do fade out in the distance, but at the same time shadow quality is much better than it was with no cascades and a distance of 50 units.

没有阴影级联,使用硬阴影,阴影距离设置为20单位,效果看起来像下图。注意阴影在距离结束处淡出,但与此同时阴影质量比没有级联和距离为50单位时更好。

Hard shadows with distance of 20 and no cascades.20单位和无级联的硬阴影。

If on the other hand we set shadow distance too high, shadows won't look good at all. Setting distance to 100 here only decreases both performance and quality and does not make much sense - no objects in the scene are further than about 50 meters anyway!

如果我们设置的阴影距离太高,所有的阴影不会好看。这里设置距离为100不过降低了性能和质量,并没有太大的意义,无论怎样场景中没有物体比50米更远。(可以理解为50米外就很难看出阴影了)

Hard shadows with distance of 100 and no cascades. Ouch! 100单位和无级联的硬阴影。

Shadow maps with cascades scale with distance much better. For example, four cascade soft shadows with covering 300 units in front of the camera look like picture below. It's somewhat worse than the picture at the top of this page, but not very bad either for a 6x increase in shadowing distance (of course in this scene that high shadow distance does not make much sense).

带有级联大小和距离的阴影贴图效果好的多。例如,摄像机前方涵盖300单位距离和4级联软阴影看起来如下图。一定程度上比上面的图片效果差,但大了6倍的阴影距离,也不错。(当然在这个场景这么高的阴影距离没有什么意义)

Soft shadows with distance of 300 and four cascades. 4级联和300单位距离的软阴影


相关文章推荐

[Unity3d] Directional Shadow Details 平行光阴影细节

This page explains shadows from Directional lights in detail. 此页面详细介绍了平行光阴影。 Directional light...

OpenGLES demo - 14. 阴影贴图 Shadow Map 之平行光

做一个场景,里面摆放着各种物体,那么bu'ke
  • hoytGM
  • hoytGM
  • 2014年08月02日 01:40
  • 1782

css3更易操作的网页细节-box-shadow阴影

box-shadow的参数有六个:X轴偏移、Y轴偏移、阴影模糊半径、阴影扩展半径、阴影颜色、阴影类型。 x-offset:X轴偏移 阴影水平偏移量,其值可以是正负值,如果是正值则阴影在对象...

Directx11教程三十一之ShadowMap(阴影贴图)之平行光成影

这一节教程跟 D3D11教程三十一之ShadowMap(阴影贴图)之点光源成影  那节教程差不多,那节教程是关于点光源下利用ShadowMap形成阴影的,这一节教程是关于平行光下利用ShadowMap...

HTML5与CSS3之box-shadow--阴影外阴影与外发光

外阴影:box-shadow:X Y Npx #color; 内阴影:box-shadow:inset X Y Npx #color; 第一个属性:阴影的X轴(可以使用负值) 第二个属性:阴影的...

Shader实现的阴影效果(Shadow)

  • 2011年01月23日 14:48
  • 3.25MB
  • 下载

基于GPU的光源空间平行分割阴影图算法

shadow Mapping 阴影投影

  • 2014年05月12日 13:58
  • 12.21MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Directional Shadow Details 平行光阴影细节
举报原因:
原因补充:

(最多只允许输入30个字)