Java 错误的操作类型'*';在glsl中?

Java 错误的操作类型'*';在glsl中?,java,glsl,lwjgl,Java,Glsl,Lwjgl,我正在用java中的lwjgl制作一个3d游戏,我使用GLSL作为着色器。尝试运行代码后,我得到: Sun May 29 17:53:13英国夏令时2016信息:使用Java PNG加载程序=true 错误:0:34:'':错误的操作数类型不存在接受“float”类型的左侧操作数和“float的3分量向量的统一10元素数组”类型的右侧操作数的操作“”(或没有可接受的转换)无法编译着色器 地形片段着色器的代码: #version 140 core in vec2 pass_textureCoor

我正在用java中的lwjgl制作一个3d游戏,我使用GLSL作为着色器。尝试运行代码后,我得到:

Sun May 29 17:53:13英国夏令时2016信息:使用Java PNG加载程序=true
错误:0:34:'':错误的操作数类型不存在接受“float”类型的左侧操作数和“float的3分量向量的统一10元素数组”类型的右侧操作数的操作“”(或没有可接受的转换)


无法编译着色器

地形片段着色器的代码:

#version 140 core

in vec2 pass_textureCoords;
in vec3 surfaceNormal;
in vec3 toLightVector[10];
in vec3 toCameraVector;
in float visibility;

out vec4 out_Color;

uniform sampler2D backgroundTexture;
uniform sampler2D rTexture;
uniform sampler2D gTexture;
uniform sampler2D bTexture;
uniform sampler2D blendMap;


uniform vec3 lightColour[10];
uniform float shineDamper;
uniform float reflectivity;
uniform vec3 skyColour;

void main(void){

    vec4 blendMapColour = texture(blendMap, pass_textureCoords);

    float backTextureAmount = 1 - (blendMapColour.r + blendMapColour.g + blendMapColour.b);
    vec2 tiledCoords = pass_textureCoords * 40.0;
    vec4 backgroundTextureColour = texture(backgroundTexture, tiledCoords) * backTextureAmount;
    vec4 rTextureColour = texture(rTexture, tiledCoords) * blendMapColour.r;
    vec4 gTextureColour = texture(gTexture, tiledCoords) * blendMapColour.g;
    vec4 bTextureColour = texture(bTexture, tiledCoords) * blendMapColour.b;

    vec4 totalColour = backgroundTextureColour + rTextureColour + gTextureColour + bTextureColour;

    vec3 unitNormal = normalize(surfaceNormal);
    vec3 unitVectorToCamera = normalize(toCameraVector);

    vec3 totalDiffuse = vec3(0.0);
    vec3 totalSpecular = vec3(0.0);

    for(int i=0;i<10;i++){
        vec3 unitLightVector = normalize(toLightVector[i]);
        float nDotl = dot(unitNormal,unitLightVector);
        float brightness = max(nDotl,0.0);
        vec3 lightDirection = -unitLightVector;
        vec3 reflectedLightDirection = reflect(lightDirection,unitNormal);
        float specularFactor = dot(reflectedLightDirection , unitVectorToCamera);
        specularFactor = max(specularFactor,0.0);
        float dampedFactor = pow(specularFactor,shineDamper);
        totalDiffuse = totalDiffuse + brightness * lightColour[i];
        totalSpecular = totalSpecular + dampedFactor * reflectivity * lightColour[i];
    }
    totalDiffuse = max(totalDiffuse,0.2);

    out_Color =  vec4(totalDiffuse,1.0) * textureColour + vec4(totalSpecular,1.0);
    out_Color = mix(vec4(skyColour, 1.0), out_Color, visibility);
}
#version 140 core

in vec2 pass_textureCoords;
in vec3 surfaceNormal;
in vec3 toLightVector[10];
in vec3 toCameraVector;
in float visibility;

out vec4 out_Color;

uniform sampler2D modelTexture;
uniform vec3 lightColour[10];
uniform float shineDamper;
uniform float reflectivity;
uniform vec3 skyColour;

void main(void){

vec3 unitNormal = normalize(surfaceNormal);
vec3 unitVectorToCamera = normalize(toCameraVector);

vec3 totalDiffuse = vec3(0.0);
vec3 totalSpecular = vec3(0.0);

for(int i=0;i<10;i++){
    vec3 unitLightVector = normalize(toLightVector[i]);
    float nDotl = dot(unitNormal,unitLightVector);
    float brightness = max(nDotl,0.0);
    vec3 lightDirection = -unitLightVector;
    vec3 reflectedLightDirection = reflect(lightDirection,unitNormal);
    float specularFactor = dot(reflectedLightDirection , unitVectorToCamera);
    specularFactor = max(specularFactor,0.0);
    float dampedFactor = pow(specularFactor,shineDamper);
    totalDiffuse = totalDiffuse + brightness * lightColour;
    totalSpecular = totalSpecular + dampedFactor * reflectivity * lightColour[i];
}
totalDiffuse = max(totalDiffuse,0.2);

vec4 textureColour = texture(modelTexture,pass_textureCoords);
if(textureColour.a<0.5){
    discard;
}

out_Color =  vec4(totalDiffuse,1.0) * textureColour + vec4(totalSpecular,1.0);
out_Color = mix(vec4(skyColour, 1.0), out_Color, visibility);
}
totalDiffuse = totalDiffuse + brightness * lightColour;
#版本140核心
在vec2中,pass_textureCoords;
vec3表面异常;
在vec3中,toLightVector[10];
在vec3中,转换为转换器;
浮标能见度;
out vec4 out_颜色;
均匀的二维背景纹理;
均匀结构;
均匀的二维纹理;
均匀的二维纹理;
均匀取样器2D blendMap;
均匀的vec3浅色[10];
均匀浮光;
均匀浮动反射率;
均匀的vec3天色;
真空总管(真空){
vec4 blendMapColour=纹理(blendMap,pass_textureCoords);
float backTextureAmount=1-(blendMapColor.r+blendMapColor.g+blendMapColor.b);
vec2 tiledCoords=通过纹理单词*40.0;
vec4 BackgroundTextureColor=纹理(backgroundTexture,tiledCoords)*backTextureAmount;
vec4 rTextureColour=纹理(rTexture,TilledCoords)*混合颜色.r;
vec4 gtexturecolor=纹理(gTexture,tiledCoords)*blendmapacolor.g;
vec4 b纹理颜色=纹理(b纹理,瓷砖坐标)*混合颜色.b;
vec4 TotalColor=背景纹理颜色+RTextureColor+GTextureColor+BTextureColor;
vec3 unitNormal=标准化(表面异常);
vec3 unitVectorToCamera=标准化(toCameraVector);
vec3 totalDiffuse=vec3(0.0);
vec3总镜面反射=vec3(0.0);

对于片段着色器的(int i=0;i第34行:

#version 140 core

in vec2 pass_textureCoords;
in vec3 surfaceNormal;
in vec3 toLightVector[10];
in vec3 toCameraVector;
in float visibility;

out vec4 out_Color;

uniform sampler2D backgroundTexture;
uniform sampler2D rTexture;
uniform sampler2D gTexture;
uniform sampler2D bTexture;
uniform sampler2D blendMap;


uniform vec3 lightColour[10];
uniform float shineDamper;
uniform float reflectivity;
uniform vec3 skyColour;

void main(void){

    vec4 blendMapColour = texture(blendMap, pass_textureCoords);

    float backTextureAmount = 1 - (blendMapColour.r + blendMapColour.g + blendMapColour.b);
    vec2 tiledCoords = pass_textureCoords * 40.0;
    vec4 backgroundTextureColour = texture(backgroundTexture, tiledCoords) * backTextureAmount;
    vec4 rTextureColour = texture(rTexture, tiledCoords) * blendMapColour.r;
    vec4 gTextureColour = texture(gTexture, tiledCoords) * blendMapColour.g;
    vec4 bTextureColour = texture(bTexture, tiledCoords) * blendMapColour.b;

    vec4 totalColour = backgroundTextureColour + rTextureColour + gTextureColour + bTextureColour;

    vec3 unitNormal = normalize(surfaceNormal);
    vec3 unitVectorToCamera = normalize(toCameraVector);

    vec3 totalDiffuse = vec3(0.0);
    vec3 totalSpecular = vec3(0.0);

    for(int i=0;i<10;i++){
        vec3 unitLightVector = normalize(toLightVector[i]);
        float nDotl = dot(unitNormal,unitLightVector);
        float brightness = max(nDotl,0.0);
        vec3 lightDirection = -unitLightVector;
        vec3 reflectedLightDirection = reflect(lightDirection,unitNormal);
        float specularFactor = dot(reflectedLightDirection , unitVectorToCamera);
        specularFactor = max(specularFactor,0.0);
        float dampedFactor = pow(specularFactor,shineDamper);
        totalDiffuse = totalDiffuse + brightness * lightColour[i];
        totalSpecular = totalSpecular + dampedFactor * reflectivity * lightColour[i];
    }
    totalDiffuse = max(totalDiffuse,0.2);

    out_Color =  vec4(totalDiffuse,1.0) * textureColour + vec4(totalSpecular,1.0);
    out_Color = mix(vec4(skyColour, 1.0), out_Color, visibility);
}
#version 140 core

in vec2 pass_textureCoords;
in vec3 surfaceNormal;
in vec3 toLightVector[10];
in vec3 toCameraVector;
in float visibility;

out vec4 out_Color;

uniform sampler2D modelTexture;
uniform vec3 lightColour[10];
uniform float shineDamper;
uniform float reflectivity;
uniform vec3 skyColour;

void main(void){

vec3 unitNormal = normalize(surfaceNormal);
vec3 unitVectorToCamera = normalize(toCameraVector);

vec3 totalDiffuse = vec3(0.0);
vec3 totalSpecular = vec3(0.0);

for(int i=0;i<10;i++){
    vec3 unitLightVector = normalize(toLightVector[i]);
    float nDotl = dot(unitNormal,unitLightVector);
    float brightness = max(nDotl,0.0);
    vec3 lightDirection = -unitLightVector;
    vec3 reflectedLightDirection = reflect(lightDirection,unitNormal);
    float specularFactor = dot(reflectedLightDirection , unitVectorToCamera);
    specularFactor = max(specularFactor,0.0);
    float dampedFactor = pow(specularFactor,shineDamper);
    totalDiffuse = totalDiffuse + brightness * lightColour;
    totalSpecular = totalSpecular + dampedFactor * reflectivity * lightColour[i];
}
totalDiffuse = max(totalDiffuse,0.2);

vec4 textureColour = texture(modelTexture,pass_textureCoords);
if(textureColour.a<0.5){
    discard;
}

out_Color =  vec4(totalDiffuse,1.0) * textureColour + vec4(totalSpecular,1.0);
out_Color = mix(vec4(skyColour, 1.0), out_Color, visibility);
}
totalDiffuse = totalDiffuse + brightness * lightColour;
您忘记指定浅色的标记:

totalDiffuse = totalDiffuse + brightness * lightColour[i];

片段着色器的第34行:

#version 140 core

in vec2 pass_textureCoords;
in vec3 surfaceNormal;
in vec3 toLightVector[10];
in vec3 toCameraVector;
in float visibility;

out vec4 out_Color;

uniform sampler2D backgroundTexture;
uniform sampler2D rTexture;
uniform sampler2D gTexture;
uniform sampler2D bTexture;
uniform sampler2D blendMap;


uniform vec3 lightColour[10];
uniform float shineDamper;
uniform float reflectivity;
uniform vec3 skyColour;

void main(void){

    vec4 blendMapColour = texture(blendMap, pass_textureCoords);

    float backTextureAmount = 1 - (blendMapColour.r + blendMapColour.g + blendMapColour.b);
    vec2 tiledCoords = pass_textureCoords * 40.0;
    vec4 backgroundTextureColour = texture(backgroundTexture, tiledCoords) * backTextureAmount;
    vec4 rTextureColour = texture(rTexture, tiledCoords) * blendMapColour.r;
    vec4 gTextureColour = texture(gTexture, tiledCoords) * blendMapColour.g;
    vec4 bTextureColour = texture(bTexture, tiledCoords) * blendMapColour.b;

    vec4 totalColour = backgroundTextureColour + rTextureColour + gTextureColour + bTextureColour;

    vec3 unitNormal = normalize(surfaceNormal);
    vec3 unitVectorToCamera = normalize(toCameraVector);

    vec3 totalDiffuse = vec3(0.0);
    vec3 totalSpecular = vec3(0.0);

    for(int i=0;i<10;i++){
        vec3 unitLightVector = normalize(toLightVector[i]);
        float nDotl = dot(unitNormal,unitLightVector);
        float brightness = max(nDotl,0.0);
        vec3 lightDirection = -unitLightVector;
        vec3 reflectedLightDirection = reflect(lightDirection,unitNormal);
        float specularFactor = dot(reflectedLightDirection , unitVectorToCamera);
        specularFactor = max(specularFactor,0.0);
        float dampedFactor = pow(specularFactor,shineDamper);
        totalDiffuse = totalDiffuse + brightness * lightColour[i];
        totalSpecular = totalSpecular + dampedFactor * reflectivity * lightColour[i];
    }
    totalDiffuse = max(totalDiffuse,0.2);

    out_Color =  vec4(totalDiffuse,1.0) * textureColour + vec4(totalSpecular,1.0);
    out_Color = mix(vec4(skyColour, 1.0), out_Color, visibility);
}
#version 140 core

in vec2 pass_textureCoords;
in vec3 surfaceNormal;
in vec3 toLightVector[10];
in vec3 toCameraVector;
in float visibility;

out vec4 out_Color;

uniform sampler2D modelTexture;
uniform vec3 lightColour[10];
uniform float shineDamper;
uniform float reflectivity;
uniform vec3 skyColour;

void main(void){

vec3 unitNormal = normalize(surfaceNormal);
vec3 unitVectorToCamera = normalize(toCameraVector);

vec3 totalDiffuse = vec3(0.0);
vec3 totalSpecular = vec3(0.0);

for(int i=0;i<10;i++){
    vec3 unitLightVector = normalize(toLightVector[i]);
    float nDotl = dot(unitNormal,unitLightVector);
    float brightness = max(nDotl,0.0);
    vec3 lightDirection = -unitLightVector;
    vec3 reflectedLightDirection = reflect(lightDirection,unitNormal);
    float specularFactor = dot(reflectedLightDirection , unitVectorToCamera);
    specularFactor = max(specularFactor,0.0);
    float dampedFactor = pow(specularFactor,shineDamper);
    totalDiffuse = totalDiffuse + brightness * lightColour;
    totalSpecular = totalSpecular + dampedFactor * reflectivity * lightColour[i];
}
totalDiffuse = max(totalDiffuse,0.2);

vec4 textureColour = texture(modelTexture,pass_textureCoords);
if(textureColour.a<0.5){
    discard;
}

out_Color =  vec4(totalDiffuse,1.0) * textureColour + vec4(totalSpecular,1.0);
out_Color = mix(vec4(skyColour, 1.0), out_Color, visibility);
}
totalDiffuse = totalDiffuse + brightness * lightColour;
您忘记指定浅色的标记:

totalDiffuse = totalDiffuse + brightness * lightColour[i];
答案是:
首先@Nasso说了什么,那是什么而不是什么

lightColour;
out_Color =  vec4(totalDiffuse,1.0) * textureColour + vec4(totalSpecular,1.0);
应该是的

lightColour[i];
之后出现了第二个错误,很容易修复:
而不是

lightColour;
out_Color =  vec4(totalDiffuse,1.0) * textureColour + vec4(totalSpecular,1.0);
我不得不把

out_Color =  vec4(totalDiffuse,1.0) * totalColour + vec4(totalSpecular,1.0);
答案是:
首先@Nasso说了什么,那是什么而不是什么

lightColour;
out_Color =  vec4(totalDiffuse,1.0) * textureColour + vec4(totalSpecular,1.0);
应该是的

lightColour[i];
之后出现了第二个错误,很容易修复:
而不是

lightColour;
out_Color =  vec4(totalDiffuse,1.0) * textureColour + vec4(totalSpecular,1.0);
我不得不把

out_Color =  vec4(totalDiffuse,1.0) * totalColour + vec4(totalSpecular,1.0);

看起来您正试图通过一个浮点来缩放RGB值的向量,但显然不是这样supported@Nasso我只是照你说的做了,但它仍然不起作用。看起来你试图用一个浮点数来缩放RGB值的向量,这显然不是supported@Nasso我只是照你说的做了,但还是不管用。当心g ThinMatrix教程!观看ThinMatrix教程时要小心!