I'm trying to implement some specular reflections. All looks OK, but specular spot isn't moving when i turn the camera. Here are the shaders:
VERTEX:
#version 330 core
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
uniform mat4 modelViewProjMatrix;
uniform vec3 lightDirection;
uniform vec3 cameraPosition;
layout(location = 0) in vec3 Position;
layout(location = 1) in vec3 Normal;
out vec3 ViewDirection;
out vec3 LightDirection;
out vec3 VertexNormal;
void main()
{
gl_Position = modelViewProjMatrix * vec4(Position, 1.0f);
vec3 worldNormal = mat3(modelMatrix) * Normal;
vec4 worldPosition = modelMatrix * vec4(Position, 1.0f);
LightDirection = -lightDirection;
ViewDirection = (cameraPosition - worldPosition.xyz);
VertexNormal = (worldNormal);
}
FRAGMENT:
#version 330 core
layout(location = 0, index = 0) out vec4 Color;
in vec3 ViewDirection;
in vec3 LightDirection;
in vec3 VertexNormal;
void main()
{
vec3 normal = normalize(VertexNormal);
vec3 lightDirection = normalize(LightDirection);
vec3 viewDirection = normalize(ViewDirection);
vec3 halfVector = normalize(lightDirection + viewDirection);
float diffuseIntensity = max(dot(lightDirection, normal), 0.0f);
float specularIntensity = pow(max(dot(halfVector, normal), 0.0f), 10.0f);
Color = vec4(specularIntensity);
}
What did i forget here?