ShadowGun:针对移动样本级别进行优化

Here at Unity, we want to offer you the smoothest experience for making fantastic games. One of the biggest parts of our job is ensuring that Unity is a highly performant platform for you to deploy to mobile devices, but when it comes to getting the best performance out of your games – that’s where you come in. So that you’re not in the dark when it comes to optimising your games, we got together with MadFinger Games, the developers of blockbuster mobile title ‘ShadowGun‘ to offer you a sample level project packed with innovative techniques, to help you learn about the techniques that they employed when creating their game.

在Unity,我们希望为您提供制作出色游戏的最流畅体验。 我们工作中最大的部分之一就是确保Unity是一个高性能平台,供您部署到移动设备上,但是要获得游戏中的最佳性能,这就是您的用武之地。在优化游戏方面,我们与MadFinger Games合作, MadFinger Games是一鸣惊人的移动游戏《 ShadowGun 》的开发商,为您提供了一个包含创新技术的示例项目,以帮助您了解他们采用的技术在创建游戏时。

UPDATE: We now have a dedicated forum thread for discussing the optimization tips shown in this sample level. Please continue discussion there – http://forum.unity3d.com/threads/130163-ShadowGun-Optimising-for-Mobile

更新:我们现在有一个专用的论坛线程,用于讨论此样本级别中显示的优化技巧。 请在那里继续讨论– http://forum.unity3d.com/threads/130163-ShadowGun-Optimising-for-Mobile

The sample level project can be downloaded via the button below. It should be noted that this is not a gameplay example but purely designed to assist you in learning about optimal mobile techniques –

可以通过下面的按钮下载示例级别的项目。 请注意,这不是游戏性示例,而仅仅是为了帮助您学习最佳移动技术而设计的–

We’d like to thank MadFinger for their help with this project and for all the information they provide below. For those of you new to some of the terms mentioned here, we include links to external sites explaining the concepts involved:

我们要感谢MadFinger在该项目中的帮助以及他们在下面提供的所有信息。 对于您不熟悉此处提到的某些术语的人,我们包括指向外部网站的链接,这些链接解释了所涉及的概念:

基本知识 (General knowledge)

If you want to have a 3rd person action game with beautiful graphics, complex levels with bunch of enemies with decent A.I. which runs flawlessly on iPhone 3Gs, you must put lot of effort into optimization. For the graphics side, you can optimize the number of triangles, amount of textures in memory and, of course, the shaders. We found that on mobile devices, shaders can be a real performance killer but also an incredible and powerful servant.

如果您想要拥有精美的图形,复杂的关卡以及具有不错的AI的敌人群的第三人称动作游戏,并且可以在iPhone 3G上完美运行,则必须投入大量精力进行优化。 对于图形方面,您可以优化三角形的数量,内存中的纹理数量,当然也可以优化着色器。 我们发现,在移动设备上,着色器可以是真正的性能杀手,但同时也是不可思议的强大功能。

Alpha混合杀死 (Alpha blending kills)

The amount of faces using alpha blending, especially when it fills a large portion of the screen, reduces performance on mobile devices dramatically. When a bunch of alpha faces overlap each other and thus increase overdraw, it is a consistent killer for performance on slower devices.

使用alpha混合的面部数量(尤其是当它占满屏幕的大部分时)会极大地降低移动设备的性能。 当一堆Alpha面彼此重叠并因此增加透支率时 ,对于在较慢设备上的性能而言,它始终是杀手kill。

复杂的每像素着色器会降低帧速率 (Complex, per-pixel shaders kill framerate)

We found that rendering large surfaces (in terms of screen area) with complex fragment shaders kills the framerate even more consistently than alpha blending. Complex fragment shaders should be used for smaller objects only.

我们发现,使用复杂的片段着色器渲染较大的表面(就屏幕面积而言)比alpha混合更一致地杀死帧速率。 复杂片段着色器应仅用于较小的对象。

ShadowGun中的明暗器 (Shaders in ShadowGun)

Thanks to great cooperation between our programmers and graphic artists, we managed to create shaders that allow us to create advanced effects that do not have great demands on performance. The following shaders were used in the sample level from ShadowGun:

得益于程序员与图形艺术家之间的大力合作,我们设法创建了着色器,使我们能够创建对性能要求不高的高级效果。 ShadowGun的示例级别中使用了以下着色器:

环境高光贴图(每个顶点着色器虚拟光泽度添加剂) (Environment specular maps (Shader Virtual Gloss Per Vertex Additive))

This shader combines Diffuse (RGB channels) and Specular (Alpha Channel). The Specular map uses the alpha channel of the texture to define the glossy vs matte parts of surface as usual, but specularity is not calculated per-pixel, but rather per vertex.

此着色器将“漫反射”(RGB通道)和“镜面反射”(Alpha通道)组合在一起。 镜面贴图通常使用纹理的Alpha通道来定义表面的光泽部分与无光部分,但是镜面反射不是按像素计算,而是按顶点计算。

The resulting effect is reasonably convincing and it is significantly faster than using per-pixel specular calculations. It is perfectly suitable for large area meshes (like a level environment). This shader allows us to modify the strength of the specular effect and to approximately determine the direction of “light”.

由此产生的效果令人信服,并且比使用每像素镜面反射计算要快得多。 它非常适合用于大面积网格(例如水平环境)。 此着色器使我们可以修改镜面效果的强度并大致确定“光”的方向。

优化的动态角色照明和阴影(Lightprobes和BRDF着色器) (Optimized dynamic character lighting and shading (Lightprobes and BRDF Shader))

The traditional problem with static lighting (Lightmaps) is achieving proper lighting on the dynamic objects (i.e. Player characters and NPCs).

静态光照(Lightmaps)的传统问题是在动态对象(即玩家角色和NPC)上实现适当的光照。

Unity offers a classic solution, which stores lighting information for dynamic objects in proxy objects (Light probes). Dynamic objects then reconstruct incoming light information from nearby probes.

Unity提供了一种经典的解决方案,该解决方案将动态对象的照明信息存储在代理对象(“光”探针)中。 然后,动态物体会从附近的探头重建入射光信息。

Unity also contains superb character shader, which is well optimized for mobile devices (check out the Mutant character in the sample scene). This shader supports Diffuse, Specular and Normal maps and uses a special script that generates a texture which is used for evaluation of the lighting in BRDF-like fashion. Resulting effect on characters perfectly mimics the next-gen character shading from big console titles.

Unity还包含出色的角色着色器,该着色器已针对移动设备进行了优化(请在示例场景中查看Mutant角色)。 该着色器支持“漫反射”,“镜面反射”和“法线”贴图,并使用一个特殊的脚本来生成纹理,该纹理用于以类似BRDF的方式评估照明。 对角色的最终效果完美地模仿了大型游戏机标题中的下一代角色阴影。

雾和体积光线(Shader Blinking Godrays) (Fog and volumetric light rays (Shader Blinking Godrays))

When you turn on the global fog in 3d engine, the framerate often drops below a usable level, especially on older mobile devices.

当您在3d引擎中启用全局雾化功能时,帧速率通常会降至可用水平以下,尤其是在较旧的移动设备上。

From a graphics point of view however, fog dramatically improves look of the environments, especially helping to perceive the depth and space of a scene. The solution we came up with is the use of simple mesh faces with a transparent texture (Fog planes) instead of global fog. Once a player comes too close to a fog plane, it fades out and moreover, vertices of the fog plane are pulled away (because even a fully transparent alpha surface still consumes lot of render time).

但是,从图形角度来看,雾显着改善了环境外观,尤其有助于感知场景的深度和空间。 我们提出的解决方案是使用具有透明纹理(雾平面)的简单网格面而不是全局雾。 一旦玩家离雾平面太近,它就会淡出,此外,雾平面的顶点会被拉开(因为即使是完全透明的Alpha曲面仍然会消耗大量渲染时间)。

在3D应用中准备网格以与着色器正确配合使用 (Preparation of the mesh in 3D app to work correctly with shader)

    Its simple to duplicate and distribute Fog planes through the level anywhere its needed. In a very similar way we use this shader for light rays, light source cones and other alpha effects.

    它很容易在需要的任何位置通过级别复制和分发雾平面。 以非常相似的方式,我们将此着色器用于光线,光源锥和其他alpha效果。

    飞机坠毁时浓烈的动画烟雾(Shader Scroll 2 Layers Sine Alpha-blend) (Dense animated smoke at plane crash (Shader Scroll 2 Layers Sine Alpha-blended))

    Because of density, the smoke particles are pretty expensive, and we found that it is better to use simple mesh with animated smoke texture (e.g. for background fire on crash site).

    由于密度大,烟雾颗粒非常昂贵,我们发现最好使用带有动画烟雾纹理的简单网格(例如,用于坠毁现场的背景火灾)。

    In our case, the smoke is animated by blending two textures and moving them over each other. There is also vertex alpha involved in order to smooth the edges of the mesh. The mesh is also colored with vertex colors (orange to mimic flames on the ground and greyish as smoke blends to the sky).

    在我们的案例中,通过混合两个纹理并将它们彼此移动来使烟雾动画化。 还涉及顶点alpha,以平滑网格的边缘。 网格还用顶点颜色着色(橙色以模仿地面上的火焰,并随着烟雾向天空混合而呈灰色)。

    移动Skybox(阴影滚动2层可乘) (Moving Skybox (Shadow Scroll 2 Layers Multiplicative))

    For our custom skybox, a similar technique with regards to scrolling in the shader creates a dynamic cloudscape.

    对于我们的自定义天空盒,有关在着色器中滚动的类似技术会创建动态cloudscape。

    风中的旗帜和布(着色器光照贴图+风) (Flags and cloths in the wind (Shader Lightmap + Wind))

    Any animated objects in the scene brings life to level and when they are animated for “free” by the shader itself. We have animated the flags and cables in the wind in this way. Information which vertices are fluttering in the wind and which are not is defined by the vertex colors alpha in 3d modeling program (white alpha moves, black alpha dont). In shader parameters, user must define the direction and speed of flutter only.

    场景中的任何动画对象都可以使生活变得更加生动,而当着色器本身对其进行“免费”动画处理时。 我们以这种方式在风中对旗帜和电缆进行了动画处理。 在3d建模程序中,哪些顶点随风飘动,哪些顶点未定义的信息由顶点颜色alpha定义(白色alpha移动,黑色alpha dont)。 在着色器参数中,用户必须仅定义颤动的方向和速度。

    法律声明 (Legal notice)

    All custom shaders in SHADOWGUN sample level are intelectual property of MADFINGER Games, a.s. and they are free to use (apart from BRDF character shader, which was created by Unity Technologies and is also free to use). Meshes and textures in the level remains property of MADFINGER Games, a.s. and cannot be used for any commercial purpose without permission from MADFINGER Games, a.s.

    SHADOWGUN样本级别中的所有自定义着色器都是MADFINGER Games的知识产权,因此它们是免费使用的(除了由Unity Technologies创建的BRDF角色着色器,也可以免费使用)。 关卡中的网格和纹理仍然是MADFINGER Games的财产,未经MADFINGER Games的许可,不得用于任何商业目的,因为

    翻译自: https://blogs.unity3d.com/2012/03/23/shadowgun-optimizing-for-mobile-sample-level/

    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

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

    抵扣说明:

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

    余额充值