0

I'm trying to compile shaders in java lwjgl 2.9, and if I run my game, it cannot compile shaders. question is why shader doesn't reconize const keyword, if I remove const then it throws error float is not reconized or something like that.

ERROR: 0:24: 'const' : syntax error syntax error. Could not compile shader!

Shader codes

Terrain Vertex shader

#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);
}

Terrain fragment shader

#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);

}
0

1 Answer 1

1
const float gradient = 5.0;
const float shadowDistance = 150.0
                                  ^ where's the semicolon?
const float transitionDistance = 10.0;
Sign up to request clarification or add additional context in comments.

1 Comment

Actualy i figured it at my own, but thanks for the anwser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.