Unity3D高级手册05:Unity中的阴影

Unity3D高级手册05:Unity中的阴影

2014-08-24 13:56:23|?次阅读|上传:huigezrx【已有?条评论】发表评论

关键词:游戏, 虚拟现实, Unity3D|来源:唯设编程网

Unity Manual > Advanced > Shadows in Unity

Unity手册->高级->Unity中的阴影

Unity 2.0 Pro makes it possible to use real-time shadows on any light. Objects can cast shadows onto each other and onto parts of themselves ("self shadowing"). All types of Lights - Directional, Spot and Point - support shadows.

Unity2.0专业版本可能使用任何光线实时阴影。对象可以投射到对方,走上自己的阴影部分(“自我阴影”)。所有类型的光源-方向光源,聚光光源和点光源-支持阴影。

Using shadows can be as simple as choosing Hard Shadows or Soft Shadows on a Light. However, if you want optimal shadow quality and performance, there are some additional things to consider.

使用阴影可以很简单的选择上硬阴影或软阴影。不过,如果你想最佳的阴影质量和性能,还有一些额外的事情要考虑。

The Shadow Troubleshooting page contains solutions to common shadowing problems. 阴影疑难解答页包含解决公共问题的阴影。

Curiously enough, the best shadows are non-realtime ones! Whenever your game level geometry and lighting is static, just precompute lightmaps in your 3D application. Computing shadows offline will always result in better quality and performance than displaying them in real time. Now onto the realtime ones...

奇怪的是,最好的阴影是非实时的!每当你的游戏水平几何和照明是静态的,只要预先计算在您的3D应用光映射。离线阴影计算总是产生更好的质量和性能超过实时显示它们。现在,到实时的...

Tweaking shadow quality 调整阴影质量

Unity uses so called shadow maps to display shadows. Shadow mapping is a texture based approach, it's easiest to think of it as "shadow textures" projecting out from lights onto the scene. Thus much like regular texturing, quality of shadow mapping mostly depends on two factors:

Unity使用所谓的阴影图形显示阴影。阴影映射是一种基于纹理的方法,最简单的把它看成“阴影纹理”从光源里投射到场景上。因此,就像常规纹理,阴影映射的质量主要取决于两个因素:

  • The resolution (size) of the shadow maps. The larger the shadow maps, the better the shadow quality.  该阴影图形分辨率(大小)。较大的阴影图形,更好的阴影质量。
  • The filtering of the shadows. Hard shadows take the nearest shadow map pixel. Soft shadows average several shadow map pixels, resulting in smoother looking shadows (but soft shadows are more expensive to render).  过滤的阴影。硬阴影采取就近的阴影图形像素。软阴影平均几个阴影图形像素,阴影看起来平滑的结果(但软阴影的渲染比较昂贵)。

Different Light types use different algorithms to calculate shadows.  不同的类型的光源使用不同的算法来计算阴影。

  • For Directional lights, the crucial settings for shadow quality are Shadow Distance and Shadow Cascades, found in Quality Settings. Shadow Resolution is also taken into account, but the first thing to try to improve directional shadow quality is reducing shadow distance. All the details about directional light shadows can be found here: Directional Shadow Details.
  • 定向光源,阴影质量的关键设置是阴影距离和阴影级联,在质量设置中找到。阴影清晰度也是考虑,但首先要努力提高定向阴影质量的减少阴影的距离。所有关于定向阴影的细节可以在这里找到:定向阴影细节。
  • For Spot and Point lights, Shadow Resolution determines shadow map size. Additionally, for lights that cover small area on the screen, smaller shadow map resolutions are used.  对于聚光光源和点光源,阴影清晰度决定阴影映射的大小。此外,对于光源覆盖在屏幕上小的面积,小的阴影图形的清晰度被使用。

Details on how shadow map sizes are computed are in Shadow Size Details page.阴影图形尺寸的详情如何计算在阴影大小详细信息页。

Shadow performance 阴影性能

Realtime shadows are quite performance hungry, so use them sparingly. For each light to render its shadows, first any potential shadow casters must be rendered into the shadow map, then all shadow receivers are rendered with the shadow map. This makes shadow casting lights even more expensive than Pixel lights, but hey, computers are getting faster as well!  实时阴影要求相当高的性能,所以要适可而止。对于每一个光渲染的它自己的阴影,首先调整任何潜在的阴影都必须进入到阴影图形里,那么所有的阴影接收阴影图形渲染。这使得阴影投影甚至比像素光源昂贵。但是,嘿,电脑速度越来越快的!

Soft shadows are more expensive to render than Hard shadows. The cost is entirely on the graphics card though (it's only longer shaders), so Hard vs. Soft shadows don't make any impact on the CPU or memory.

软阴影是较昂贵的渲染比硬阴影。费用完全是图形卡,但(这只是长久的阴影),所以硬阴影与软阴影相比,不受任何CPU或内存的影响

Quality Settings contains a setting called Shadow Distance - this is how far from the camera shadows are drawn. Often it makes no sense to calculate and display shadows that are 500 meters away from the camera, so use as low shadow distance as possible for your game. This will help performance (and will improve quality of directional light shadows, see above).  质量设置包含一个名为阴影距离-这就是远距离摄像机阴影绘制。往往是没有意义的计算和显示阴影,有500米距离相机,因此使用尽可能低的阴影距离为你的游戏。这将有助于性能(和将提高定向阴影质量,见上文)。

Hardware support for shadows 硬件支持的阴影

Built-in shadows require a fragment program (pixel shader 2.0) capable graphics card. This is the list of supported cards:  内置阴影需要一个片断程序(支持Pixel Shader 2.0)的图形卡。这是支持的卡列表:

  • On Windows:  windows平台
    • ATI Radeon 9500 and up, Radeon X series, Radeon HD series.
      • When using OpenGL, ATI cards do not support Point light shadows (point lights won't have shadows). 当使用OpenGL,ATI显卡不支持点光源阴影(点光源不会有阴影)。
    • NVIDIA GeForce FX, 6xxx, 7xxx, 8xxx, 9xxx, GeForce GT, GTX series.
    • Intel GMA 3000 (965) and up.
  • On Mac OS X:  在Mac平台上
    • ATI Radeon 9500 and up, Radeon X series.
    • NVIDIA GeForce FX, 6xxx, 7xxx, 8xxx, 9xxx series.
      • NVIDIA cards on OS X 10.3 have shadows disabled.
    • Intel GMA 950.
      • Soft shadows are disabled because of driver bugs (hard shadows will be used instead).  软阴影被停用是因为驱动程序错误(硬阴影将代替)。

Notes 注释

  • Point light shadows are always "hard". Selecting Hard or Soft shadows does not make a difference. 点光源阴影总是“硬”。选择硬阴影或软阴影并没有发挥作用。
  • Vertex-lit lights don't have shadows. 顶点背光光源没有阴影。
  • Vertex-lit materials won't receive shadows (but do cast shadows). Some other materials don't receive shadows as well (Diffuse Fast).  顶点背光材料将不会收到阴影(但投射阴影)。其它一些材料也不会收到阴影(快速弥漫)。
  • Transparent objects don't cast or receive shadows. Transparent Cutout objects do cast and receive shadows.  透明的对象不投射阴影或接收阴影。透明切块物体投射和接收阴影。
发表评论0条 】
网友评论(共?条评论)..
Unity3D高级手册05:Unity中的阴影