Unity3D高级手册0503:阴影大小计算

2014-08-29 20:40:59|?次阅读|上传:huigezrx【已有?条评论】发表评论

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

Unity Manual > Advanced > Shadows in Unity > Shadow Size Computation

Unity手册->高级->Unity中的阴影->阴影大小计算

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).

当显卡拥有512M或更过视频内存,高阴影图片被限制增加(定向光源为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.  在点光源上最小尺寸看起来似乎是因为他们使用的立方体图片的阴影。这意味着6个立方体面临着在这项决定必须在视频内存。它们也相当昂贵的渲染,作为潜在的阴影脚轮必须渲染成6个立方体的表面。

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将同时使用,以确定允许内存使用的阴影地图。当分配一个阴影图根据以上的规模计算,它的大小将减少直到它(TotalVideoMemory - ScreenMemory - RenderTextureMemory)/ 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.

假设所有正规的纹理,顶点数据和其他图形对象可以被交换出去的视频内存,最大显存可以通过地图使用的阴影将是(TotalVideoMemory - ScreenMemory - RenderTextureMemory)。但是,具体数额由屏幕所呈现的纹理内存永远不能确定,有些对象不能被交换出去,如果所有的纹理会不断交换和退出,性能将是可怕的。因此,Unity不允许阴影地图超过三分之一的“普遍”的视频内存,其运作方式在实践中相当不错。

发表评论0条 】
网友评论(共?条评论)..
Unity3D高级手册0503:阴影大小计算