> 记录一些shader的优化项,不断更新中

Data Type

float

32位 高精度 运算慢

half

16位 中低精度 适合uv,色值 等一些数据的存放。 运算速度一般

fixed

11位 低精度 部分GPU不支持此类型。 运算最快. 例图中包括了不支持的显卡型号。

Shader Code Optimize

Set Important Lighting

  1. 在UNITY3D光源组件中设置Important Lighting。不设置默认Auto.
  2. 在#pragma中声明 noforwardadd .

Reuse Variable

1.尽量少声明变量
2.尽量复用变量

Close Other Options

关闭其他不需要使用的选项,以下原文来自UNITY3D文档

1
2
3
4
5
6
7
8
9
10
11
12
Code generation options - by default generated surface shader code tries to handle all possible lighting/shadowing/lightmap scenarios. However in some cases you know you won’t need some of them, and it is possible to adjust generated code to skip them. This can result in smaller shaders that are faster to load.

exclude_path:deferred, exclude_path:forward, exclude_path:prepass - Do not generate passes for given rendering path (Deferred Shading, Forward and Legacy Deferred respectively).
noshadow - Disables all shadow receiving support in this shader.
noambient - Do not apply any ambient lighting or light probes.
novertexlights - Do not apply any light probes or per-vertex lights in Forward rendering.
nolightmap - Disables all lightmapping support in this shader.
nodynlightmap - Disables runtime dynamic global illumination support in this shader.
nodirlightmap - Disables directional lightmaps support in this shader.
nofog - Disables all built-in Fog support.
nometa - Does not generate a “meta” pass (that’s used by lightmapping & dynamic global illumination to extract surface information).
noforwardadd - Disables Forward rendering additive pass. This makes the shader support one full directional light, with all other lights computed per-vertex/SH. Makes shaders smaller as well.

example :

1
#pragma surface surf HelloWorld exclude_path:prepass noshadow noforwardadd nofog

2016.10.25更新

减少StandShader的使用
减少StandShader的使用
减少StandShader的使用
重要事情要说三遍!