I tried my best to find the answer to this problem or any mistake I made in the code, but I just could not find anything.
If this helps, I have a Sapphire Radeon HD 6950 graphics card and it uses the AMD Radeon HD 6900 driver.
Error message:
Wed May 27 13:55:50 CDT 2015 INFO:Use Java PNG Loader = true Vertex shader failed to compile with the following errors: ERROR: 0:26: error(
Vertex Shader:
#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; out float visibility; uniform mat4 transformationMatrix; uniform mat4 projectionMatrix; uniform mat4 viewMatrix; uniform vec3 lightPosition; uniform float useFakeLighting; const float density = 0.0035; const float gradient = 5.0; void main(void) { vec4 worldPosition = transformationMatrix * vec4(position, 1.0); vec4 positionRelativeToCam = viewMatrix * worldPosition; gl_Position = projectionMatrix * positionRelativeToCam; pass_textureCoords = textureCoords; vec3 actualNormal = normal; if(useFakeLighting > 0.5) { actualNormal = vec3(0.0, 1.0, 0.0); } surfaceNormal = (transformationMatrix * vec4(actualNormal, 0.0)).xyz; toLightVector = lightPosition - worldPosition.xyz; toCameraVector = vec4(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); }
FragmentShader:
#version 400 core in vec2 pass_textureCoords; in vec3 surfaceNormal; in vec3 toLightVector; in vec3 toCameraVector; in float visibility; out vec4 out_Color; uniform sampler2D modelTexture; uniform vec3 lightColor; uniform float shineDamper; uniform float reflectivity; uniform vec3 skyColor; void main(void){ vec3 unitNormal = normalize(surfaceNormal); vec3 unitLightVector = normalize(toLightVector); float nDot1 = dot(unitNormal, unitLightVector); float brightness = max(nDot1, 0.2); vec3 diffuse = brightness * lightColor; 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 * lightColor * reflectivity; vec4 textureColor = texture(modelTexture, pass_textureCoords); if(textureColor.a < 0.5) { discard; } out_Color = vec4(diffuse, 1.0) * texture(modelTexture,pass_textureCoords) + vec4(finalSpecular, 1.0); out_Color = mix(vec4(skyColor, 1.0), out_Color, visibility); }
StaticShader (loads shaders):
package shaders; import org.lwjgl.util.vector.Matrix4f; import org.lwjgl.util.vector.Vector3f; import com.game.entities.Camera; import com.game.entities.Light; import com.game.toolbox.Maths; public class StaticShader extends ShaderProgram { public static final String VERTEX_FILE = "src/shaders/vertexShader.txt"; public static final String FRAGMENT_FILE = "src/shaders/fragmentShader.txt"; private int location_transformationMatrix; private int location_projectionMatrix; private int location_viewMatrix; private int location_lightPos; private int location_lightCol; private int location_shineDamper; private int location_reflectivity; private int location_useFakeLighting; private int location_skyColor; public StaticShader() { super(VERTEX_FILE, FRAGMENT_FILE); } @Override protected void bindAttributes()
Finally, the ShaderProgram Class:
package shaders; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.nio.FloatBuffer; import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL20; import org.lwjgl.util.vector.Matrix4f; import org.lwjgl.util.vector.Vector3f; public abstract class ShaderProgram { private int programID; private int vertexShaderID; private int fragmentShaderID; private static FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16); public ShaderProgram(String vertexFile, String fragmentFile) { vertexShaderID = loadShader(vertexFile, GL20.GL_VERTEX_SHADER); fragmentShaderID = loadShader(fragmentFile, GL20.GL_FRAGMENT_SHADER); programID = GL20.glCreateProgram(); GL20.glAttachShader(programID, vertexShaderID); GL20.glAttachShader(programID, fragmentShaderID); bindAttributes(); GL20.glLinkProgram(programID); GL20.glValidateProgram(programID); getAllUniformLocations(); } protected abstract void getAllUniformLocations(); protected int getUniformLocation(String uniformName) { return GL20.glGetUniformLocation(programID, uniformName); } public void start() { GL20.glUseProgram(programID); } public void stop() { GL20.glUseProgram(0); } public void cleanUp() { stop(); GL20.glDetachShader(programID, vertexShaderID); GL20.glDetachShader(programID, fragmentShaderID); GL20.glDeleteShader(vertexShaderID); GL20.glDeleteShader(fragmentShaderID); GL20.glDeleteProgram(programID); } protected abstract void bindAttributes(); protected void bindAttribute(int attribute, String variableName) { GL20.glBindAttribLocation(programID, attribute, variableName); } protected void loadFloat(int location, float value) { GL20.glUniform1f(location, value); } protected void loadInt(int location, int value) { GL20.glUniform1i(location, value); } protected void loadVector(int location, Vector3f vector) { GL20.glUniform3f(location, vector.x, vector.y, vector.z); } protected void loadBoolean(int location, boolean value) { float toLoad = 0; if(value) toLoad = 1; GL20.glUniform1f(location, toLoad); } protected void loadMatrix(int location, Matrix4f matrix) { matrix.store(matrixBuffer); matrixBuffer.flip(); GL20.glUniformMatrix4(location, false, matrixBuffer); } private static int loadShader(String fileName, int type)