Jump to content
Sign in to follow this  
  • entries
    94
  • comments
    127
  • views
    83576

raytracer part 10 (blinn VS phong)

Sign in to follow this  
Seriema

135 views

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...

Phong

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;
}
}






Blinn

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

VS


And the judge:
Sign in to follow this  


0 Comments


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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!