查看: 3620|回复: 0
打印 上一主题 下一主题

[Unity 组件参考手册]iOS:内置着色器指南之Unity着色器的性能

[复制链接]
.    

3797

主题

11

听众

5万

积分

首席设计师

Rank: 8Rank: 8

纳金币
32328
精华
41

活跃会员 优秀版主 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2013-2-20 17:07:14 |只看该作者 |倒序浏览
There are a number of factors that can affect the overall performance of your game. This page will talk specifically about the performance considerations for Built-in Shaders. Performance of a shader mostly depends on two things: shader itself and which Rendering Path is used by the project or specific camera. For performance tips when writing your own shaders, see ShaderLab Shader Performance page.有一些因素能影响你的游戏的总体的性能,本章节将会讲述关于内置着色器的性能注意事项。着色器的性能和两件事情直接有关,着色器本身和被项目或者特定摄像机的渲染路径。关于你自定义着色器的性能问题,请查阅ShaderLab Shader Performance。
Rendering Paths and shader performance
渲染路径和着色器性能From the rendering paths Unity supports, Deferred Lighting and Vertex Lit paths have the most predictable performance. In Deferred lighting, each object is generally drawn twice, no matter what lights are affecting it. Similarly, in Vertex Lit each object is generally drawn once. So then, the performance differences in shaders mostly depend on how many textures they use and what calculations they do.Unity支持的渲染路径中,延迟光照和顶点关照路径有着可以预测的性能。在延迟光照中,每一个对象同城被描绘两次,不管光线是否影响到它。而在顶点光照中,简单来说,每一个对象通常只被描绘一次。因此,纹理如何被使用和需要的计算量最大程度的影响着色器性能,而产生了性能的差别。
Shader Performance in Forward rendering path
前向渲染路径的着色器性能In Forward rendering path, performance of a shader depends on both the shader itself and the lights in the scene. The following section explains the details. There are two basic categories of shaders from a performance perspective, Vertex-Lit, and Pixel-Lit.在前向(理解为在渲染过程的前期阶段,不必要的计算较多)渲染路径中,着色器的性能取决于着色器自身和场景中的灯光数量有关。接下来的章节将描述这些细节。从两个基本的角度来描述着色器的性能,分别是顶点光照和像素光照。Vertex-Lit shaders in Forward rendering path are always cheaper than Pixel-Lit shaders. These shaders work by calculating lighting based on the mesh vertices, using all lights at once. Because of this, no matter how many lights are shining on the object, it will only have to be drawn once.前向渲染路径中的顶点照明着色器总是比像素着色器要廉价。这些着色器通过基于网格节点一次使用所有光照来计算光照。因此,不管多少光照正照射着物体,它总是只绘制一次。Pixel-Lit shaders calculate final lighting at each pixel that is drawn. Because of this, the object has to be drawn once to get the ambient & main directional light, and once for each additional light that is shining on it. Thus the formula is N rendering passes, where N is the final number of pixel lights shining on the object. This increases the load on the CPU to process and send off commands to the graphics card, and on the graphics card to process the vertices and draw the pixels. The size of the Pixel-lit object on the screen will also affect the speed at which it is drawn. The larger the object, the slower it will be drawn.像素着色器为每一个将被绘制的像素计算最终的光照。因此,物体将被环境光或主要的方向性光照绘制一次,然后为每一个额外的能照射到它的光源再绘制一次。这将是N次渲染通路。N是在照射在物体上的像素光照的最后数量。这增加了CPU的处理负担和发送到显卡的命令苏亮,在显卡处理顶点和绘制像素的处理。像素光照的物体在屏幕上的尺寸也会影响到其绘制的速度。物体越大,绘制越慢。So pixel lit shaders come at performance cost, but that cost allows for some spectacular effects: shadows, normal-mapping, good looking specular highlights and light cookies, just to name a few.因此像素照明着色器 带来了性能开销,却开销却带来了一些特殊的效果,阴影,法线贴图,好质量的高光和光线饼干(…),等等。Remember that lights can be forced into a pixel ("important") or vertex/SH ("not important") mode. Any vertex lights shining on a Pixel-Lit shader will be calculated based on the object's vertices or whole object, and will not add to the rendering cost or visual effects that are associated with pixel lights.光照能被强制进入像素模式(重要)或是顶点模式("不重要")。任何顶点光源在一个像素光照着色器中会被基于物体的顶点或是整个物体来计算,而不会增加渲染开销或是和像素光照相关的视觉特效。
General shader performance 通常的着色器性能Out of Built-in Shaders, they come roughly in this order of increasing complexity:在内置着色器以外,他们将依次略微增加一些复杂性。    Unlit. This is just a texture, not affected by any lighting.
    不发光。这只是一个纹理,不被任何光照影响
    VertexLit. 顶点光照
    Diffuse. 漫反射
    Normal mapped. This is a bit more expensive than Diffuse: it adds one more texture (normal map), and a couple of shader ins***ctions.
    法线贴图,比漫反射更昂贵:增加了一个或更多纹理(法线贴图)和几个着色器结构
    Specular. This adds specular highlight calculation.
    高光。这增加了特殊的高光计算
    Normal Mapped Specular. Again, this is a bit more expensive than Specular.
    高光法线贴图。这比高光更昂贵一点
    Parallax Normal mapped. This adds parallax normal-mapping calculation.
    视差法线贴图。这增加了视差法线贴图计算
    Parallax Normal Mapped Specular. This adds both parallax normal-mapping and specular highlight calculation.
    视差高光法线贴图。这增加了视差法线贴图和镜面高光计算 Additionally, Unity has several simplified shaders targeted at mobile platforms, under "Mobile" category. These shaders work on other platforms as well, so if you can live with their simplifications (e.g. approximate specular, no per-material color support etc.), try using them!此外,Unity为手机平台准备了几种简单着色器,在"Mobile"类别下面。这些着色器工作在其他平台也一样工作,因此你能简单的使用它们(例如,近似的高光,非每材质的颜色支持等等),尝试使用它们吧。
【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-4 00:58 , Processed in 0.085040 second(s), 33 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部