Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

three.js - Does WebGL have a uniform or texture binding limit?

I'm trying to render a car's license plate in WebGL with a purple texture whose uniform name is diffTex.

  1. When I render the rest of the car with a simple black material and no textures, the drawcall that renders the license plate binds uniform 35 to diffTex and uniform 36 to specNrmMap for 6 total activeTexture() calls. The purple plate shows onscreen as expected.

enter image description here

  1. However, when I render the entire car with their own materials, textures, etc. the drawcall that renders the license plate skips diffTex, and binds uniform 35 to specNrmMap with no #36 for 5 total activeTexture() calls. The purple plate shows up white without the diffuse texture.

enter image description here

Does WebGL have a uniform limit or a texture binding limit that I might be overlooking? webglreport.com states my Max Texture Image Units is 16 in the fragment shader, and I'm only using 6, so I have 10 to spare. I'm not changing anything in the license plate material, it just works when I render the car in black without textures, and it stops working when I render the rest of the car with textures.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Uniforms do not have numbers in WebGL. Those numbers in your debugger are something assigned by the debugger. How it numbers them is up to the debugger. It could number them by querying them. If so they'd get different numbers across implementations. They'd also change if you change the shader. It could number them based on the order you use them. If so, then you setting different textures would also number them different.

Uniforms are almost always optimized out if they are not used so if you stopped using a particular uniform then again the debugger you're using might number them differently.

As for limits, as you already checked there is a limit to the number of texture units and you can bind a different texture to every unit so your 6 textures is well under the limit.

For uniforms the limit is queried via gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS) for vertex shaders and gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS) though it's unlikely you're hitting that limit because you'd get an error trying to compile the shaders.

Note: how many uniforms you can actually use from that number is defined by the packing algorithm. See this answer

As for why your code is not working you'd have to post a repo (in the question itself) for us to figure that out.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...