Saeid Nourian
Saeid Nourian

Reputation: 1778

a simple compare of vec4.x > 5

I cannot compile the following fragment shader:

uniform vec3 color;
uniform sampler2D tDiffuse;
varying vec2 vUv;

void main() {
  vec4 texel = texture2D( tDiffuse, vUv );
  vec3 luma = vec3( 0.299, 0.587, 0.114 );
  float v = dot( texel.xyz, luma );
  if (texel.x > 5)
    gl_FragColor = vec4( v * color, texel.w );
  else
    gl_FragColor = texel;
}

If I change (texel.x > 5) to (1 > 5) it works fine. But somehow texel.x causes a compile error. Does anyone see an obvious problem with this code?

Upvotes: 0

Views: 93

Answers (1)

Volune
Volune

Reputation: 4339

texel.x is a float, 5 is an int, you can't compare both directly.

Try to write 5.0 instead:

if (texel.x > 5.0)

Upvotes: 3

Related Questions