【问题标题】:OpenGL error c1101OpenGL 错误 c1101
【发布时间】:2017-06-24 18:52:38
【问题描述】:

我正在关注有关使用 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 编写),着色器编译器告诉您着色器的代码有问题。着色器代码是什么样的?
  • @Jesper 我添加了着色器代码。

标签: java opengl rendering lwjgl


【解决方案1】:

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

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

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;

【讨论】:

  • 非常感谢它的工作,愚蠢的我只是看了十亿次。应该自己看过,但还是谢谢:)
【解决方案2】:

错误消息准确地告诉您问题所在:在着色器的第 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。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-15
    • 2013-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多