Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

raytracer part 10 (blinn VS phong)

Sign in to follow this  


So I was using the standard Phong lighting equation. But it didn't match the teachers reference pic. So I checked his old notes, found a description of using the half vector (i.e. Blinn's variant).

Blinn's approximation sucks according to me...


if( (*nearestObject)->material().shininess() > 0.0 )
const cVector3<> viewDirection = ray.direction();
const cVector3<> reflection = directionToLight - Real(2.0) * dotLN * surfaceNormal;
const Real dotVR = Dot( viewDirection, reflection );
if( dotVR > 0 )
// Apply specular (phong) lightiing
const Real specular = pow( dotVR, (*nearestObject)->material().shininess() ) * (*nearestObject)->material().specular();
color += specular * light->color() * shade;


if( (*nearestObject)->material().shininess() > 0.0 )
const cVector3<> viewDirection = -ray.direction(); // should be directionToViewer?
const cVector3<> sumLV = directionToLight + viewDirection;
const cVector3<> halfway = sumLV / sumLV.length();

const Real dotHN = Dot( halfway, surfaceNormal );
if( dotHN > 0 )
// Apply specular (Blinn's Phong) lightiing
const Real specular = pow( dotHN, (*nearestObject)->material().shininess() ) * (*nearestObject)->material().specular();
color += specular * light->color() * shade; // NOTE: this is subject to attune

Image compare, Phong to the left and Blinn to the right


And the judge:
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 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!