Search code examples
openglglslfragment-shadervertex-shader

Fragment Shader IN variable causes nothing to appear


I'm trying to send a variable from my vertex shader to my fragment shader, but when I include a specific the in variable in an if statement, it causes nothing to show up. Removing the if statement causes everything to appear and work normally. What's weird is that if statement isn't actually doing anything and that no errors are being generated by the fragment shader.

I have several other variables I'm sending from my vertex shader to my fragment shader but this one specifically is the only one causing issues. I know type is being set correct because I'm using it for something else that's working correctly.

vertex shader

#version 150

in float type;
out int roofBool;

void main(void)
{
  textureXY = texcoords;
  roofBool = 0;
  if(type == 2){
    roofBool = 1;
  }
}

fragment shader

#version 150

in int roofBool;

// The output. Always a color
out vec4 fragColor;

void main() 
{  
  int a = 0;
  if(roofBool == 1){ //removing this causes everything to work
    a = 2;
  }
}

Solution

  • int variables cannot be interpolated by the GL. You must declare both the output and the corresponding input with the flat qualifier`.

    From the behavior you described, it seems like you are not properly checking the compile and link status of your shaders/programs, and don't seem to retrieve the compiler/linker info log. You would vert likely have gotten a useful error message if you did.