<p>Using the same name is exactly how you tell OpenGL that you want the value passed through from vertex to fragment.</p>

<p>You say "we already hand the color value from vertex shader to fragment shader", but that's not correct. Usually, the only value that's passed between shaders <em>automatically</em> is position, and that's only because it feeds into the GPU's rasterization hardware to draw the triangle on the screen.</p>

<p>Any other values such as color, normal, texture coordinates, etc. that you want passed between shader stages have to be explicitly hooked up by the shader author. And the way you do that in GLSL is to create an <code>out</code> variable in one stage, and an <code>in</code> variable in the next stage, with the same name.</p>

CC BY-SA 3.0
2016-01-09T20:12:41.833Z
2016-01-09T20:12:41.833Z
Nathan Reed
<p>Because you may want to pass more than one attribute through to the fragment shader. 2 which are essential are normal vector and the texture coordinates once you start doing lighting and textured meshes.</p>

<p>You can in newer openGL versions give a numbered location to the attributes you pass through using <code>layout(location=1)</code>. Then the names don't have to match.</p>

CC BY-SA 3.0
2016-01-09T23:16:32.433Z
2016-01-09T23:16:32.433Z
ratchet freak
<p>Why do I need to specify the same name for color input in fragment shader and output color from vertex shader?</p>

<pre><code>//Vertex shader
out vec3 vertex_color;

void main()
{
    vertex_color=vec3(1.0,0.0,0.0);
}
</code></pre>



<pre><code>//Fragment shader 
in vec3 vertex_color;
out vec4 frag_color;

void main()
{
    frag_color=vec4(vertex_color,1.0);
}
</code></pre>

<p>Since we already hand the color value from vertex shader to fragment shader, why do we need same names?</p>

<opengl><shader><glsl>
OpenGL vertex color
videogamechef
# OpenGL vertex color

(Asked by: username_0 on 2016-01-09)

Why do I need to specify the same name for color input in fragment shader and output color from vertex shader?

```
//Vertex shader
out vec3 vertex_color;

void main()
{
    vertex_color=vec3(1.0,0.0,0.0);
}

```

```
//Fragment shader 
in vec3 vertex_color;
out vec4 frag_color;

void main()
{
    frag_color=vec4(vertex_color,1.0);
}

```

Since we already hand the color value from vertex shader to fragment shader, why do we need same names?

**Tags:** opengl, shader, glsl


---

## 2 answers

### Answer by username_1 on 2016-01-09. Score: 4

Using the same name is exactly how you tell OpenGL that you want the value passed through from vertex to fragment.

You say "we already hand the color value from vertex shader to fragment shader", but that's not correct. Usually, the only value that's passed between shaders *automatically* is position, and that's only because it feeds into the GPU's rasterization hardware to draw the triangle on the screen.

Any other values such as color, normal, texture coordinates, etc. that you want passed between shader stages have to be explicitly hooked up by the shader author. And the way you do that in GLSL is to create an `out` variable in one stage, and an `in` variable in the next stage, with the same name.


---

### Answer by username_2 on 2016-01-09. Score: 3

Because you may want to pass more than one attribute through to the fragment shader. 2 which are essential are normal vector and the texture coordinates once you start doing lighting and textured meshes.

You can in newer openGL versions give a numbered location to the attributes you pass through using `layout(location=1)`. Then the names don't have to match.


---

