title: Is it possible to access pre-set textureunits within a shader?
body: <p><strong>TL;DR:</strong> I've activated and bound textures to textureunits 1-4 and now I wish to use them within shaders without using a program specific uniform position. Is it possible to read data from textures using the &quot;global&quot; texture units?</p>
  <p>I'm having a bit of a hard time understanding how to access textures in webgl. Here in <a href="https://webglfundamentals.org/webgl/lessons/webgl-texture-units.html" rel="nofollow noreferrer">this tutorial on textures</a> it says &quot;<em>Texture units are a global array of references to textures.</em>&quot;, and this sounds great. I've bound my textures using</p>
  <pre><code>gl.activeTexture(gl.TEXTURE1 + i);
  gl.bindTexture(gl.TEXTURE_2D, tex);
  </code></pre>
  <p>where <code>i</code> is the index of the newly created texture and <code>tex</code> is the texture itself.</p>
  <p>But it doesn't give an example of how to access the texture within a shader using this global reference. In <a href="https://webglfundamentals.org/webgl/lessons/webgl-2-textures.html" rel="nofollow noreferrer">this tutorial from the same page</a> it does give an example of how to access the textures from within a shader, but only when using an uniform position (much like how an attribute is accessed), which requires a program (and thus, removing the global aspect, in a way, since it's dependent on the program to be accessed). In <a href="https://webglfundamentals.org/webgl/lessons/webgl-3d-textures.html" rel="nofollow noreferrer">this preceding tutorial</a> any details of how to actually set up the texture &quot;u_texture&quot; is skipped altogether.</p>
  <p>In short, I have two programs, and I wish to use textures globally in both of them without having to getUniformLocation on each program, if it's possible to do so. Seeing the promises of texture units, I thought I could use them, but I don't know how to actually do something like</p>
  <pre><code>sampler2D textureUnit2;
  </code></pre>
  <p>within the shaders. Is this possible? Am i confusing the implementation of the textureUnits with the practicality of using them?</p>
  <p>Many thanks!</p>