OpenGL 错误 c1101

OpenGL error c1101

我正在学习有关使用 LWJGL 构建游戏引擎的在线教程,我进展顺利并且真的尝试理解我正在教授的代码,但是我现在收到此错误并且我真的不不知道我做错了什么。

我尝试添加镜面反射照明,如果有帮助,这是我正在学习的教程:https://www.youtube.com/watch?v=GZ_1xOm-3qU&index=12&list=PLRIWtICgwaX0u7Rf9zkZhLoLuZVfUksDP

当我尝试 运行 我的应用程序时,这在我的控制台中显示:

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

这是输出这些消息的方法:

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);
}

我希望任何人都可以帮助解决这个问题,在此先感谢:)

谨致问候, 斯坦

编辑:这是我的着色器代码(确实是用 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);

}

我不是 GLSL 专家,但错误消息似乎表明您正在尝试将 mat4 乘以 vec3,但没有可用的乘法函数。

您正在尝试在这一行中执行此操作:

toCameraVector = inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0).xyz - worldPosition.xyz;

请注意,inverse(viewMatrix)mat4vec4(0.0, 0.0, 0.0, 1.0).xyzvec3

你可能想做这样的事情:

toCameraVector = (inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0)).xyz - worldPosition.xyz;

错误消息准确地告诉您问题出在哪里:在着色器的第 25 行中,您试图将 mat4 与 vec3 相乘,这是不可能的。

toCameraVector = inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0).xyz - worldPosition.xyz;

您可以将 mat4 乘以 vec4 或将 mat3 乘以 vec3。查看教程时,您会注意到您删除了一些括号:

toCameraVector = (inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0)).xyz - worldPosition.xyz;

请注意,在正确的版本中,您将 mat4 乘以 vec4,然后将其钳位到 vec3。