<p><em>I don't have enough rep to comment :(</em></p>

<p>Hi,</p>

<p>It looks like with (2), fs_in.TexCoords is == vec2(0.0,0.0). Do you keep both <strong><em>in VS_OUT {}/ out VS_OUT {}</em></strong> and <strong><em>out vec2/in vec2</em></strong> ? If so, it's possible that as both have the same name (TexCoords) the compiler is confused. Try using only one of the two options.</p>

CC BY-SA 3.0
2017-12-15T11:46:20.380Z
I tried it, but the result was same. 
You mentioned fs_in.TexCoords is == vec2(0.0,0.0)
but as you can see, the glass color is brown and there are some shading, not perfect black.
Maybe it meant that the entire color is darkened by some reason.
shashack
CC BY-SA 3.0
2017-12-15T11:56:11.983Z
To me it looks that there are multiple sub meshes (each one with a set of uvs) Is that right? If that is the case, then you are getting 0,0 but for other reason then.
Nacho
CC BY-SA 3.0
2017-12-15T12:09:46.700Z
You're right. but I don't know the reason. The two pair code are same? no?
shashack
CC BY-SA 3.0
2017-12-15T12:16:05.247Z
Yeah both should work with gl version 330. You could launch your project with RenderDoc or Nvidia Nsight maybe that gives you a clew.
Nacho
CC BY-SA 3.0
2017-12-15T20:57:17.513Z
Oh my god, I found my mistake. I duplicate the same name file other folder, and executed the code. the pairs are same. Sorry to bother you..
shashack
CC BY-SA 3.0
2017-12-16T20:21:07.167Z
Good you found it!
Nacho
CC BY-SA 3.0
2017-12-15T11:30:10.510Z
2017-12-15T11:30:10.510Z
Nacho
<p>I'm doing a project with assimp.</p>

<p>I got confused with the weird situation for me.
I think the both code are exactly same, but the result is different.</p>

<p>Why the codes act differently?</p>

<p>(vertex shader)</p>

<pre><code>#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoords;

// declare an interface block; see 'Advanced GLSL' for what these are.
out VS_OUT {
    vec2 TexCoords;
} vs_out;

out vec2 TexCoords;

uniform mat4 model;
uniform mat4 projection;
uniform mat4 view;


void main()
{
    TexCoords = aTexCoords; ----(1)
    //vs_out.TexCoords = aTexCoords; ----(2) 
    gl_Position = projection * view * model * vec4(aPos, 1.0);
}
</code></pre>

<p>(fragment shader)</p>

<pre><code>#version 330 core
out vec4 FragColor;

in VS_OUT {
    vec2 TexCoords;
} fs_in;

in vec2 TexCoords;

uniform sampler2D texture_diffuse1;
uniform vec3 lightPos;
uniform vec3 viewPos;

void main()
{
    FragColor = vec4(texture(texture_diffuse1, TexCoords).rgb, 1.0); ----(1)
    //FragColor = vec4(texture(texture_diffuse1, fs_in.TexCoords).rgb, 1.0); ----(2)
}
</code></pre>

<p>If I use the code above, the result is as follows</p>

<p><a href="https://i.sstatic.net/A70UG.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/A70UG.png" alt="enter image description here"></a></p>

<p>but, instead of (1) pair, if I use the pair (2), then the result is strange.</p>

<p><a href="https://i.sstatic.net/OjMQb.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/OjMQb.png" alt="enter image description here"></a></p>

<p>Why it happened?</p>

CC BY-SA 3.0
2017-12-15T12:23:05.730Z
if you use (2), do you comment out the first line of your vertex shader (in the main function, the TexCoords assignement)?
because if you do, i'm not sure this is legal - you'd have an out variable that never had a value assignment.
Tare
CC BY-SA 3.0
2017-12-15T12:30:37.447Z
I tried both of them. And all result were same.
shashack
CC BY-SA 3.0
2017-12-15T20:58:28.127Z
I added comment the below answer. I'm really sorry about that
shashack
<opengl><shader>
What's the difference between two code in shader?
shashack
# What's the difference between two code in shader?

(Asked by: username_0 on 2017-12-15)

I'm doing a project with assimp.

I got confused with the weird situation for me.
I think the both code are exactly same, but the result is different.

Why the codes act differently?

(vertex shader)

```
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoords;

// declare an interface block; see 'Advanced GLSL' for what these are.
out VS_OUT {
    vec2 TexCoords;
} vs_out;

out vec2 TexCoords;

uniform mat4 model;
uniform mat4 projection;
uniform mat4 view;

void main()
{
    TexCoords = aTexCoords; ----(1)
    //vs_out.TexCoords = aTexCoords; ----(2) 
    gl_Position = projection * view * model * vec4(aPos, 1.0);
}

```

(fragment shader)

```
#version 330 core
out vec4 FragColor;

in VS_OUT {
    vec2 TexCoords;
} fs_in;

in vec2 TexCoords;

uniform sampler2D texture_diffuse1;
uniform vec3 lightPos;
uniform vec3 viewPos;

void main()
{
    FragColor = vec4(texture(texture_diffuse1, TexCoords).rgb, 1.0); ----(1)
    //FragColor = vec4(texture(texture_diffuse1, fs_in.TexCoords).rgb, 1.0); ----(2)
}

```

If I use the code above, the result is as follows

[![enter image description here](https://i.sstatic.net/A70UG.png)](https://i.sstatic.net/A70UG.png)

but, instead of (1) pair, if I use the pair (2), then the result is strange.

[![enter image description here](https://i.sstatic.net/OjMQb.png)](https://i.sstatic.net/OjMQb.png)

Why it happened?

**Tags:** opengl, shader

> **Comments:**
> **username_1**: if you use (2), do you comment out the first line of your vertex shader (in the main function, the TexCoords assignement)? because if you do, i'm not sure this is legal - you'd have an out variable that never had a value assignment.  
> **username_0**: I tried both of them. And all result were same.  
> **username_0**: I added comment the below answer. I'm really sorry about that  

---

## 1 answers

### Answer by username_2 on 2017-12-15. Score: 1 | Accepted answer

*I don't have enough rep to comment :(*

Hi,

It looks like with (2), fs\_in.TexCoords is == vec2(0.0,0.0). Do you keep both ***in VS\_OUT {}/ out VS\_OUT {}*** and ***out vec2/in vec2*** ? If so, it's possible that as both have the same name (TexCoords) the compiler is confused. Try using only one of the two options.

> **Comments:**
> **username_0**: I tried it, but the result was same.  You mentioned fs_in.TexCoords is == vec2(0.0,0.0) but as you can see, the glass color is brown and there are some shading, not perfect black. Maybe it meant that the entire color is darkened by some reason.  
> **username_2**: To me it looks that there are multiple sub meshes (each one with a set of uvs) Is that right? If that is the case, then you are getting 0,0 but for other reason then.  
> **username_0**: You're right. but I don't know the reason. The two pair code are same? no?  
> **username_2**: Yeah both should work with gl version 330. You could launch your project with RenderDoc or Nvidia Nsight maybe that gives you a clew.  
> **username_0**: Oh my god, I found my mistake. I duplicate the same name file other folder, and executed the code. the pairs are same. Sorry to bother you..  
> **username_2**: Good you found it!  

---

