ParagonArcade

12-17-2014, 09:45 AM

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?

1558

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?

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?

1558

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?