Reputation:
I'm following an online tutorial regarding building a game engine using LWJGL, I'm coming along great and really try to understand the code I'm being taught, however I now get this error and I really don't know what I'm doing wrong.
I tried adding specular lighting, this is the tutorial I'm following if that helps: https://www.youtube.com/watch?v=GZ_1xOm-3qU&index=12&list=PLRIWtICgwaX0u7Rf9zkZhLoLuZVfUksDP
When I try to run my application this shows in my console:
Could not compile shader.
0(25) : error C1101: ambiguous overloaded function reference "mul(mat4, vec3)"
(0) : mat3x4 mul(mat3x1, mat1x4)
(0) : mat3 mul(mat3x1, mat1x3)
(0) : mat3x2 mul(mat3x1, mat1x2)
(0) : mat3x1 mul(mat3x1, mat1)
(0) : mat2x4 mul(mat2x1, mat1x4)
(0) : mat2x3 mul(mat2x1, mat1x3)
(0) : mat2 mul(mat2x1, mat1x2)
(0) : mat2x1 mul(mat2x1, mat1)
(0) : mat1x4 mul(mat1x3, mat3x4)
(0) : mat1x3 mul(mat1x3, mat3)
(0) : mat1x2 mul(mat1x3, mat3x2)
(0) : mat1 mul(mat1
This is the method that's outputting those messages:
if (GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
System.out.println(GL20.glGetShaderInfoLog(shaderID, 500));
System.err.println("Could not compile shader.");
System.exit(-1);
}
I hope anyone could help fixing this, thanks in advance :)
With kind regards, Stan
EDIT: Here's my shader code (indeed written in GLSL)
vertexShader.txt:
#version 400 core
in vec3 position;
in vec2 textureCoords;
in vec3 normal;
out vec2 pass_textureCoords;
out vec3 surfaceNormal;
out vec3 toLightVector;
out vec3 toCameraVector;
uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform vec3 lightPosition;
void main(void) {
vec4 worldPosition = transformationMatrix * vec4(position, 1.0);
gl_Position = projectionMatrix * viewMatrix * worldPosition;
pass_textureCoords = textureCoords;
surfaceNormal = (transformationMatrix * vec4(normal, 0.0)).xyz;
toLightVector = lightPosition - worldPosition.xyz;
toCameraVector = inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0).xyz - worldPosition.xyz;
}
fragmentShader.txt
#version 400 core
in vec2 pass_textureCoords;
in vec3 surfaceNormal;
in vec3 toLightVector;
in vec3 toCameraVector;
out vec4 out_Color;
uniform sampler2D textureSampler;
uniform vec3 lightColour;
uniform float shineDamper;
uniform float reflectivity;
void main(void) {
vec3 unitNormal = normalize(surfaceNormal);
vec3 unitLightVector = normalize(toLightVector);
float nDotl = dot(unitNormal, unitLightVector);
float brightness = max(nDotl, 0.0);
vec3 diffuse = brightness * lightColour;
vec3 unitVectorToCamera = normalize(toCameraVector);
vec3 lightDirection = -unitLightVector;
vec3 reflectedLightDirection = reflect(lightDirection, unitNormal);
float specularFactor = dot(reflectedLightDirection, unitVectorToCamera);
specularFactor = max(specularFactor, 0.0);
float dampedFactor = pow(specularFactor, shineDamper);
vec3 finalSpecular = dampedFactor * lightColour;
out_Color = vec4(diffuse, 1.0) * texture(textureSampler, pass_textureCoords) + vec4(finalSpecular, 1.0);
}
Upvotes: 0
Views: 1135
Reputation: 22168
The error message tells you exactly what the problem is: In line 25 of your shader you are trying to multiply a mat4 with a vec3 which is impossible.
toCameraVector = inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0).xyz - worldPosition.xyz;
You can either multiply a mat4 by a vec4 or a mat3 by a vec3. When looking at the tutorial, you'll note that you removed some brackets:
toCameraVector = (inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0)).xyz - worldPosition.xyz;
Note, that in the correct version you are multiplying a mat4 by a vec4 and afterwards clamp it to a vec3.
Upvotes: 1
Reputation: 206816
I'm not an expert in GLSL but the error message seems to suggest that you are trying to multiply a mat4
by a vec3
, for which there is no multiply function available.
You are trying to do this in this line:
toCameraVector = inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0).xyz - worldPosition.xyz;
Note that inverse(viewMatrix)
is a mat4
and vec4(0.0, 0.0, 0.0, 1.0).xyz
is a vec3
.
You probably want to do something like this instead:
toCameraVector = (inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0)).xyz - worldPosition.xyz;
Upvotes: 3