<p>From the error message the problem is in line 24 of your fragment shader:</p>

<pre><code>vec3 transformedNormal = normalize(normalMatrix * normal);
</code></pre>

<p><code>normalMatrix</code> is a <code>mat4</code> but <code>normal</code> is a <code>vec3</code>. </p>

<p>The solution is to make normalMatrix a mat3 instead.</p>

CC BY-SA 3.0
2016-01-08T15:36:28.617Z
I do not get matrix errors anymore but It just wont compile. I have posted the original working code for a single light. How should I approach it?
eneko
CC BY-SA 3.0
2016-01-08T15:22:36.260Z
2016-01-08T15:22:36.260Z
ratchet freak
<p>I have wirtten a fragment shader that works just fine with a single light. Now I am trying to adpat it to work with 8 lights, the implement it in Processing. Clearly I am doing something wrong in the math and I cannot see what it is... I have read other posts about this and try to adapt the answer to my problem, no luck though...</p>

<p><a href="https://i.sstatic.net/9u1P9.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/9u1P9.png" alt="enter image description here"></a></p>

<pre><code>////Fragment/////

    #ifdef GL_ES
precision mediump float;
precision mediump int;
#endif

varying vec4 vertColor;
varying vec3 ecNormal;
varying vec3 lightDir;

void main() {  
  vec3 direction = normalize(lightDir);
  vec3 normal = normalize(ecNormal);
  float intensity = max(0.0, dot(direction, normal));
  gl_FragColor = vec4(intensity, intensity, intensity, 1) * vertColor;
}

////vertex/////

        #define PROCESSING_LIGHT_SHADER

uniform mat4 modelview;
uniform mat4 transform;
uniform mat3 normalMatrix;

uniform vec4 lightPosition;
uniform vec3 lightNormal;

attribute vec4 vertex;
attribute vec4 color;
attribute vec3 normal;

varying vec4 vertColor;
varying vec3 ecNormal;
varying vec3 lightDir;

void main() {
  gl_Position = transform * vertex;    
  vec3 ecVertex = vec3(modelview * vertex);  

  ecNormal = normalize(normalMatrix * normal);
  lightDir = normalize(lightPosition.xyz - ecVertex);  
  vertColor = color;
}
</code></pre>

CC BY-SA 3.0
2016-01-08T14:33:11.280Z
show us what your output is and describe what you expect it to be
ratchet freak
CC BY-SA 3.0
2016-01-08T14:44:49.503Z
It just wont compile. It is a version of a basic pixel ilumination shader. The previous version just supports 1 light. I am trying to adapt it so that it can process 8 lights.
eneko
CC BY-SA 3.0
2016-01-08T14:55:00.770Z
we'll need to see the info log from the failed compilation/linking. It's a good practice to always log it while developing.
ratchet freak
CC BY-SA 3.0
2016-01-08T15:01:46.820Z
I am pretty much just starting with shaders...  I do get :


 
Cannot compile frgament shader: 0(24) : error C1101: ambiguous overloaded function reference "mul(mat4, vec3") (0): mat3x4 mul(mat3x1, mat1x4) (0): mat3 mul(mat3x1, mat1x3) (0): mat3x2 mul(mat3x1, mat1x2) ...
eneko
<opengl><shader>
Multiple light pixel Shader in GLSL
eneko
# Multiple light pixel Shader in GLSL

(Asked by: username_0 on 2016-01-08)

I have wirtten a fragment shader that works just fine with a single light. Now I am trying to adpat it to work with 8 lights, the implement it in Processing. Clearly I am doing something wrong in the math and I cannot see what it is... I have read other posts about this and try to adapt the answer to my problem, no luck though...

[![enter image description here](https://i.sstatic.net/9u1P9.png)](https://i.sstatic.net/9u1P9.png)

```
////Fragment/////

    #ifdef GL_ES
precision mediump float;
precision mediump int;
#endif

varying vec4 vertColor;
varying vec3 ecNormal;
varying vec3 lightDir;

void main() {  
  vec3 direction = normalize(lightDir);
  vec3 normal = normalize(ecNormal);
  float intensity = max(0.0, dot(direction, normal));
  gl_FragColor = vec4(intensity, intensity, intensity, 1) * vertColor;
}

////vertex/////

        #define PROCESSING_LIGHT_SHADER

uniform mat4 modelview;
uniform mat4 transform;
uniform mat3 normalMatrix;

uniform vec4 lightPosition;
uniform vec3 lightNormal;

attribute vec4 vertex;
attribute vec4 color;
attribute vec3 normal;

varying vec4 vertColor;
varying vec3 ecNormal;
varying vec3 lightDir;

void main() {
  gl_Position = transform * vertex;    
  vec3 ecVertex = vec3(modelview * vertex);  

  ecNormal = normalize(normalMatrix * normal);
  lightDir = normalize(lightPosition.xyz - ecVertex);  
  vertColor = color;
}

```

**Tags:** opengl, shader

> **Comments:**
> **username_1**: show us what your output is and describe what you expect it to be  
> **username_0**: It just wont compile. It is a version of a basic pixel ilumination shader. The previous version just supports 1 light. I am trying to adapt it so that it can process 8 lights.  
> **username_1**: we'll need to see the info log from the failed compilation/linking. It's a good practice to always log it while developing.  
> **username_0**: I am pretty much just starting with shaders...  I do get :     Cannot compile frgament shader: 0(24) : error C1101: ambiguous overloaded function reference "mul(mat4, vec3") (0): mat3x4 mul(mat3x1, mat1x4) (0): mat3 mul(mat3x1, mat1x3) (0): mat3x2 mul(mat3x1, mat1x2) ...  

---

## 1 answers

### Answer by username_1 on 2016-01-08. Score: 2 | Accepted answer

From the error message the problem is in line 24 of your fragment shader:

```
vec3 transformedNormal = normalize(normalMatrix * normal);

```

`normalMatrix` is a `mat4` but `normal` is a `vec3`.

The solution is to make normalMatrix a mat3 instead.

> **Comments:**
> **username_0**: I do not get matrix errors anymore but It just wont compile. I have posted the original working code for a single light. How should I approach it?  

---

