翻译自:https://msdn.microsoft.com/en-us/library/windows/desktop/cc627119%28v=vs.85%29.aspx
前言:

This section describes general-purpose strategies that you can use to optimize your shaders. You can apply these strategies to shaders that are written in any language, on any platform.
本节描述的通用策略,您可以使用它们来优化你的阴影。可以将这些策略应用到着色器,是用任何语言编写的,在任何平台。
主要的内容如下:
- Know Where To Perform Shader Calculations
- Skip Unnecessary Instructions
- Pack Variables and Interpolants
- Reduce Shader Complexity
- Related Topics
Know Where To Perform Shader Calculations
Vertex shaders perform operations that include fetching vertices and performing matrix transformation of vertex data. Typically, vertex shaders are executed once per vertex.
顶点着色器执行操作,包括抓取顶点和顶点数据的执行矩阵转换。通常,每个顶点顶点着色器执行一次。
Pixel Shaders perform operations that include fetching texture data and performing lighting calculations. Typically, pixel shaders are executed once per pixel for a given piece of geometry.
像素着色器,包括提取纹理数据执行操作和执行照明计算。对于一个给定的几何,像素着色器通常是执行一次每像素。
Typically, pixels outnumber vertices in a scene, so pixel shaders execute more often than vertex shaders.
一般来说,像素比顶点在一个场景,所以像素着色器比顶点着色器执行的更多。
When you design shader algorithms, keep the following in mind:
当您设计着色器算法时,请记住以下几点:
- Perform calculations on the vertex shader if possible. A calculation that is performed on a pixel shader is much more expensive than a calculation that is performed on a vertex shader.
- Consider using per-vertex calculations to improve performance in situations such as dense meshes. For dense meshes, per-vertex calculations may produce results that are visually indistinguishable from results produced with per-pixel calculations.
Skip Unnecessary Instructions