2

I have a fragment shader which is failing to compile in a WebGL 2 context:

#version 300 es
precision highp float;
uniform isampler2D tex_in;
out vec2 outColor;
void main() {
    outColor = vec2(0.0, 0.0);
}

When I gl.compileShader this shader, gl.getShaderParameter(glFragmentShader, GL.COMPILE_STATUS) returns false. If I change isampler2D to sampler2D, the compile succeeds instead.

According to the webgl 2 quick reference, isampler2D is a supported keyword. What am I doing wrong?

Craig Gidney
  • 17,763
  • 5
  • 68
  • 136

2 Answers2

2

You need to specify a precision for the sampler:

uniform highp isampler2D tex_in;

Note the highp.

Craig Gidney
  • 17,763
  • 5
  • 68
  • 136
1

Rather than just point out the specific issue it's just a good practice to print the shader log when gl.getShaderParameter(shader, GL.COMPILE_STATUS) is false

example

const gl = document.createElement('canvas').getContext('webgl2');
const s = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(s, `#version 300 es
precision highp float;
uniform isampler2D tex_in;
out vec2 outColor;
void main() {
    outColor = vec2(0.0, 0.0);
}`);
gl.compileShader(s);
if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) {
  throw new Error(gl.getShaderInfoLog(s));
}

prints

Uncaught Error: ERROR: 0:3: 'isampler2D' : No precision specified

So the issue is you didn't specify a precision

gman
  • 100,619
  • 31
  • 269
  • 393