Search code examples
openglglslshadervertex-shader

GLSL Error: "Type should be float or int"


I am trying to compile a shader, and it is compiling on Intel HD on one PC, but not on AMD drivers on another PC.

Vertex Shader:

#version 330
precision mediump float;
precision lowp sampler2D;

uniform mat4 ProjectionMatrix;
uniform mat4 ModelViewMatrix;
uniform mat4 WorldViewMatrix;
in vec3 position;
in vec2 TexCoord;
out vec2 texCoord;

void main() {
    texCoord = TexCoord;
    gl_Position = ProjectionMatrix * ModelViewMatrix * WorldViewMatrix * vec4(position, 1);
}

Fragment Shader:

#version 330
precision mediump float;
precision lowp sampler2D;

uniform vec4 TextureHueColor;
uniform sampler2D TextureUnit;
in vec2 texCoord;
out vec4 gl_FragColor;

void main() {
    gl_FragColor = texture(TextureUnit, texCoord) * TextureHueColor;
}

On AMD drivers, I am getting:

Vertex shader failed to compile with the following errors:
ERROR: 0:3: error(#228) Type should be float or int
ERROR: error(#273) 1 compilation errors.  No code generated

I am a beginner, and have no idea what is wrong with this shader, to me it looks fine. Anyone spot what's wrong?


Solution

  • Default precision qualifiers in GLSL 3.30 cannot be applied to sampler types. Or any type other than int or float.

    Also, FYI: when using desktop GLSL (as opposed to GLSL ES), the precision qualifiers accomplish nothing. They're ignored; they exist solely for compatibility with GLSL ES shaders.