java lwjgl 2着色器错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java lwjgl 2着色器错误相关的知识,希望对你有一定的参考价值。

我正在尝试在java lwjgl 2.9中编译着色器,如果我运行我的游戏,它就无法编译着色器。问题是为什么着色器不重新协调const关键字,如果我删除const然后它抛出错误float未重新调整或类似的东西。

错误:0:24:'const':语法错误语法错误。无法编译着色器!

着色器代码

地形顶点着色器

#version 150

in vec3 position;
in vec2 textureCoordinates;
in vec3 normal;

out vec2 pass_textureCoordinates;
out vec3 surfaceNormal;
out vec3 toLightVector[4];
out vec3 toCameraVector;
out float visibility;
out vec4 shadowCoords;

uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform vec3 lightPosition[4];

uniform mat4 toShadowMapSpace;

const float density = 0;
const float gradient = 5.0;
const float shadowDistance = 150.0
const float transitionDistance = 10.0;

uniform vec4 plane;

void main(void){

vec4 worldPosition = transformationMatrix * vec4(position,1.0);
shadowCoords = toShadowMapSpace * worldPosition;

gl_ClipDistance[0] = dot(worldPosition, plane);

vec4 positionRelativeToCam = viewMatrix * worldPosition;
gl_Position = projectionMatrix * positionRelativeToCam;
pass_textureCoordinates = textureCoordinates;

surfaceNormal = (transformationMatrix * vec4(normal,0.0)).xyz;
for(int i=0;i<4;i++){
    toLightVector[i] = lightPosition[i] - worldPosition.xyz;
}
toCameraVector = (inverse(viewMatrix) * vec4(0.0,0.0,0.0,1.0)).xyz - worldPosition.xyz;

float distance = length(positionRelativeToCam.xyz);
visibility = exp(-pow((distance*density),gradient));
visibility = clamp(visibility,0.0,1.0);

distance = distance - (shadowDistance - transitionDistance);
distance = distance / transitionDistance;
shadowCoords.w = clamp(1.0-distance, 0.0, 1.0);
}

地形片段着色器

#version 330

in vec2 textureCoords;

out vec4 out_colour;

uniform sampler2D modelTexture;

void main(void){

float alpha = texture(modelTexture, textureCoords).a;
if(alpha < 0.5){
 discard;
}

out_colour = vec4(1.0);

}
答案
const float gradient = 5.0;
const float shadowDistance = 150.0
                                  ^ where's the semicolon?
const float transitionDistance = 10.0;

以上是关于java lwjgl 2着色器错误的主要内容,如果未能解决你的问题,请参考以下文章

GLSL 着色器未编译,没有错误消息

LWJGL 无法在着色器中采样帧缓冲纹理

损坏的顶点和片段着色器

金属着色器混合片段接收错误的颜色值

透视投影 OPENGL 和计算着色器

着色器在 2d OpenGL 中不起作用