Shader Optimization Tips

Author : http://www.cnblogs.com/open-coder/p/3982999.html

During the last few months, I have been working on the Graphics and shader optimization work. 
Good FPS is the balance between art and technocal. A good designed level  and game play should take account the potional performance issue. After the optimization work on the high level was done, we could deep into the lower level, and do some invistigation of shader part.
Here are some tips that you could try:
1) Don’t reinvent the wheel, use instrinsic functions; Some one would like to write his own ‘dot’ function, this is not allowed;
2) Use the most appropriate data types in calculations (float, float2, float3 and float4);
3) Get rid of typecasting when it’s not need. Such as convert float3 to float4, float to float4, fixed to half, half to float…
4) Instead of integers rely on floats for math;
5) When indexing into arrays of constants use integers instead of floats;
6) Combine scalar constants into full vectors, pack array elements into full constant vectors;
7) For conditional compilation use boolean constants declared as static;
8) Whennever possible vectorize code by joining similar operations together;
9) Do not use expensive functions, such as  log, exp, pow, sin, cos;
10) Well arrange the variable calculations among application objects, per vertex and per fragment. Per fragment is the most expensive, per vertex is less expensive, and per object is cheap;
11) Get rid of clip as possible, some one will suggest use alpha blend to replace alpah test;
12) Remove branch statements. Some powerful device will support branch well, like K1 device uber-shader;
13) Reduce the bandwith that pass from vertex shader to fragment shader;
14) Use constant variables when you could make sure what those value is:
15) Be careful on the precision such as float, half, fixed. Use theme properly, and get rid of typecast whenever possible.

 

Reference
http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/Dark_Secrets_of_shader_Dev-Mojo.pdf
http://blog.hvidtfeldts.net/index.php/2011/07/optimizing-glsl-code/
http://hi.baidu.com/haibo19981984/item/fef0a36de646e508a1cf0f93

转载于:https://www.cnblogs.com/open-coder/p/3982999.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值