0
\$\begingroup\$

I have a webgl shader that uses multiple render targets. This one only renders to one texture for now. However, I plan that this shader shall render more. However, as soon as I add layout qualifiers, and #version 300 es, my shader stops working, because I get a message saying it is an invalid program.

  #version 300 es

  uniform mat4 viewProjectionMatrix;

  attribute vec3 vertex;
  attribute vec2 uv;

  varying vec2 vUv;

  void main() {
    gl_Position = viewProjectionMatrix * vec4(vertex, 1);
    vUv = uv;
  }

Fragment shader

  #version 300 es

  precision mediump float;

  layout(location = 0) out vec4 color;

  uniform sampler2D textureId;

  varying vec2 vUv;

  void main() {
    color = texture2D(textureId, vUv);
  }
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

It seems that you have a WebGL version 1 (OpenGL ES 2.0) and that's why it does not accept OpenGL ES 3.x features.

Review the code where you request the context for WebGL

var gl = canvas.getContext("webgl2");   // 2!

If you are requesting WebGL2, check that there are no whitespaces before #version 300 es.

You can find additional guidance here.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.