Jump to content
  • Advertisement
Sign in to follow this  
pseudomarvin

Phong model correctness (video)

This topic is 740 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Do you guys think this implementation of Phong shading and Phong reflection model is correct?

 

I use a directionial light pointing exactly where the black line is heading (0, 0, -1). I modify the shininess value later in the video. 

I especially find it strange that when I look in direction exactly opposite to light, the contours of the bunny start glowing (if the shininess factor is low enough). But I have compared my implementation

to a reference from our graphics class and it did the same thing.

 

 

Code:

// Calculation is performed in world space
vec3 N = normalize(worldNormal);
vec3 specColor = vec3(1.0f, 1.0f, 1.0f);
float ambient = 0.2f;
float NLdot = max(dot(-U::worldLightDirection, N), 0.0f);
float diffuse = NLdot;
vec3 V = normalize(U::worldCameraPosition - worldPos);
vec3 R = normalize(glm::reflect(U::worldLightDirection, N));
float specular = pow(max(dot(R, V), 0.0f), U::shininess);
vec3 shadedColor = (ambient + diffuse) * albedo + specular * specColor;

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!