我可以在 webgl 片段着色器中使用多少个纹理? [英] How many textures can I use in a webgl fragment shader?
问题描述
简单的问题,但我在任何地方的规范中都找不到答案.我可能在某处遗漏了明显的答案.
Simple question but I can't find the answer in a specification anywhere. I'm probably missing the obvious answer somewhere.
我可以在 WebGL 片段着色器中一次使用多少个纹理?如果它是可变的,那么假设 PC 使用的合理数字是多少?(对移动设备不太感兴趣).
How many textures can I use at once in a WebGL Fragment shader? If it's variable, what is a reasonable number to assume for PC use? (Not so interested in mobile).
我的一个着色器中至少需要 23 个,所以想知道在我开始编写代码之前我是否能够做到这一点,或者我是否需要进行多次传递.
I need at least 23 in one of my shaders so want to know if I'll be able to do that before I start work on the code or if I'll need to do multiple passes.
推荐答案
我很确定你可以通过
var maxTexturesInFragmentShader = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
WebGL (OpenGL ES 2.0) 片段着色器只需要最少 8 个.
WebGL (OpenGL ES 2.0) only requires 8 minimum for fragment shaders.
请注意,您可以访问的纹理数量与您可以访问 1 个纹理的次数是分开的.因此,例如,如果您想仅使用 1 个纹理单元访问 2 个纹理,则组合这些纹理并调整您的 UV 坐标.例如,将 2 个纹理 [A] 和 [B] 的内容并排放入一个纹理 [AB] 中,然后
Note that the number of textures you can access is separate from the amount of times you can access 1 texture. Therefore, for example, if you wanted to access 2 textures using only 1 texture unit then combine the textures and adjust your UV coords. So for example put the contents of 2 textures [A] and [B] side by side into one texture [AB] and then
vec4 colorFromTexA = texture2D(samplerAB, uvForTexA * vec2(0.5, 1.0));
vec4 colorFromTexB = texture2D(samplerAB, uvForTexB * vec2(0.5, 1.0) + vec2(0.5, 0.0));
当然,您可能需要为无 mips 等设置过滤...
Of course you probably need to turn set filtering for no mips etc...
这篇关于我可以在 webgl 片段着色器中使用多少个纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!