在 iOS/Android 的片段着色器中使用 highp 可以吗? [英] Is it OK to use highp in fragment shaders for iOS/Android?

查看:57
本文介绍了在 iOS/Android 的片段着色器中使用 highp 可以吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据GLSL ES 参考,支持highp 是可选的.所以我一直在我所有的片段着色器中使用 precision mediump float; 所以我没有设备兼容性问题.在某些情况下,很难以 10 位的相对精度产生好看的输出,我希望能够在必要时切换到 highp.

According to the GLSL ES reference, support for highp in fragment shaders is optional. So I have been using precision mediump float; in all my fragment shaders so I don't have device compatibility issues. In some cases it's quite difficult to produce good-looking output with only 10 bits of relative precision, and I would love to be able to switch to highp when necessary.

在片段着色器中要求 highp 支持在实践中有多安全?我已经在各种设备上尝试过,它适用于我尝试过的所有设备.我只想针对 Android 4.1+ 和 iOS 8+,所以如果它只是不支持它的硬壳旧设备,那么我可以接受.

How safe is it in practice to require highp support in a fragment shader? I've tried it on a variety of devices, and it works on every device I've tried. I'm only looking to target, say, Android 4.1+ and iOS 8+, so if it's only crusty old devices that don't support it then I'm fine with that.

我知道有运行时检查等.我应该做,但首先我想大致了解我们正在谈论的设备在野外的百分比.我一直无法在任何地方找到这些信息.如果只有 75% 的设备支持 highp,那么我会坚持使用 mediump.如果 99.9% 的设备支持它,highp 我们来了.

I know there are runtime checks etc. I should be doing, but first I'd just like to get an approximate feel for what percentage of devices in the wild we're talking about. I haven't been able to find this information anywhere. If only 75% of devices support highp, then I'll stick with mediump. If 99.9% of devices support it, highp here we come.

推荐答案

有一个数据库,您可以在其中查找 GL_OES_fragment_precision_high,这表明只有不到 50% 的 Android 设备在片段着色器中支持 highp.您可以检查哪些有此扩展名,哪些没有.链接

There's a database, where you can lookup GL_OES_fragment_precision_high which suggests that just under 50% of Android devices support highp in the fragment shader. You can inspect which ones have and do not have this extension. link

然而,这可能会产生误导,因为 GLES 扩展已被撤回,因此即使某些设备确实支持 highp,也可能不再报告它,因此您可以考虑至少 50% - 它可能会高很多.扩展名被 GetShaderPrecisionFormat 取代,我找不到合适的数据库.

However, that might be misleading because that GLES extension has been withdrawn, so maybe some devices don't report it anymore even though they do support highp, so you can consider that 50% a minimum - it could be a lot higher. The extension is replaced by GetShaderPrecisionFormat, and I can't find a good database for that.

使用小得多的数据集,我在 28 台设备上测试了我的游戏,其中 8 台不支持片段着色器中的 highp,包括运行 Android 4.4 的 Nexus 7 和三星 Galaxy Note II 以及运行 4.3 的三星 Galaxy S3(我拥有的其他在片段着色器中不支持 highp 的设备都是非常不起眼的品牌)

With a much smaller dataset, I have tested my game on 28 devices, 8 of which do not support highp in fragment shader, including a Nexus 7 and a Samsung Galaxy Note II running Android 4.4 and a Samsung Galaxy S3 running 4.3 (the other devices I had which didn't support highp in fragment shader were pretty obscure brands)

我很确定您的所有目标 iOS 设备都支持片段着色器中的 highp,但现在找不到任何证据来支持这一点.

I'm pretty sure all your target iOS devices do support highp in fragment shader but can't find any evidence right now to back that up.

最后,当你提到precision mediump float;"时,IMO 你应该根据具体情况选择一个精度,而不是为整个着色器选择一个级别.如果您在所有东西上都使用 highp(特别是基于颜色的操作,很容易成为 lowp),那么您将在某些 GPU 上浪费大量性能.当然,您可以设置默认精度,然后在必要时覆盖,也许这就是您正在做的,但我个人不喜欢在片段着色器中设置默认精度,然后编译器强制我明确.

Finally, as you mention "precision mediump float;", IMO you should be picking a precision on a case-by-case basis and not picking a level for the entire shader. You'd be wasting a lot of performance on some GPUs if you used highp on everything (particularly colour based operations which can easily be lowp). Of course, you can set a default precision, then override wherever necessary, and perhaps that's what you're doing, but personally I prefer not to set a default precision in fragment shaders, then the compiler forces me to be explicit.

此外,即使对于不支持它的设备,也允许在片段着色器中使用 highp,您只会获得 mediump.在很多情况下,回退行为是好的 - 高端设备获得更好的精确照明或其他任何东西,低端设备回退到不太完美但仍然可以接受的东西.

这篇关于在 iOS/Android 的片段着色器中使用 highp 可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆