2017-06-24 1 views
-1

Je suis un tutoriel en ligne concernant la construction d'un moteur de jeu en utilisant LWJGL, je vais bien et j'essaie vraiment de comprendre le code que l'on m'enseigne, mais je reçois maintenant cette erreur et je ne sais vraiment pas Je ne sais pas ce que je fais mal.OpenGL erreur c1101

J'ai essayé d'ajouter un éclairage spéculaires, c'est le tutoriel que je suis si cela aide: https://www.youtube.com/watch?v=GZ_1xOm-3qU&index=12&list=PLRIWtICgwaX0u7Rf9zkZhLoLuZVfUksDP

Lorsque je tente de lancer ma demande cela se voit dans la 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 

C'est le méthode qui sortie ces 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); 
} 

J'espère que quelqu'un pourrait aider à corriger ce, grâce à l'avance :)

Cordialement, Stan

EDIT: Voici mon code shader (en effet écrit en 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); 

} 
+0

Il semble que vous essayez de compiler un shader (probablement écrit dans [GLSL] (https://en.wikipedia.org/wiki/OpenGL_Shading_Language)) et le compilateur shader vous dit qu'il y a quelque chose qui ne va pas avec le code du shader. À quoi ressemble le code shader? – Jesper

+0

@Jesper J'ai ajouté les codes de shader. – Stannies

Répondre

2

Je ne suis pas un expert en GLSL mais le message d'erreur semble suggérer que vous essayez de multiplier un mat4 par un vec3, pour lequel il n'y a pas de fonction de multiplication disponible.

Vous essayez de le faire dans cette ligne:

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

Notez que inverse(viewMatrix) est un mat4 et vec4(0.0, 0.0, 0.0, 1.0).xyz est un vec3.

Vous voulez sans doute faire quelque chose comme ceci:

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

Merci beaucoup qui a fonctionné, stupide comment je l'ai regardé un milliard de fois. J'aurais dû le voir moi-même, mais merci quand même :) – Stannies

0

Le message d'erreur vous indique exactement quel est le problème: Dans la ligne 25 de votre shaders que vous essayez de multiplier un mat4 avec un vec3 qui est impossible.

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

Vous pouvez multiplier un mat4 par un vec4 ou un mat3 par un vec3. Lorsque l'on regarde le tutoriel, vous remarquerez que vous avez retiré des supports:

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

Notez que dans la version correcte vous multipliez un mat4 par un vec4 et pince ensuite à un vec3.