GLSL复杂错误:从vec4强制转换为vec3

时间:2018-12-12 12:57:08

标签: opengl glsl

不必要的vec4() vec3()仅用于调试问题。

完整错误:

  

0(36):错误C7011:从“ vec4”隐式转换为“ vec3”
  0(36):错误C1035:分配了不兼容的类型

代码:

#version 330

in vec2 pass_textureCoords;
in vec3 surfaceNormal;
in vec3 toLightVector;
in vec3 toCameraVector;
in vec3 visibility;

out vec4 out_Color;

uniform sampler2D textureSampler;
uniform vec3 lightColor;
uniform float shineDamper;
uniform float reflectivity;
uniform vec3 skyColor;

void main(void) {

    vec3 unitNormal = normalize(surfaceNormal);
    vec3 unitLightVector = normalize(toLightVector);

    float nDotl = dot(unitNormal, unitLightVector);
    float brightness = max(nDotl, 0.2);
    vec3 diffuse = brightness * lightColor;

    vec3 unitVectorCameraVector = normalize(toCameraVector);
    vec3 lightDirection = -unitLightVector;
    vec3 reflectedLightDirection = reflect(lightDirection, unitNormal);

    float specularFactor = dot(reflectedLightDirection, unitVectorCameraVector);
    specularFactor = max(specularFactor, 0.0);
    float dampedFactor = pow(specularFactor, shineDamper);
    vec3 finalSpecular = dampedFactor * reflectivity *lightColor;

    out_Color = vec4(diffuse, 1.0) * texture(textureSampler, pass_textureCoords) + vec4(finalSpecular, 1.0);
    out_Color = mix(vec4(skyColor, 1.0), vec4(out_Color), visibility);
}

1 个答案:

答案 0 :(得分:3)

问题是您将vec3用作mix()的第三个参数。这是不正确的,因为它只能是与其他参数的类型相同的类型:vec4()或使用原始类型。