GPU优化:Alpha优化

来源:互联网 发布:红薯夫妇知乎扒皮 编辑:程序博客网 时间:2024/05/17 22:25

GPU优化:Alpha优化

Some GPUs, particularly ones found in mobile devices, incur a high performance overhead for alpha-testing (or use of the discard and clip operations in pixel shaders). You should replace alpha-test shaders with alpha-blended ones if possible. Where alpha-testing cannot be avoided, you should keep the overall number of visible alpha-tested pixels to a minimum.

一些GPU,尤其是在移动设备上的GPU,在做alpha测试(或者在pixel shader里做剪切和丢弃操作)的时候会产生很大的性能开销。如果可能,你应该用alpha混合来代替alpha测试。如果alpha测试不能避免,你应该保证可见的进行alpha测试的像素个数是最小值。

iOS Texture Compression
iOS纹理压缩

Some images, especially if using iOS/Android PVR texture compression, are prone to visual artifacts in the alpha channel. In such cases, you might need to tweak the PVRT compression parameters directly in your imaging software. You can do that by installing the PVR export plugin or using PVRTexToolfrom Imagination Tech, the creators of the PVRTC format. The resulting compressed image file with a .pvr extension will be imported by the Unity editor directly and the specified compression parameters will be preserved. If PVRT-compressed textures do not give good enough visual quality or you need especially crisp imaging (as you might for GUI textures) then you should consider using 16-bit textures instead of 32-bit. By doing so, you will reduce the memory bandwidth and storage requirements by half.

有一些图像,尤其是使用iOS/Android pvr格式压缩的纹理,在alpha通道上容易出现视觉假象,在这种情况下,你可能需要在图像处理软件中调整PVRT 压缩的参数。你通过安装PVR导出插件可以做到这一点,或者使用Imagination Tech(PVRTC格式的创建者)的PVRTexTool工具。压缩后的图像后缀名是.pvr,可以被Unity编辑器导入,其压缩参数将被保留。如果PVRT格式的压缩纹理图像效果不够好,或者你需要特别清晰的图像(为了用于GUI 纹理),这时你应该使用16位的纹理,而不是32位。这样,你会减少一半内存带宽和存储空间的需求。

Android Texture Compression
Android 纹理压缩

All Android devices with support for OpenGL ES 2.0 also support the ETC1 compression format; it's therefore encouraged to whenever possible use ETC1 as the prefered texture format.

所有的Android 设备都能支持OpenGL ES 2.0 ,并因此支持ETC1压缩格式,因此,鼓励尽可能使用ETC1作为首选纹理格式。

If targeting a specific graphics architecture, such as the Nvidia Tegra or Qualcomm Snapdragon, it may be worth considering using the proprietary compression formats available on those architectures. The Android Market also allows filtering based on supported texture compression format, meaning a distribution archive (.apk) with for example DXT compressed textures can be prevented for download on a device which doesn't support it.

如果针对特定的图形架构,如NvidIA的Tegra 和 高通的 Snapdragon,值得考虑使用专有的压缩格式。Android市场也允许基于支持的纹理压缩格式的过滤,这意味着:如果一个发布的APK包里包含有例如DXT格式的压缩纹理,那么那些不支持DXT格式的设备将不允许下载这个APK包。

An Exercise (Unity PRO only) 一个练习(只支持Unity Pro)

  • Download Render to Texel. 下载Render to Texel
  • Bake lighting on your model. 为你的模型烘焙光照
  • Run the High Pass filter on the result in Photoshop. 使用高通滤镜在Photoshop里
  • Edit the "Mobile/Cubemapped" shader, included in the Render to Texel package, so that the missing low-frequency light details are replaced by vertex light. 
    编辑"Mobile/Cubemapped" shader,将其添加到 Render to Texel 工具的package里,让顶点光来代替丢失的低频光照细节。