1
votes

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.

1

1 Answers

3
votes

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.