0

Sorry for the bad title, but I couldn't come up with anything better.

I have the following fragment shader code:

#version 430 core
out vec4 color;
uniform vec4 coords; //set to {1.f,1.f,1.f,1.f}
uniform vec3 values; //{time, a, b} 
void main() {
  float time = values[0]; 
  float c;
  c = coords[1]; //green
  c = coords[1]*0.5f; //dark green
  c = sin(time); //works like it should. moves between black and green.
  c = time*1.0f; //quickly becomes green
  c = 1.0f*coords[1]; //green
  c = time*coords[1]; //black.
  color = vec4(0,c,0,1);
}

However, I can't for the life of me manage to combine the variable time and any element in coords. It just becomes black. I.e. time*coords[1] never produces any color, even though coords[1] is always 1.0f and time quickly becomes large.

Edit: There are no errors when loading the shader.

Grisungen
  • 333
  • 2
  • 7
  • Keep in mind the time will most probably be way more than 1.0f! But I doubt this is than problem. You are only asking about the `time*coords[1]` here, correct? – fordcars Feb 19 '16 at 17:45
  • What's suspicious is that the not working case is the only one where both uniforms are active. Better double-check your uniform setting code. – derhass Feb 19 '16 at 20:48

1 Answers1

1

In your code:

uniform vec3 values; //{time, a, b} 

What type of value is time? Is it a real time value (i.e. integer) from the OS, or is is a computed parameter? Is it integer-based when you set the uniform? If this is the case, values that go way out of the unit range (i.e. 0.0 - 1.0) can have unpredictable results in some aspects of GL shaders. Double check the values that you're sending via glUniform* (That's usually been the source of problem for me).

yapdog
  • 106
  • 4