Reputation: 19710
I'm currently using the following fragment shader for basic black and white effects:
uniform sampler2D texture;
uniform float time_passed_fraction;
//gl_Color: in the fragment shader, the interpolated color passed from the vertex shader
void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
vec3 texel = pixel .rgb;
gl_FragColor = pixel;
float bw_val = max(texel.r,max(texel.g,texel.b));
gl_FragColor.r = pixel.r * (1-time_passed_fraction) + bw_val * time_passed_fraction;
gl_FragColor.g = pixel.g * (1-time_passed_fraction) + bw_val * time_passed_fraction;
gl_FragColor.b = pixel.b * (1-time_passed_fraction) + bw_val * time_passed_fraction;
gl_FragColor.a = pixel.a;
// multiply it by the color
//gl_FragColor = gl_Color * pixel;
}
This fragment shader works perfectly on my PC. But I'm getting some feedback from people that they're getting the following errors:
ERROR: 0:17: '-' : wrong operand types no operation '-' exists that takes a left-hand operand of type 'const int' and a right operand of type 'uniform float' (or there is no acceptable conversion)
ERROR: 0:17: '*' : wrong operand types no operation '*' exists that takes a left-hand operand of type 'float' and a right operand of type 'const int' (or there is no acceptable conversion)
ERROR: 0:18: '-' : wrong operand types no operation '-' exists that takes a left-hand operand of type 'const int' and a right operand of type 'uniform float' (or there is no acceptable conversion)
ERROR: 0:18: '*' : wrong operand types no operation '*' exists that takes a left-hand operand of type 'float' and a right operand of type 'const int' (or there is no acceptable conversion)
ERROR: 0:19: '-' : wrong operand types no operation '-' exists that takes a left-hand operand of type 'const int' and a right operand of type 'uniform float' (or there is no acceptable conversion)
This seems to allude to some type errors, but I'm not understanding where the inconsistencies are coming from. Could someone perhaps explain?
Note: line 17 is this line) gl_FragColor.r = pixel.r * (1-time_passed_fraction) + bw_val * time_passed_fraction;
Upvotes: 3
Views: 1593
Reputation: 52167
The missing #version
directive at the beginning of your shader implies #version 110
which as Colonel Thirty Two noted does not support implicit int
-> float
conversion.
Note that typeof(1)
== int
!= float
== typeof(1.0)
.
So your lines like this:
gl_FragColor.r = pixel.r * (1-time_passed_fraction) + bw_val * time_passed_fraction;
^ nope
Need to be:
gl_FragColor.r = pixel.r * (1.0-time_passed_fraction) + bw_val * time_passed_fraction;
^^^ fix'd
Upvotes: 6