How many textures can I use in a webgl fragment shader?

匿名 (未验证) 提交于 2019-12-03 09:10:12

问题:

Simple question but I can't find the answer in a specification anywhere. I'm probably missing the obvious answer somewhere.

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).

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.

回答1:

I'm pretty sure you can find out with

var maxTexturesInFragmentShader = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS); 

WebGL (OpenGL ES 2.0) only requires 8 minimum for fragment shaders.

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)); 

Of course you probably need to turn set filtering for no mips etc...



回答2:

You can find the answer at http://webglstats.com/webgl/parameter/MAX_TEXTURE_IMAGE_UNITS

It seems you are out of luck as the stats suggest that most only have 16.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!