title: glGetUniformLocation returns -1 even though I used the variable in shader
body: <p>It seems that the glsl compiler optimizes unused variable (remove).
  In my case I used the variable but the <code>glGetUniformLocation</code> returns -1</p>
  
  <pre><code>rgbScene.addRenderStage(
      [&amp;obj = std::as_const(model)](Camera* cam) {
  
      auto&amp; mesh = std::get&lt;Mesh&gt;(obj);
      auto&amp; program = std::get&lt;ShaderProgram&gt;(obj);
  
      glUseProgram(program);
  
      glBindVertexArray(mesh.getData&lt;VAO&gt;());
      int loc;
      glUniformMatrix4fv(
          loc = glGetUniformLocation(program, "proj_matrix"),
          1, GL_FALSE,
          glm::value_ptr(cam-&gt;getProjectionMatrix())
      );
  
      glUniformMatrix4fv(
          loc = glGetUniformLocation(program, "view_matrix"),
          1, GL_FALSE,
          glm::value_ptr(cam-&gt;getViewMatrix())
      );
  
      glUniformMatrix4fv(
          loc = glGetUniformLocation(program, "model_matrix"),
          1, GL_FALSE,
          glm::value_ptr(mesh.getModelMatrix())
      );
  
      glUniform3fv(
          loc = glGetUniformLocation(program, "light_direction"),
          1, glm::value_ptr(-(cam-&gt;getForward()))
      );
  
      glEnableVertexAttribArray(0);
      glBindBuffer(GL_ARRAY_BUFFER, mesh.getData&lt;VertexData&gt;());
      glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
  
      glEnableVertexAttribArray(1);
      glBindBuffer(GL_ARRAY_BUFFER, mesh.getData&lt;NormalData&gt;());
      glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
  
      glDrawArrays(GL_TRIANGLES, 0, mesh.getSize());
  
      glDisableVertexAttribArray(1);
      glDisableVertexAttribArray(0);
  });
  </code></pre>
  
  <p>I checked variable <code>loc</code> by debuging line by line in Visual Studio 2019 and at the last <code>glGetUniformLocation</code> returns -1</p>
  
  <p>here's my vertex shader code</p>
  
  <pre><code>#version 460 core
  
  uniform mat4 proj_matrix;
  uniform mat4 view_matrix;
  uniform mat4 model_matrix;
  uniform vec3 light_direction;
  
  layout(location = 0) in vec3 pos;
  layout(location = 1) in vec3 normal;
  
  out VS_OUT
  {
      vec3 N;
      vec3 L;
      vec3 V;
  } vs_out;
  
  void main(void)
  {
      vec4 P = view_matrix * model_matrix * vec4(pos, 1.0);
  
      vs_out.N = mat3(view_matrix * model_matrix) * normal;
      vs_out.L = mat3(view_matrix) * (-light_direction);
      vs_out.V = -P.xyz;
  
      gl_Position = proj_matrix * P;
  }
  </code></pre>
  
  <p>I tried changing the variable name, different order... but cannot fixed this problem</p>
  
  <p>Is there any other rules for uniform variable in shader??</p>
  
  <p>-- Edit --
  for fragment shader,</p>
  
  <pre><code>#version 460 core
  
  layout (location = 0) out vec4 color;
  
  in VS_OUT
  {
      vec3 N;
      vec3 L;
      vec3 V;
  } fs_in;
  
  uniform vec3 diffuse_albedo = vec3(0.8, 0.3, 0.2);
  uniform vec3 specular_albedo = vec3(0.7);
  uniform float specular_power = 128.0;
  
  void main(void)
  {
      vec3 N = normalize(fs_in.N);
      vec3 L = normalize(fs_in.L);
      vec3 V = normalize(fs_in.V);
  
      vec3 R = reflect(-L, N);
  
      vec3 diffuse = max(dot(N, L), 0.0) * diffuse_albedo;
      vec3 specular = pow(max(dot(R, V), 0.0), specular_power) * specular_albedo;
  
      color = vec4(diffuse + specular, 1.0);
  
      // color = vec4(1.0,1.0, 1.0, 1.0);
  }
  </code></pre>