Shader performance

 

 Performance of a shader mostly depends on two things: shader itself and which Rendering Path is used by the project or specific camera

 shader的性能依靠shader自己 和 被工程或摄像机使用的渲染路径。

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.

延迟光照和顶点光照有最可预测的性能。延迟光照:无论什么灯在照射,每个物体被普遍绘制两次。顶点光照:每个物体被绘制一次。

shader的性能差异大部分依靠texture的数量和做什么计算。

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.

在Forward rendering path中,shader的性能依靠shader自身和场景中的light。从性能观点区分有两类shader: Vertex-Lit 和 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.

在forward rendering path中,顶点光照shader比像素光照shader的开销小。这些shader通过计算mesh 顶点的光照,一次计算所以使用的灯光。正是这个原因,无论多少灯光正在照射这个问题,它仅仅被绘制一次。

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

像素shader计算在每个被绘制像素点的最终灯光,因此,一个物体必须被绘制一次来得到周伟环境,主方向光一次,一旦额外的灯光照射它又是一次。

这个公式是N渲染通道。 N是最终照射到物体本身的像素灯数量。这增加了CPU来处理 和 发送给显卡来处理顶点和绘制像素命令的负担。像素灯在屏幕上的尺寸将影响被绘制地方的速度,这个物体越大,绘制越慢。

因此像素光照比顶点光照开销高,但这个开销在一些特殊的效果中是值得的: 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.(即取决于灯光类型而不是shader,性能只和灯光类型参考的变量个数有关,如顶点光的计算取决于物体的顶点和整个物体)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值