我可以避免在webgl中进行纹理渐变计算吗? [英] Can I avoid texture gradient calculations in webgl?

查看:178
本文介绍了我可以避免在webgl中进行纹理渐变计算吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个webgl/three.js应用程序,该应用程序广泛使用纹理缓冲区来在遍之间传递数据并存储数据数组.这些都没有用于mipmap.我们很容易就能防止生成Mipmap:在three.js级别上,我们将min和mag过滤器设置为NearestFilter,并将generateMipmaps设置为false.

We have a webgl/three.js application that makes extensive use of texture buffers for passing data between passes and for storing arrays of data. None of these has any use for mipmaps. We are easily able to prevent mipmap generation: at the three.js level we set min and mag filters to NearestFilter, and set generateMipmaps false.

但是,着色器在编译时不知道没有映射.使用ANGLE进行编译时,我们会收到许多警告消息:

However, the shaders do not know at compile time that there is no mipmapping. When compiled using ANGLE we get a lot of warning messages:

警告X4121:必须将基于梯度的操作移出流控制,以防止发散.通过使用非梯度操作可以提高性能

我已重新编码,以便避免(可选)围绕此类查找的流程. 在我的Windows/NVidia计算机上,使用条件流可以提高性能,并且不会引起任何视觉问题(但会导致出现消息).

I have recoded so that the flow around such lookups is (optionally) avoided. On my Windows/NVidia machine using the conditional flows improves performance and does not cause any visual issues (but does cause the messages).

我不希望纹理查找是基于梯度的操作.我想做的是编写着色器,使它们在编译时知道没有决定要进行.这应该(略微地)提高性能,并使消息消失.但是,我看不到在GSL 2(由webgl使用)的GLSL中执行此操作的任何方法.可以在以后的版本中使用textureLodOffset()和其他各种方式来完成此操作.我可以看到的第2级唯一控件是texture2D()的bias选项,但这不是绝对值,因此不能解决问题.所以,最后...

I don't want the texture lookups to be gradient-based operations. What I would like to do is to write the shaders in such a way that they know at compile time that there is no decision to be made; which should (marginally) improve performance and also make the messages go away. However, I cannot see any way to do this in GLSL for GLES 2 (as used by webgl). It can be done in later versions with textureLodOffset() and various other ways. The only control in level 2 I can see is the bias option on texture2D(), but that is a bias not an absolute value and so does not resolve the issue. So, finally ...

问题:您知道在WEBGL级别GLSL着色器中阻止lod计算的任何方法吗?

推荐答案

您可以尝试确保:

  • 使用gl_FragCoord代替用户更改
  • NEAREST设置在texImage2d之前,而不是在
  • 之后
  • Using gl_FragCoord instead of a user varying
  • NEAREST is set before texImage2d, instead of after

这篇关于我可以避免在webgl中进行纹理渐变计算吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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