0

I have never had any problems passing variables from vertex shader to fragment shader. But today, I added a new "out" variable in the vs, and a corresponding "in" variable in the fs. GLSL says the following:

Shader Program: The fragment shader uses varying tbn, but previous shader does not write to it.

Just to confirm, here's the relevant part of the VS:

#version 330 core

layout(location = 0) in vec4 position;
layout(location = 1) in vec2 uv;

// plus other layout & uniform inputs here

out DATA
{
    vec2 uv;
    vec3 tangentViewDir;
    mat3 tbn;
} vs_out;

void main()
{
    vs_out.uv       = uv;
    vs_out.tangentViewDir = vec3(1.0);
    vs_out.tbn = mat3(1.0);

    gl_Position     = sys_ProjectionViewMatrix * sys_ModelMatrix * position;
}

And in the FS, it is declared as:

in DATA
{
    vec2 uv;
    vec3 tangentViewDir;
    mat3 tbn;
} fs_in;

Interestingly, all other varyings, like "uv" and all, work. They are declared the same way.

Also interesting: Even though GLSL says the variable isn't written to - it still recognizes the changes when I write to it, and displays those changes.

So is it just a false warning or bug? Even though it tells me otherwise, the value seems to be passed correctly. Why do I receive this warning?

GDN9
  • 329
  • 3
  • 15
  • 1
    Can you give us a [mcve]? – HolyBlackCat Sep 08 '18 at 20:52
  • Hi guys, thanks for the responses, I've added the simplified version with the relevant info to the op. The shader-log doesn't complain about vs_out.uv, only the other two variables in "out DATA" – GDN9 Sep 08 '18 at 21:13
  • 1
    It would help if you created an actual MCVE (see the link above), just so we can rule out e.g. accidentally attaching an incorrect vertex shader. – HolyBlackCat Sep 08 '18 at 21:24
  • You pointed me in the right direction, error found - it was indeed a shader mismatch! Posted the answer for reference, should anyone face similar issues in the future. Thank you! – GDN9 Sep 08 '18 at 22:18

1 Answers1

0

HolvBlackCat pointed me in the right direction - it was indeed a shader mismatch!

I had 2 shader programs, same FS in both, but different VSs, and I forgot to update the outputs of the 2nd VS to match the output layout of the first, so that they both work with the same FS!

Ouch, I guess now that I've run into this error, lesson learnt.

Thank you HolvBlackCat!

GDN9
  • 329
  • 3
  • 15