2

In the three.js example "webgl_rtt.html" one can see:

    varying vec2 vUv;

    void main() {

        vUv = uv;
        gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );

    }

webgl_rtt.html

"uv" is not defined in any .js file in this example, nor in three.js. Obviously it is part of WebGL, but where is it defined, where is the documentation about it, and what other WebGL vars exist???

user5515
  • 301
  • 2
  • 18
  • How did you conclude that it’s not defined in three.js? – pailhead Mar 23 '18 at 07:45
  • I was looking in three.js for other kinds of definition, I didn't know vars could be defined like: this.defaultAttributeValues = { 'color': [ 1, 1, 1 ], 'uv': [ 0, 0 ], 'uv2': [ 0, 0 ] }; – user5515 Mar 23 '18 at 17:56
  • I agree this is not a very obvious topic in the three.js docs when coming from native WebGL programming. Could probably use a paragraph in the manual to point people in the right direction to docs regarding custom shaders and built-in uniform/attributes. – maeneak Jun 13 '19 at 02:32

1 Answers1

5

uv is not part of WebGL. Since the posted vertex shader is used to create a THREE.ShaderMaterial, uv is provided as a default attribute by three.js (see section Built-in attributes and uniforms).

They are listed in the WebGLProgram docs.

2pha
  • 9,798
  • 2
  • 29
  • 43
Mugen87
  • 28,829
  • 4
  • 27
  • 50
  • So what exactly is UV (I know it's used for texture coordinates), but is this like an X & Y of the current current coordinate in the vertex shader for the pixel path of what it's drawing from one vertex to the next? Why do we see this commonly sent over to the fragment shader? – Joseph Astrahan Apr 05 '23 at 07:52
  • Texture coordinates just define what position in the texture should be sampled. That's the reasons why you see uv data in the fragment shader because texture sampling mainly happens in this stage. – Mugen87 Apr 05 '23 at 08:10