Shadow Size Computation 阴影大小计算

Date:2011-10-22
Desktop

Unity computes shadow map sizes this way:

Unity计算阴影贴图大小是这样的:

First light's "coverage box" on the screen is computed. This is what rectangle on the screen the light possibly illuminates:

首先计算屏幕上灯光的覆盖范围,这可能是屏幕上灯光照亮的矩形范围:

  • For Directional lights that is the whole screen.
    对于平行光是整个屏幕。
  • For Spot lights it's the bounding rectangle of light's pyramid projected on the screen.
    聚光灯是屏幕上圆锥型投影的包围矩形(圆锥投影是在矩形范围内)。
  • For Point lights it's the bounding rectangle of light's sphere projected on the screen.
    点光源是屏幕上球形投影的包围矩形(球形投影是在矩形范围内)。

Then the larger value of this box' width & height is chosen; call that pixel size.

然后这个盒的宽和高较大的值被选择;调用像素大小。

At "High" shadow resolution, the size of the shadow map then is:

"高"阴影分辨率,阴影贴图的大小是:

  • Directional lights: NextPowerOfTwo( pixel size * 1.9 ), but no more than 2048.
    平行光源: NextPowerOfTwo( pixel size * 1.9 ),但不超过2048。
  • Spot lights: NextPowerOfTwo( pixel size ), but no more than 1024.
    聚光灯:NextPowerOfTwo( pixel size ),但不超过1024。
  • Point lights: NextPowerOfTwo( pixel size * 0.5 ), but no more than 512.
    点光源:NextPowerOfTwo( pixel size * 0.5 ),但不超过512。

When graphics card has 512MB or more video memory, the upper shadow map limits are increased (4096 for Directional, 2048 for Spot, 1024 for Point lights).

当显卡有512MB或更多的显存,阴影贴图的上限倍增(4096 为平行光, 2048 为聚光灯, 1024 为点光源)。

At "Medium" shadow resolution, shadow map size is 2X smaller than at "High" resolution. And at "Low" resolution, it's 4X smaller than at "High" resolution.

"中"阴影分辨率,阴影贴图大小2倍小于"高"分辨率。"低"阴影分辨率,阴影贴图大小4倍小于"高"分辨率。

The seemingly low limit on Point lights is because they use cubemaps for shadows. That means six cubemap faces at this resolution must be in video memory. They are also quite expensive to render, as potential shadow casters must be rendered into up to six cubemap faces.

点光源看上去很低的限制是因为它们为阴影使用cubemap贴图。这意味着着,在显存中有cubemap六面贴图。这使渲染十分消耗性能,作为潜在的阴影投射需要渲染到cubemap的六面。

Shadow size computation when running close to memory limits
当运行时接近显存限制时,阴影大小计算

When running close to video memory limits, Unity will automatically drop shadow map resolution computed above.

当运行接近显存限制时,Unity将自动降低阴影分辨率。

Generally memory for the screen (backbuffer, frontbuffer, depth buffer) has to be in video memory; and memory for render textures has to be in video memory, Unity will use both to determine allowed memory usage of shadow maps. When allocating a shadow map according to size computed above, it's size will be reduced until it fits into (TotalVideoMemory - ScreenMemory - RenderTextureMemory) / 3.

一般来说屏幕内存(前台缓冲,后台缓冲,深度缓冲)是在显存中;以及渲染纹理内存也是在显存中;Unity想使用这两项来确定阴影贴图的显存使用量。根据上面计算的大小分配阴影贴图时,它的大小将减小,直至适合。 (总显存 - 屏幕内存 - 渲染纹理内存) / 3。

Assuming all regular textures, vertex data and other graphics objects can be swapped out of video memory, maximum VRAM that could be used by a shadow map would be (TotalVideoMemory-ScreenMemory-RenderTextureMemory). But exact amounts of memory taken by screen and render textures can never be determined, and some objects can not be swapped out, and performance would be horrible if all textures would be constantly swapping in and out. So Unity does not allow a shadow map to exceed one third of "generally available" video memory, which works quite well in practice.

假设所有标准纹理,顶点数据和其他图形物体可以换出显存,阴影贴图可使用的最大显存(总显存 - 屏幕内存 - 渲染纹理内存)。但屏幕和渲染纹理使用确切内存永远不能确定,并且一些物体不能被换出,如果所有纹理不断换进换出,影响性能是非常可怕的。因此,Unity不允许阴影贴图超可用显存三分之一,这在实践中工作的很好。

iOS

This is currently not supported on the iOS platform.

此功能目前不支持iOS的目标。

Android

This is currently not supported on the Android Platform.

此功能目前不支持Android的目标。

最近页面更新: 2010-09-07

分类:Manual|评论: 0|浏览: 83 翻译: U_鹰
评论
暂无评论
发表评论
用户名:

评论审核后才会显示!