# Specular Reflections

Still working out the kinks in my lighting system. I have ambient, direct, and point lights all working properly. But the correct specular reflection calculation still eludes me. See image:

Direction Light pointing (-1,-1, 0) then normalized. Look almost parallel to that. Directional light is illuminating the proper wall faces but the specular component is acting super weird. I never can make heads or tails of the equation from all the tuts online. Helps?

[ATTACH=CONFIG]843[/ATTACH]

``````
vec3 calcDirectLight(float intensity, vec3 color, vec3 direction, vec3 normal)
{
//. Initialize
vec3 diffuseColor = vec3(0.0f);
vec3 specularColor = vec3(0.0f);

//. Calculate Specular Reflection
//vec3 cameraPosition = (projection * vec4(eyePosition, 1.0f)).xyz;

vec3 directionToEye = normalize(eyePosition - vPosition);
vec3 reflection     = normalize(reflect(direction, normal));

//. Diffuse/Specular Factors
float diffuseFactor  = max(0.0f, dot(normal, -direction));
float specularFactor = max(0.0f, dot(directionToEye, reflection));

//. Calculate Specular Lighting
specularFactor = pow(specularFactor, specularPower);

//. Save Diffuse & Specular
diffuseColor = color * intensity * diffuseFactor;
specularColor = color * specularIntensity * specularFactor;

return diffuseColor + specularColor;
}

``````

Like should I be using the transformed camera position or the original position? I know I got my reflect vector right I believe. But what bout the directions for the dot product? Something big is wrong?

try to add uniform camera position varible and pass it to glsl

[QUOTE=ParagonArcade;1263029]Directional light is illuminating the proper wall faces but the specular component is acting super weird. I never can make heads or tails of the equation from all the tuts online.[/QUOTE].
The specular component is a model of an imperfect mirror.

The specular component is at its peak when the vector from the surface to the light is the reflection of the vector from the surface to the observer. IOW, when the vector half-way between the two has the same direction to the surface normal. Assuming that all vectors are normalised, this can be formulated as either

``````
dot(normalize(light_vector + eye_vector), normal)

``````

or

``````
dot(reflect(-light_vector,normal), eye_vector)

``````

or

``````
dot(reflect(-eye_vector,normal), light_vector)

``````

Note that light_vector points from the surface to the light, so for a directional light it’s the negation of the light direction.

The result of the dot product is then raised to an exponent which determines the shininess. A larger exponent causes the intensity to fall off more quickly, resulting in “harder” reflections, i.e. a more perfect mirror.