位置: 编程技术 - 正文
推荐整理分享unity3d移动平台性能优化专题(8):shader优化(unity3dwasd移动),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:unity移动游戏开发,unity3d跨平台,unity移动ui,unity移动游戏开发,unity3dwasd移动,unity移动ui,unity移动ui,unity3dwasd移动,内容如对您有帮助,希望把文章链接给更多的朋友!
当然如果你完全可以采用内置的Mobile下面的shader是最好,性能肯定是杠杠的。但是相信绝大部分游戏还是不得不自己写shader,那就要注意写出高性能的shader。
1.复杂的数学函数(如 pow,exp,log,cos,sin,tan 等等)会大大增加 GPU 负担,所以一个好的经验法则是,此类运算在每个像素中不得超过一个。考虑在合适时使用查找纹理作为替代选择。
2.alpha 测试运算会让片段速度变慢。(on PowerVR GPUs found in iOS and some Android devices)
3.编写自定义的着色器时,应始终指定浮点变量精度。为获得最佳性能,挑选精度尽可能小的浮点式至关重要。很多台式机 GPU 均完全忽略运算精确,但是它对于大量移动 GPU 的性能具有重大影响。
如果着色器使用 Cg/HLSL 编写,那么精度规定如下:
float — 完整的 位浮点式,适合用于顶点变换,但性能最慢。half — 简化的 位浮点式,适用于纹理 UV 坐标且比 float 大约快两倍。fixed — 位定点式,适合色彩、照明计算和其它高性能操作,速度大约比 float 快 4 倍如果着色器以 GLSL ES 编写,那么浮点精度将分别规定为 highp、mediump、lowp。
4.大部分shader都有_Color属性,但如果你并没有使用,那么就应该去掉,避免无谓的计算。5.通用的表面着色器虽然通用,但性能其实并不好,参考:
Surface Shaders are great for writing shaders that interact with lighting. However, their default options are tuned for “general case”. In many cases, you can tweak them to make shaders run faster or at least be smaller:
approxview directive for shaders that use view direction (i.e. Specular) will make view direction be normalized per-vertex instead of per-pixel. This is approximate, but often good enough.halfasview for Specular shader types is even faster. Half-vector (halfway between lighting direction and view vector) will be computed and normalized per vertex, andlighting function will already receive half-vector as a parameter instead of view vector.noforwardadd will make a shader fully support only one directional light in Forward rendering. The rest of the lights can still have an effect as per-vertex lights or spherical harmonics. This is great to make shader smaller and make sure it always renders in one pass, even with multiple lights present.noambient will disable ambient lighting and spherical harmonics lights on a shader. This can be slightly faster. 因为我们没有光照,所以我建议采用顶点着色器和片段着色器。
Unity3D 学习笔记 (1) 在公司实习一个星期了,现在来写下这周实习的心得吧。公司用的是Unity3D这东西完全没用过……本来在学校学的是java只能从java转到C#上了,实习了一个
Unity动态创建空GameObject的方法 因为MonoBehaviour不能New实例化所以先创建空GameObject后在添加脚本即可GameObjecttGO=newGameObject(tGO);tGO.AddComponentT();
Unity同时接入ShareSdk和微派支付sdk(二) 说明一下,我是首先接入了微派支付的sdk,在微派AndroidManifest.xml的基础上加入的sharesdk。本人仅仅接入sharesdk和微派sdk,其他sdk可能不能这么做,慎重!
标签: unity3dwasd移动
本文链接地址:https://www.jiuchutong.com/biancheng/378817.html 转载请保留说明!友情链接: 武汉网站建设