Unity 2D,多层背景透支

安东·卡萨布斯基(Anton Kasabutski)

问题的定义很简单,但是我找不到简单或直接的解决方案。

我有一个由几个不透明层组成的背景:

  1. 渐变天空(1pic,静态);
  2. 明亮的大山(1pic,移动一点);
  3. 较黑的(较近的)山脉(随机生成几张照片,移动速度更快);
  4. 甚至更黑更近的山脉都有一些细节(一些图片,随机生成,移动得更快)。

我经历了透支:每张图片都在彼此叠加。每一层都是动态的,所以我不能只砍掉一半的天空或砍掉一半的山。但是,50%的图片只是一种纯色+全透明。

问题1:防止背景透支的最佳实践是什么?考虑最简单的示例:背景天空(100%屏幕)+移动山峰(80%屏幕)。

问题2:有些山脉是简单的图片-一种不透明的颜色,弯曲的形状,其余则完全透明。我应该继续将它们用作精灵中的纹理,还是必须参与一些实践才能以不同方式使用它?

背景外观: 背景外观

安东·卡萨布斯基(Anton Kasabutski)

答案:

  1. 除非会从头开始写一些东西,否则没有防止透支的解决方案。很有可能会涉及网格和根据图层位置进行的智能运行时自适应。
  2. Unity now has SVG support. I tested this and it's better (depending on the number of vertices) than having individual textures. Properly imported SVG images have no textures in them which prevents increasing of SetPassCalls and overall texture loading/unloading.

Overdraw is the problem for low-end devices and the best practice is to minimize the number of layers. However, something additional can be done.

  • First of all, the empty scene rendering should cost as little as possible. That means no post-processing, no unoptimized scripts, etc. Simple FPS counter and temperature measures of a low-end device will help here.
  • Then, the choice of shaders matters the most. The simplest forms of shaders are Unlit/*. However, they aren't as flexible as default shaders (which also can be considered as lightweight).
  • SetPassCalls是一个可能很重要的主题,但对我来说并不是设备崩溃。本质上,最好将所有背景都包含在一个地图集中,共享同一着色器,并且两者之间不要有其他任何东西。这样,您可以根据需要具有任意多个图层,所有内容都将在一个绘制通道调用中绘制。
  • 最后,避免全屏动态照明。光源应尽可能少地发光,且面积应尽可能小。照明的质量也可以切换。我仍在与照明作斗争,并尝试在任务中进行烘焙,但到目前为止,摆脱背景全屏照明对FPS的推动作用很大。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章